user32: Fix a pointer cast warning.
[wine] / dlls / infosoft / tests / infosoft.c
1 /*
2  * tests for the language neutral word breaker
3  *
4  * Copyright 2006 Mike McCormack for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define COBJMACROS
22 #define CONST_VTABLE
23
24 #include <stdio.h>
25 #include <ole2.h>
26 #include "indexsrv.h"
27
28 #include "wine/test.h"
29
30 #include <initguid.h>
31
32 DEFINE_GUID(CLSID_wb_neutral,  0x369647e0,0x17b0,0x11ce,0x99,0x50,0x00,0xaa,0x00,0x4b,0xbb,0x1f);
33 DEFINE_GUID(_IID_IWordBreaker, 0xD53552C8,0x77E3,0x101A,0xB5,0x52,0x08,0x00,0x2B,0x33,0xB0,0xE6);
34
35 static WCHAR teststring[] = {
36     's','q','u','a','r','e',' ',
37     'c','i','r','c','l','e',' ',
38     't','r','i','a','n','g','l','e',' ',
39     'b','o','x',0
40 };
41
42 struct expected {
43     UINT ofs;
44     UINT len;
45     WCHAR data[10];
46 };
47
48 static int wordnum;
49
50 static struct expected testres[] = {
51     { 0, 6, {'s','q','u','a','r','e',0 }},
52     { 7, 6, {'c','i','r','c','l','e',0 }},
53     { 14, 8, {'t','r','i','a','n','g','l','e',0 }},
54     { 23, 3, {'b','o','x',0}},
55 };
56
57 static HRESULT WINAPI ws_QueryInterface(IWordSink *iface, REFIID riid, void **ppvObject)
58 {
59     ok(0, "not expected\n");
60     return E_NOINTERFACE;
61 }
62
63 static ULONG WINAPI ws_AddRef(IWordSink *iface)
64 {
65     ok(0, "not expected\n");
66     return 2;
67 }
68
69 static ULONG WINAPI ws_Release(IWordSink *iface)
70 {
71     ok(0, "not expected\n");
72     return 1;
73 }
74
75 static HRESULT WINAPI ws_PutWord(IWordSink *iface, ULONG cwc, const WCHAR *pwcInBuf,
76                                  ULONG cwcSrcLen, ULONG cwcSrcPos)
77 {
78     ok(testres[wordnum].len == cwcSrcLen, "wrong length\n");
79     ok(!cwcSrcPos ||(testres[wordnum].ofs == cwcSrcPos), "wrong offset\n");
80     ok(!memcmp(testres[wordnum].data, pwcInBuf, cwcSrcLen), "wrong data\n");
81     wordnum++;
82     return S_OK;
83 }
84
85 static HRESULT WINAPI ws_PutAltWord(IWordSink *iface, ULONG cwc, const WCHAR *pwcInBuf,
86                                     ULONG cwcSrcLen, ULONG cwcSrcPos)
87 {
88     ok(0, "not expected\n");
89     return S_OK;
90 }
91
92 static HRESULT WINAPI ws_StartAltPhrase(IWordSink *iface)
93 {
94     ok(0, "not expected\n");
95     return S_OK;
96 }
97
98 static HRESULT WINAPI ws_EndAltPhrase(IWordSink *iface)
99 {
100     ok(0, "not expected\n");
101     return S_OK;
102 }
103
104 static HRESULT WINAPI ws_PutBreak(IWordSink *iface, WORDREP_BREAK_TYPE breakType)
105 {
106     ok(0, "not expected\n");
107     return S_OK;
108 }
109
110 static const IWordSinkVtbl wsvt =
111 {
112     ws_QueryInterface,
113     ws_AddRef,
114     ws_Release,
115     ws_PutWord,
116     ws_PutAltWord,
117     ws_StartAltPhrase,
118     ws_EndAltPhrase,
119     ws_PutBreak,
120 };
121
122 typedef struct _wordsink_impl
123 {
124     IWordSink IWordSink_iface;
125 } wordsink_impl;
126
127 static wordsink_impl wordsink = { { &wsvt } };
128
129 static HRESULT WINAPI fillbuf_none(TEXT_SOURCE *ts)
130 {
131     return E_FAIL;
132 }
133
134 static HRESULT WINAPI fillbuf_many(TEXT_SOURCE *ts)
135 {
136     int i;
137
138     if (ts->awcBuffer == NULL)
139         ts->awcBuffer = teststring;
140     else
141         ts->awcBuffer += ts->iCur;
142
143     if (!ts->awcBuffer[0])
144         return E_FAIL;
145
146     for( i=0; ts->awcBuffer[i] && ts->awcBuffer[i] != ' '; i++)
147         ;
148     if (ts->awcBuffer[i] == ' ')
149         i++;
150
151     ts->iCur = 0;
152     ts->iEnd = i;
153
154     return S_OK;
155 }
156
157 START_TEST(infosoft)
158 {
159     HRESULT r;
160     BOOL license;
161     IWordBreaker *wb = NULL;
162     TEXT_SOURCE ts;
163
164     r = CoInitialize(NULL);
165     ok( r == S_OK, "failed\n");
166
167     r = CoCreateInstance( &CLSID_wb_neutral, NULL, CLSCTX_INPROC_SERVER,
168                         &_IID_IWordBreaker, (LPVOID)&wb);
169
170     if (FAILED(r))
171         return;
172
173     r = IWordBreaker_Init( wb, FALSE, 0x100, &license );
174     ok( r == S_OK, "failed to init the wordbreaker\n");
175     /* ok( license == TRUE, "should be no license\n"); */
176
177     wordnum = 0;
178     ts.pfnFillTextBuffer = fillbuf_none;
179     ts.awcBuffer = teststring;
180     ts.iEnd = lstrlenW(ts.awcBuffer);
181     ts.iCur = 0;
182     r = IWordBreaker_BreakText(wb, &ts, &wordsink.IWordSink_iface, NULL);
183     ok( r == S_OK, "failed\n");
184
185     ok(wordnum == 4, "words not processed\n");
186
187     wordnum = 0;
188     ts.pfnFillTextBuffer = fillbuf_many;
189     ts.awcBuffer = teststring;
190     ts.iEnd = 0;
191     ts.iCur = 0;
192
193     r = fillbuf_many(&ts);
194     ok( r == S_OK, "failed\n");
195
196     r = IWordBreaker_BreakText(wb, &ts, &wordsink.IWordSink_iface, NULL);
197     ok( r == S_OK, "failed\n");
198
199     ok(wordnum == 4, "words not processed\n");
200     IWordBreaker_Release( wb );
201
202     CoUninitialize();
203 }