Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / infosoft / tests / infosoft.c
blob9570636d43d221be7dc498d03e06bdd5bf4c397a
1 /*
2 * tests for the language neutral word breaker
4 * Copyright 2006 Mike McCormack for CodeWeavers
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.
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.
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
21 #define COBJMACROS
23 #include <stdio.h>
24 #include <ole2.h>
25 #include "indexsrv.h"
27 #include "wine/test.h"
29 #include <initguid.h>
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);
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
41 struct expected {
42 UINT ofs;
43 UINT len;
44 WCHAR data[10];
47 static int wordnum;
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}},
56 static HRESULT WINAPI ws_QueryInterface(IWordSink *ws, REFIID riid, void **ppvObject)
58 ok(0, "not expected\n");
59 return E_NOINTERFACE;
62 static ULONG WINAPI ws_AddRef(IWordSink *ws)
64 ok(0, "not expected\n");
65 return 2;
68 static ULONG WINAPI ws_Release(IWordSink *ws)
70 ok(0, "not expected\n");
71 return 1;
74 static HRESULT WINAPI ws_PutWord(IWordSink *ws,
75 ULONG cwc, const WCHAR * pwcInBuf,
76 ULONG cwcSrcLen, ULONG cwcSrcPos)
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;
85 static HRESULT WINAPI ws_PutAltWord(IWordSink *ws,
86 ULONG cwc, const WCHAR * pwcInBuf,
87 ULONG cwcSrcLen, ULONG cwcSrcPos)
89 ok(0, "not expected\n");
90 return S_OK;
93 static HRESULT WINAPI ws_StartAltPhrase(IWordSink *ws)
95 ok(0, "not expected\n");
96 return S_OK;
99 static HRESULT WINAPI ws_EndAltPhrase(IWordSink *ws)
101 ok(0, "not expected\n");
102 return S_OK;
105 static HRESULT WINAPI ws_PutBreak(IWordSink *ws, WORDREP_BREAK_TYPE breakType)
107 ok(0, "not expected\n");
108 return S_OK;
111 static const IWordSinkVtbl wsvt =
113 ws_QueryInterface,
114 ws_AddRef,
115 ws_Release,
116 ws_PutWord,
117 ws_PutAltWord,
118 ws_StartAltPhrase,
119 ws_EndAltPhrase,
120 ws_PutBreak,
123 typedef struct _wordsink_impl
125 const IWordSinkVtbl *vtbl;
126 } wordsink_impl;
128 static wordsink_impl wordsink = { &wsvt };
130 static HRESULT WINAPI fillbuf_none(TEXT_SOURCE *ts)
132 return E_FAIL;
135 static HRESULT WINAPI fillbuf_many(TEXT_SOURCE *ts)
137 int i;
139 if (ts->awcBuffer == NULL)
140 ts->awcBuffer = teststring;
141 else
142 ts->awcBuffer += ts->iCur;
144 if (!ts->awcBuffer[0])
145 return E_FAIL;
147 for( i=0; ts->awcBuffer[i] && ts->awcBuffer[i] != ' '; i++)
149 if (ts->awcBuffer[i] == ' ')
150 i++;
152 ts->iCur = 0;
153 ts->iEnd = i;
155 return S_OK;
158 START_TEST(infosoft)
160 HRESULT r;
161 BOOL license;
162 IWordBreaker *wb = NULL;
163 TEXT_SOURCE ts;
165 r = CoInitialize(NULL);
166 ok( r == S_OK, "failed\n");
168 r = CoCreateInstance( &CLSID_wb_neutral, NULL, CLSCTX_INPROC_SERVER,
169 &_IID_IWordBreaker, (LPVOID)&wb);
171 if (FAILED(r))
172 return;
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"); */
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");
186 ok(wordnum == 4, "words not processed\n");
188 wordnum = 0;
189 ts.pfnFillTextBuffer = fillbuf_many;
190 ts.awcBuffer = teststring;
191 ts.iEnd = 0;
192 ts.iCur = 0;
194 r = fillbuf_many(&ts);
195 ok( r == S_OK, "failed\n");
197 r = IWordBreaker_BreakText( wb, &ts, (IWordSink*) &wordsink, NULL);
198 ok( r == S_OK, "failed\n");
200 ok(wordnum == 4, "words not processed\n");
201 IWordBreaker_Release( wb );
203 CoUninitialize();