urlmon: Don't create stgmed_obj for binding to object.
[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
23 #include <stdio.h>
24 #include <ole2.h>
25 #include "indexsrv.h"
26
27 #include "wine/test.h"
28
29 #include <initguid.h>
30
31 DEFINE_GUID(CLSID_wb_neutral,  0x369647e0,0x17b0,0x11ce,0x99,0x50,0x00,0xaa,0x00,0x4b,0xbb,0x1f);
32 DEFINE_GUID(_IID_IWordBreaker, 0xD53552C8,0x77E3,0x101A,0xB5,0x52,0x08,0x00,0x2B,0x33,0xB0,0xE6);
33
34 static WCHAR teststring[] = {
35     's','q','u','a','r','e',' ',
36     'c','i','r','c','l','e',' ',
37     't','r','i','a','n','g','l','e',' ',
38     'b','o','x',0
39 };
40
41 struct expected {
42     UINT ofs;
43     UINT len;
44     WCHAR data[10];
45 };
46
47 static int wordnum;
48
49 static struct expected testres[] = {
50     { 0, 6, {'s','q','u','a','r','e',0 }},
51     { 7, 6, {'c','i','r','c','l','e',0 }},
52     { 14, 8, {'t','r','i','a','n','g','l','e',0 }},
53     { 23, 3, {'b','o','x',0}},
54 };
55
56 static HRESULT WINAPI ws_QueryInterface(IWordSink *ws, REFIID riid, void **ppvObject)
57 {
58     ok(0, "not expected\n");
59     return E_NOINTERFACE;
60 }
61
62 static ULONG WINAPI ws_AddRef(IWordSink *ws)
63 {
64     ok(0, "not expected\n");
65     return 2;
66 }
67
68 static ULONG WINAPI ws_Release(IWordSink *ws)
69 {
70     ok(0, "not expected\n");
71     return 1;
72 }
73
74 static HRESULT WINAPI ws_PutWord(IWordSink *ws,
75                                  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 *ws,
86                                     ULONG cwc, const WCHAR * pwcInBuf,
87                                     ULONG cwcSrcLen, ULONG cwcSrcPos)
88 {
89     ok(0, "not expected\n");
90     return S_OK;
91 }
92
93 static HRESULT WINAPI ws_StartAltPhrase(IWordSink *ws)
94 {
95     ok(0, "not expected\n");
96     return S_OK;
97 }
98
99 static HRESULT WINAPI ws_EndAltPhrase(IWordSink *ws)
100 {
101     ok(0, "not expected\n");
102     return S_OK;
103 }
104
105 static HRESULT WINAPI ws_PutBreak(IWordSink *ws, WORDREP_BREAK_TYPE breakType)
106 {
107     ok(0, "not expected\n");
108     return S_OK;
109 }
110
111 static const IWordSinkVtbl wsvt =
112 {
113     ws_QueryInterface,
114     ws_AddRef,
115     ws_Release,
116     ws_PutWord,
117     ws_PutAltWord,
118     ws_StartAltPhrase,
119     ws_EndAltPhrase,
120     ws_PutBreak,
121 };
122
123 typedef struct _wordsink_impl
124 {
125     const IWordSinkVtbl *vtbl;
126 } wordsink_impl;
127
128 static wordsink_impl wordsink = { &wsvt };
129
130 static HRESULT WINAPI fillbuf_none(TEXT_SOURCE *ts)
131 {
132     return E_FAIL;
133 }
134
135 static HRESULT WINAPI fillbuf_many(TEXT_SOURCE *ts)
136 {
137     int i;
138
139     if (ts->awcBuffer == NULL)
140         ts->awcBuffer = teststring;
141     else
142         ts->awcBuffer += ts->iCur;
143
144     if (!ts->awcBuffer[0])
145         return E_FAIL;
146
147     for( i=0; ts->awcBuffer[i] && ts->awcBuffer[i] != ' '; i++)
148         ;
149     if (ts->awcBuffer[i] == ' ')
150         i++;
151
152     ts->iCur = 0;
153     ts->iEnd = i;
154
155     return S_OK;
156 }
157
158 START_TEST(infosoft)
159 {
160     HRESULT r;
161     BOOL license;
162     IWordBreaker *wb = NULL;
163     TEXT_SOURCE ts;
164
165     r = CoInitialize(NULL);
166     ok( r == S_OK, "failed\n");
167
168     r = CoCreateInstance( &CLSID_wb_neutral, NULL, CLSCTX_INPROC_SERVER,
169                         &_IID_IWordBreaker, (LPVOID)&wb);
170
171     if (FAILED(r))
172         return;
173
174     r = IWordBreaker_Init( wb, FALSE, 0x100, &license );
175     ok( r == S_OK, "failed to init the wordbreaker\n");
176     /* ok( license == TRUE, "should be no license\n"); */
177
178     wordnum = 0;
179     ts.pfnFillTextBuffer = fillbuf_none;
180     ts.awcBuffer = teststring;
181     ts.iEnd = lstrlenW(ts.awcBuffer);
182     ts.iCur = 0;
183     r = IWordBreaker_BreakText( wb, &ts, (IWordSink*) &wordsink, NULL);
184     ok( r == S_OK, "failed\n");
185
186     ok(wordnum == 4, "words not processed\n");
187
188     wordnum = 0;
189     ts.pfnFillTextBuffer = fillbuf_many;
190     ts.awcBuffer = teststring;
191     ts.iEnd = 0;
192     ts.iCur = 0;
193
194     r = fillbuf_many(&ts);
195     ok( r == S_OK, "failed\n");
196
197     r = IWordBreaker_BreakText( wb, &ts, (IWordSink*) &wordsink, NULL);
198     ok( r == S_OK, "failed\n");
199
200     ok(wordnum == 4, "words not processed\n");
201     IWordBreaker_Release( wb );
202
203     CoUninitialize();
204 }