From: Bartosz Kosiorek gang65@poczta.onet.pl
--- dlls/mlang/tests/Makefile.in | 3 +- dlls/mlang/tests/linebreakconsole.c | 144 ++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 dlls/mlang/tests/linebreakconsole.c
diff --git a/dlls/mlang/tests/Makefile.in b/dlls/mlang/tests/Makefile.in index 21ec4b2465f..255a9d3ff33 100644 --- a/dlls/mlang/tests/Makefile.in +++ b/dlls/mlang/tests/Makefile.in @@ -2,4 +2,5 @@ TESTDLL = mlang.dll IMPORTS = mlang oleaut32 ole32 user32 gdi32
C_SRCS = \ - mlang.c + mlang.c \ + linebreakconsole.c diff --git a/dlls/mlang/tests/linebreakconsole.c b/dlls/mlang/tests/linebreakconsole.c new file mode 100644 index 00000000000..c25ac7588c2 --- /dev/null +++ b/dlls/mlang/tests/linebreakconsole.c @@ -0,0 +1,144 @@ +/* + * Unit test suite for IMLangLineBreakConsole interface API. + * + * Copyright 2023 Bartosz Kosiorek + * + * 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 + +#include <stdarg.h> +#include <stdio.h> + +#include "windef.h" +#include "winbase.h" +#include "winerror.h" +#include "mlang.h" +#include "mimeole.h" + +#include "wine/test.h" + +static void test_BreakLineA(IMLangLineBreakConsole *mlbc) +{ + LCID locale = 1024; + UINT uCodePage; + CHAR *pszSrc = malloc(100); + LONG cchMax = 20; + LONG cMaxColumns; + LONG cchLine, cchSkip; + HRESULT res; + + cMaxColumns = 10; + uCodePage = CP_UNICODE; + strcpy(pszSrc, "Ś†rińg Wi†h Póliśh ćharacterś"); + res = IMLangLineBreakConsole_BreakLineA(mlbc, locale, uCodePage, pszSrc, cchMax, cMaxColumns, &cchLine, &cchSkip); + todo_wine ok(res == E_FAIL, "got %08lx\n", res); + todo_wine ok(cchLine == 0, "got %li\n", cchLine); + ok(cchSkip == 0, "got %li\n", cchSkip); + + uCodePage = 10; // Some random value + strcpy(pszSrc, "String With strange codepage"); + res = IMLangLineBreakConsole_BreakLineA(mlbc, locale, uCodePage, pszSrc, cchMax, cMaxColumns, &cchLine, &cchSkip); + todo_wine ok(res == E_FAIL, "got %08lx\n", res); + todo_wine ok(cchLine == 0, "got %li\n", cchLine); + ok(cchSkip == 0, "got %li\n", cchSkip); + + uCodePage = CP_USASCII; + strcpy(pszSrc, "StringWithoutAnySpaces"); + res = IMLangLineBreakConsole_BreakLineA(mlbc, locale, uCodePage, pszSrc, cchMax, cMaxColumns, &cchLine, &cchSkip); + ok(res == S_OK, "got %08lx\n", res); + ok(cchLine == 10, "got %li\n", cchLine); + ok(cchSkip == 0, "got %li\n", cchSkip); + + /* Single Unicode character */ + strcpy(pszSrc, "Ź "); + res = IMLangLineBreakConsole_BreakLineA(mlbc, locale, uCodePage, pszSrc, cchMax, cMaxColumns, &cchLine, &cchSkip); + ok(res == S_OK, "got %08lx\n", res); + ok(cchLine == 2, "got %li\n", cchLine); + todo_wine ok((cchSkip == 18), "got %li\n", cchSkip); + + /* Unicode characters */ + strcpy(pszSrc, "Ś†rińg Wi†h Póliśh ćharacterś"); + res = IMLangLineBreakConsole_BreakLineA(mlbc, locale, uCodePage, pszSrc, cchMax, cMaxColumns, &cchLine, &cchSkip); + ok(res == S_OK, "got %08lx\n", res); + ok(cchLine == 10, "got %li\n", cchLine); + ok((cchSkip == 0) || /* on machine with zh_CN Simplified Chinese Localization */ + (cchSkip == 1), "got %li\n", cchSkip); + + strcpy(pszSrc, " String With Many Spaces"); + res = IMLangLineBreakConsole_BreakLineA(mlbc, locale, uCodePage, pszSrc, cchMax, cMaxColumns, &cchLine, &cchSkip); + ok(res == S_OK, "got %08lx\n", res); + todo_wine ok(cchLine == 10, "got %li\n", cchLine); + todo_wine ok(cchSkip == 10, "got %li\n", cchSkip); + + strcpy(pszSrc, " Whole line with spaces"); + res = IMLangLineBreakConsole_BreakLineA(mlbc, locale, uCodePage, pszSrc, cchMax, cMaxColumns, &cchLine, &cchSkip); + ok(res == S_OK, "got %08lx\n", res); + ok(cchLine == 0, "got %li\n", cchLine); + todo_wine ok(cchSkip == 20, "got %li\n", cchSkip); + + strcpy(pszSrc, "\tString\t\t\tWith\tTabs"); + res = IMLangLineBreakConsole_BreakLineA(mlbc, locale, uCodePage, pszSrc, cchMax, cMaxColumns, &cchLine, &cchSkip); + ok(res == S_OK, "got %08lx\n", res); + todo_wine ok(cchLine == 7, "got %li\n", cchLine); + todo_wine ok(cchSkip == 3, "got %li\n", cchSkip); + + strcpy(pszSrc, "\tString \t\t With\tSpaces And Tabs"); + res = IMLangLineBreakConsole_BreakLineA(mlbc, locale, uCodePage, pszSrc, cchMax, cMaxColumns, &cchLine, &cchSkip); + ok(res == S_OK, "got %08lx\n", res); + todo_wine ok(cchLine == 7, "got %li\n", cchLine); + todo_wine ok(cchSkip == 4, "got %li\n", cchSkip); + + strcpy(pszSrc, "String\nWith\nNew\nLines"); + res = IMLangLineBreakConsole_BreakLineA(mlbc, locale, uCodePage, pszSrc, cchMax, cMaxColumns, &cchLine, &cchSkip); + ok(res == S_OK, "got %08lx\n", res); + todo_wine ok(cchLine == 6, "got %li\n", cchLine); + todo_wine ok(cchSkip == 1, "got %li\n", cchSkip); + + strcpy(pszSrc, "\nString\nWith\nNew\nLine at Beginning"); + res = IMLangLineBreakConsole_BreakLineA(mlbc, locale, uCodePage, pszSrc, cchMax, cMaxColumns, &cchLine, &cchSkip); + ok(res == S_OK, "got %08lx\n", res); + todo_wine ok(cchLine == 0, "got %li\n", cchLine); + todo_wine ok(cchSkip == 1, "got %li\n", cchSkip); + + strcpy(pszSrc, " S t r i n g S i n g l e L e t t e r s "); + res = IMLangLineBreakConsole_BreakLineA(mlbc, locale, uCodePage, pszSrc, cchMax, cMaxColumns, &cchLine, &cchSkip); + ok(res == S_OK, "got %08lx\n", res); + todo_wine ok(cchLine == 10, "got %li\n", cchLine); + ok(cchSkip == 1, "got %li\n", cchSkip); + + free(pszSrc); +} + +START_TEST(linebreakconsole) +{ + IMLangLineBreakConsole* pMLangLineBreakConsole = NULL; + HRESULT res; + + CoInitialize(NULL); + + trace("IMLangLineBreakConsole\n"); + res = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER, + &IID_IMLangLineBreakConsole, + (void **)&pMLangLineBreakConsole); + if (res == S_OK) + { + test_BreakLineA(pMLangLineBreakConsole); + IMLangLineBreakConsole_Release(pMLangLineBreakConsole); + } + + CoUninitialize(); +}