2006-08-15 15:58:12 +02:00
|
|
|
/*
|
|
|
|
* tests for the language neutral word breaker
|
|
|
|
*
|
|
|
|
* Copyright 2006 Mike McCormack for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
2011-06-01 00:22:53 +02:00
|
|
|
#define CONST_VTABLE
|
2006-08-15 15:58:12 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ole2.h>
|
|
|
|
#include "indexsrv.h"
|
2021-05-10 15:54:11 +02:00
|
|
|
#include "cierror.h"
|
2006-08-15 15:58:12 +02:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
#include <initguid.h>
|
|
|
|
|
|
|
|
DEFINE_GUID(CLSID_wb_neutral, 0x369647e0,0x17b0,0x11ce,0x99,0x50,0x00,0xaa,0x00,0x4b,0xbb,0x1f);
|
|
|
|
DEFINE_GUID(_IID_IWordBreaker, 0xD53552C8,0x77E3,0x101A,0xB5,0x52,0x08,0x00,0x2B,0x33,0xB0,0xE6);
|
|
|
|
|
2020-10-01 23:26:29 +02:00
|
|
|
static const WCHAR teststring[] = L"square circle triangle box";
|
2006-08-15 15:58:12 +02:00
|
|
|
|
|
|
|
struct expected {
|
|
|
|
UINT ofs;
|
|
|
|
UINT len;
|
|
|
|
WCHAR data[10];
|
|
|
|
};
|
|
|
|
|
|
|
|
static int wordnum;
|
|
|
|
|
|
|
|
static struct expected testres[] = {
|
2020-10-01 23:26:29 +02:00
|
|
|
{ 0, 6, L"square" },
|
|
|
|
{ 7, 6, L"circle" },
|
|
|
|
{ 14, 8, L"triangle" },
|
|
|
|
{ 23, 3, L"box" },
|
2006-08-15 15:58:12 +02:00
|
|
|
};
|
|
|
|
|
2011-06-01 00:22:53 +02:00
|
|
|
static HRESULT WINAPI ws_QueryInterface(IWordSink *iface, REFIID riid, void **ppvObject)
|
2006-08-15 15:58:12 +02:00
|
|
|
{
|
|
|
|
ok(0, "not expected\n");
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2011-06-01 00:22:53 +02:00
|
|
|
static ULONG WINAPI ws_AddRef(IWordSink *iface)
|
2006-08-15 15:58:12 +02:00
|
|
|
{
|
|
|
|
ok(0, "not expected\n");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2011-06-01 00:22:53 +02:00
|
|
|
static ULONG WINAPI ws_Release(IWordSink *iface)
|
2006-08-15 15:58:12 +02:00
|
|
|
{
|
|
|
|
ok(0, "not expected\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-06-01 00:22:53 +02:00
|
|
|
static HRESULT WINAPI ws_PutWord(IWordSink *iface, ULONG cwc, const WCHAR *pwcInBuf,
|
2006-08-15 15:58:12 +02:00
|
|
|
ULONG cwcSrcLen, ULONG cwcSrcPos)
|
|
|
|
{
|
2021-05-10 15:53:19 +02:00
|
|
|
HRESULT rc = S_OK;
|
2021-05-10 15:53:57 +02:00
|
|
|
|
|
|
|
winetest_push_context("word %d", wordnum);
|
2021-05-10 15:53:19 +02:00
|
|
|
if (wordnum < ARRAY_SIZE(testres))
|
|
|
|
{
|
2022-02-28 08:26:57 +01:00
|
|
|
ok(testres[wordnum].len == cwcSrcLen, "expected length %d, got %ld\n",
|
2021-05-10 15:53:57 +02:00
|
|
|
testres[wordnum].len, cwcSrcLen);
|
|
|
|
ok(!cwcSrcPos || (testres[wordnum].ofs == cwcSrcPos),
|
2022-02-28 08:26:57 +01:00
|
|
|
"expected offset %d, got %ld\n", testres[wordnum].ofs, cwcSrcPos);
|
2021-05-10 15:53:57 +02:00
|
|
|
ok(!memcmp(testres[wordnum].data, pwcInBuf, cwcSrcLen),
|
|
|
|
"expected data %s, got %s\n",
|
|
|
|
wine_dbgstr_wn(testres[wordnum].data, cwcSrcLen),
|
|
|
|
wine_dbgstr_wn(pwcInBuf, cwcSrcLen));
|
2021-05-10 15:53:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(0, "found too many words: %d\n", wordnum + 1);
|
|
|
|
rc = E_FAIL;
|
|
|
|
}
|
2021-05-10 15:53:57 +02:00
|
|
|
winetest_pop_context();
|
|
|
|
|
2006-08-15 15:58:12 +02:00
|
|
|
wordnum++;
|
2021-05-10 15:53:19 +02:00
|
|
|
return rc;
|
2006-08-15 15:58:12 +02:00
|
|
|
}
|
|
|
|
|
2011-06-01 00:22:53 +02:00
|
|
|
static HRESULT WINAPI ws_PutAltWord(IWordSink *iface, ULONG cwc, const WCHAR *pwcInBuf,
|
2006-08-15 15:58:12 +02:00
|
|
|
ULONG cwcSrcLen, ULONG cwcSrcPos)
|
|
|
|
{
|
|
|
|
ok(0, "not expected\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-01 00:22:53 +02:00
|
|
|
static HRESULT WINAPI ws_StartAltPhrase(IWordSink *iface)
|
2006-08-15 15:58:12 +02:00
|
|
|
{
|
|
|
|
ok(0, "not expected\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-01 00:22:53 +02:00
|
|
|
static HRESULT WINAPI ws_EndAltPhrase(IWordSink *iface)
|
2006-08-15 15:58:12 +02:00
|
|
|
{
|
|
|
|
ok(0, "not expected\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-01 00:22:53 +02:00
|
|
|
static HRESULT WINAPI ws_PutBreak(IWordSink *iface, WORDREP_BREAK_TYPE breakType)
|
2006-08-15 15:58:12 +02:00
|
|
|
{
|
|
|
|
ok(0, "not expected\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWordSinkVtbl wsvt =
|
|
|
|
{
|
|
|
|
ws_QueryInterface,
|
|
|
|
ws_AddRef,
|
|
|
|
ws_Release,
|
|
|
|
ws_PutWord,
|
|
|
|
ws_PutAltWord,
|
|
|
|
ws_StartAltPhrase,
|
|
|
|
ws_EndAltPhrase,
|
|
|
|
ws_PutBreak,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _wordsink_impl
|
|
|
|
{
|
2011-06-01 00:22:53 +02:00
|
|
|
IWordSink IWordSink_iface;
|
2006-08-15 15:58:12 +02:00
|
|
|
} wordsink_impl;
|
|
|
|
|
2011-06-01 00:22:53 +02:00
|
|
|
static wordsink_impl wordsink = { { &wsvt } };
|
2006-08-15 15:58:12 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI fillbuf_none(TEXT_SOURCE *ts)
|
|
|
|
{
|
2021-05-10 15:54:11 +02:00
|
|
|
return WBREAK_E_END_OF_TEXT;
|
2006-08-15 15:58:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI fillbuf_many(TEXT_SOURCE *ts)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ts->awcBuffer == NULL)
|
|
|
|
ts->awcBuffer = teststring;
|
|
|
|
else
|
2021-05-10 15:55:26 +02:00
|
|
|
ts->awcBuffer += ts->iEnd;
|
2006-08-15 15:58:12 +02:00
|
|
|
|
|
|
|
if (!ts->awcBuffer[0])
|
2021-05-10 15:54:11 +02:00
|
|
|
return WBREAK_E_END_OF_TEXT;
|
2006-08-15 15:58:12 +02:00
|
|
|
|
|
|
|
for( i=0; ts->awcBuffer[i] && ts->awcBuffer[i] != ' '; i++)
|
|
|
|
;
|
|
|
|
if (ts->awcBuffer[i] == ' ')
|
|
|
|
i++;
|
|
|
|
|
|
|
|
ts->iCur = 0;
|
|
|
|
ts->iEnd = i;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(infosoft)
|
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
BOOL license;
|
|
|
|
IWordBreaker *wb = NULL;
|
|
|
|
TEXT_SOURCE ts;
|
|
|
|
|
|
|
|
r = CoInitialize(NULL);
|
2022-02-28 08:26:57 +01:00
|
|
|
ok( r == S_OK, "failed: %08lx\n", r);
|
2006-08-15 15:58:12 +02:00
|
|
|
|
|
|
|
r = CoCreateInstance( &CLSID_wb_neutral, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&_IID_IWordBreaker, (LPVOID)&wb);
|
|
|
|
|
|
|
|
if (FAILED(r))
|
|
|
|
return;
|
|
|
|
|
|
|
|
r = IWordBreaker_Init( wb, FALSE, 0x100, &license );
|
|
|
|
ok( r == S_OK, "failed to init the wordbreaker\n");
|
|
|
|
/* ok( license == TRUE, "should be no license\n"); */
|
|
|
|
|
|
|
|
wordnum = 0;
|
|
|
|
ts.pfnFillTextBuffer = fillbuf_none;
|
|
|
|
ts.awcBuffer = teststring;
|
|
|
|
ts.iEnd = lstrlenW(ts.awcBuffer);
|
|
|
|
ts.iCur = 0;
|
2011-06-01 00:22:53 +02:00
|
|
|
r = IWordBreaker_BreakText(wb, &ts, &wordsink.IWordSink_iface, NULL);
|
2022-02-28 08:26:57 +01:00
|
|
|
ok( r == S_OK, "failed: %08lx\n", r);
|
2006-08-15 15:58:12 +02:00
|
|
|
|
2021-05-10 15:53:57 +02:00
|
|
|
ok(wordnum == 4, "expected 4 words, got %d\n", wordnum);
|
2006-08-15 15:58:12 +02:00
|
|
|
|
|
|
|
wordnum = 0;
|
|
|
|
ts.pfnFillTextBuffer = fillbuf_many;
|
|
|
|
ts.awcBuffer = teststring;
|
|
|
|
ts.iEnd = 0;
|
|
|
|
ts.iCur = 0;
|
|
|
|
|
|
|
|
r = fillbuf_many(&ts);
|
2022-02-28 08:26:57 +01:00
|
|
|
ok( r == S_OK, "failed: %08lx\n", r);
|
2006-08-15 15:58:12 +02:00
|
|
|
|
2011-06-01 00:22:53 +02:00
|
|
|
r = IWordBreaker_BreakText(wb, &ts, &wordsink.IWordSink_iface, NULL);
|
2022-02-28 08:26:57 +01:00
|
|
|
ok( r == S_OK, "failed: %08lx\n", r);
|
2006-08-15 15:58:12 +02:00
|
|
|
|
2021-05-10 15:53:57 +02:00
|
|
|
ok(wordnum == 4, "expected 4 words, got %d\n", wordnum);
|
2006-08-15 15:58:12 +02:00
|
|
|
IWordBreaker_Release( wb );
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|