Make a 16-bit test in wine for krnl386.exe16

Bruno Jesus 00cpxxx at gmail.com
Sun Nov 29 11:30:11 CST 2015


Hi all, I'm trying to create tests for GetPrivateProfileString16 but
it is not working as expected because the test is calling the kernel32
version of the function instead of the krnl386.exe16.

Is there any way to make a test that compiles and runs against krnl386
instead of kernel32?

I tried a few different things and the attached patch is the last
attempt (the tests are wrong but that is not the point yet).

Any help is appreciated, thanks in advance,
Bruno
-------------- next part --------------

---
 configure.ac                         |  1 +
 dlls/krnl386.exe16/file.c            |  1 +
 dlls/krnl386.exe16/tests/Makefile.in |  4 ++
 dlls/krnl386.exe16/tests/profile.c   | 74 ++++++++++++++++++++++++++++++++++++
 4 files changed, 80 insertions(+)
 create mode 100644 dlls/krnl386.exe16/tests/Makefile.in
 create mode 100644 dlls/krnl386.exe16/tests/profile.c

diff --git a/configure.ac b/configure.ac
index 2d2a168..eac282b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2952,6 +2952,7 @@ WINE_CONFIG_DLL(kernel32,,[clean,implib,mc])
 WINE_CONFIG_TEST(dlls/kernel32/tests)
 WINE_CONFIG_DLL(keyboard.drv16,enable_win16)
 WINE_CONFIG_DLL(krnl386.exe16,enable_win16,[implib],[kernel])
+WINE_CONFIG_TEST(dlls/krnl386.exe16/tests,enable_win16)
 WINE_CONFIG_DLL(ksuser)
 WINE_CONFIG_DLL(ktmw32)
 WINE_CONFIG_DLL(loadperf,,[implib])
diff --git a/dlls/krnl386.exe16/file.c b/dlls/krnl386.exe16/file.c
index 77908c2..f16ad00 100644
--- a/dlls/krnl386.exe16/file.c
+++ b/dlls/krnl386.exe16/file.c
@@ -539,6 +539,7 @@ INT16 WINAPI GetPrivateProfileString16( LPCSTR section, LPCSTR entry,
                                         LPCSTR def_val, LPSTR buffer,
                                         UINT16 len, LPCSTR filename )
 {
+printf("TEST\n\n");
     if (!section)
     {
         if (buffer && len) buffer[0] = 0;
diff --git a/dlls/krnl386.exe16/tests/Makefile.in b/dlls/krnl386.exe16/tests/Makefile.in
new file mode 100644
index 0000000..2fa1a5f
--- /dev/null
+++ b/dlls/krnl386.exe16/tests/Makefile.in
@@ -0,0 +1,4 @@
+TESTDLL   = krnl386.exe16
+
+C_SRCS = \
+	profile.c
diff --git a/dlls/krnl386.exe16/tests/profile.c b/dlls/krnl386.exe16/tests/profile.c
new file mode 100644
index 0000000..870f55c
--- /dev/null
+++ b/dlls/krnl386.exe16/tests/profile.c
@@ -0,0 +1,74 @@
+/*
+ * Unit tests for 16-bit profile functions
+ *
+ * Copyright (c) 2015 Bruno Jesus
+ *
+ * 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
+ */
+
+#include "wine/test.h"
+#include "windef.h"
+#include "winbase.h"
+#include "windows.h"
+
+static void create_test_file(LPCSTR name, LPCSTR data, DWORD size)
+{
+    HANDLE hfile;
+    DWORD count;
+
+    hfile = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+    ok(hfile != INVALID_HANDLE_VALUE, "cannot create %s\n", name);
+    WriteFile(hfile, data, size, &count, NULL);
+    CloseHandle(hfile);
+}
+
+static void test_GetPrivateProfileString16(const char *content)
+{
+    DWORD ret, len;
+    CHAR buf[MAX_PATH], *ptr;
+
+    static const char filename[] = ".\\winetest.ini";
+
+    create_test_file(filename, content, lstrlenA(content));
+
+    /* Run this test series with caching. Wine won't cache profile
+       files younger than 2.1 seconds. */
+    Sleep(2500);
+
+    buf[0] = '\0';
+    ret = GetPrivateProfileStringA("section1", NULL, NULL, buf, sizeof(buf), filename);
+    ok( ret == 0, "expected return size 0, got %d\n", ret );
+    ptr = buf;
+    ok( *ptr && !strcmp("name1", ptr), "expected name1, got %s\n", ptr);
+    ptr += strlen(ptr);
+    ok( *ptr && !strcmp("name2", ptr), "expected name2, got %s\n", ptr);
+    ptr += strlen(ptr);
+    ok( *ptr && !strcmp("name4", ptr), "expected name4, got %s\n", ptr);
+    ptr += strlen(ptr);
+    ok ( *ptr == '\0', "expected end of string sequence, got %s\n", ptr);
+
+    DeleteFileA(filename);
+}
+
+START_TEST(profile)
+{
+    test_GetPrivateProfileString16(
+        "[section1]\r\n"
+        "name1=val1\r\n"
+        "name2=\"val2\"\r\n"
+        "name3\r\n"
+        "name4=a\r\n"
+        "[section2]\r\n");
+}
-- 
2.1.4



More information about the wine-devel mailing list