kernel: Add tests for GetPrivateProfileSectionNames. Make behaviour the same as observed on Windows XP.

Frank Richter frank.richter at gmail.com
Fri Aug 25 13:00:53 CDT 2006



-------------- next part --------------
>From b8d713d9b45c97535356ef802c34ccc6aeaee7f6 Mon Sep 17 00:00:00 2001
From: Frank Richter frank.richter at gmail.com <frank.richter at gmail.com>
Date: Fri, 25 Aug 2006 19:59:46 +0200
Subject: [PATCH] kernel: Add tests for GetPrivateProfileSectionNames. Make behaviour the same as observed on Windows XP.
---
 dlls/kernel/profile.c       |    8 ++++--
 dlls/kernel/tests/profile.c |   53 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/dlls/kernel/profile.c b/dlls/kernel/profile.c
index a0f1dca..dbd6590 100644
--- a/dlls/kernel/profile.c
+++ b/dlls/kernel/profile.c
@@ -906,7 +906,7 @@ static INT PROFILE_GetSectionNames( LPWS
     while ((section!=NULL)) {
         if (section->name[0]) {
             tmplen = strlenW(section->name)+1;
-            if (tmplen > buflen) {
+            if (tmplen >= buflen) {
                 if (buflen > 0) {
                     memcpy(buf, section->name, (buflen-1) * sizeof(WCHAR));
                     buf += buflen-1;
@@ -1626,12 +1626,14 @@ DWORD WINAPI GetPrivateProfileSectionNam
     retW = GetPrivateProfileSectionNamesW(bufferW, size, filenameW.Buffer);
     if (retW && size)
     {
-        ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW, buffer, size, NULL, NULL);
+        ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW+1, buffer, size-1, NULL, NULL);
         if (!ret)
         {
-            ret = size;
+            ret = size-2;
             buffer[size-1] = 0;
         }
+        else
+          ret = ret-1;
     }
 
     RtlFreeUnicodeString(&filenameW);
diff --git a/dlls/kernel/tests/profile.c b/dlls/kernel/tests/profile.c
index 3ab1df9..4379ee2 100644
--- a/dlls/kernel/tests/profile.c
+++ b/dlls/kernel/tests/profile.c
@@ -135,8 +135,61 @@ static void test_profile_string(void)
     DeleteFileA( TESTFILE2);
 }
 
+static void test_profile_sections(void)
+{
+    HANDLE h;
+    int ret;
+    DWORD count;
+    char buf[100];
+    WCHAR bufW[100];
+    static const char content[]="[section1]\r\n[section2]\r\n[section3]\r\n";
+    static const char testfile3[]=".\\testwine3.ini";
+    static const WCHAR testfile3W[]={ '.','\\','t','e','s','t','w','i','n','e','3','.','i','n','i',0 };
+    DeleteFileA( testfile3 );
+    h = CreateFileA( testfile3, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
+        FILE_ATTRIBUTE_NORMAL, NULL);
+    ok( h != INVALID_HANDLE_VALUE, " cannot create %s\n", testfile3);
+    if( h == INVALID_HANDLE_VALUE) return;
+    WriteFile( h, content, sizeof(content), &count, NULL);
+    CloseHandle( h);
+
+    /* Test with sufficiently large buffer */
+    ret = GetPrivateProfileSectionNamesA( buf, 29, testfile3 );
+    ok( ret == 27, "expected return size 27, got %d\n", ret );
+    ok( buf[ret-1] == 0 && buf[ret] == 0, "returned buffer not terminated with double-null\n" );
+    
+    /* Test with exactly fitting buffer */
+    ret = GetPrivateProfileSectionNamesA( buf, 28, testfile3 );
+    ok( ret == 26, "expected return size 26, got %d\n", ret );
+    ok( buf[ret+1] == 0 && buf[ret] == 0, "returned buffer not terminated with double-null\n" );
+    
+    /* Test with a buffer too small */
+    ret = GetPrivateProfileSectionNamesA( buf, 27, testfile3 );
+    ok( ret == 25, "expected return size 25, got %d\n", ret );
+    ok( buf[ret+1] == 0 && buf[ret] == 0, "returned buffer not terminated with double-null\n" );
+    
+    
+    /* Test with sufficiently large buffer */
+    ret = GetPrivateProfileSectionNamesW( bufW, 29, testfile3W );
+    ok( ret == 27, "expected return size 27, got %d\n", ret );
+    ok( buf[ret-1] == 0 && buf[ret] == 0, "returned buffer not terminated with double-null\n" );
+    
+    /* Test with exactly fitting buffer */
+    ret = GetPrivateProfileSectionNamesW( bufW, 28, testfile3W );
+    ok( ret == 26, "expected return size 26, got %d\n", ret );
+    ok( buf[ret+1] == 0 && buf[ret] == 0, "returned buffer not terminated with double-null\n" );
+    
+    /* Test with a buffer too small */
+    ret = GetPrivateProfileSectionNamesW( bufW, 27, testfile3W );
+    ok( ret == 25, "expected return size 25, got %d\n", ret );
+    ok( buf[ret+1] == 0 && buf[ret] == 0, "returned buffer not terminated with double-null\n" );
+    
+    DeleteFileA( testfile3 );
+}
+
 START_TEST(profile)
 {
     test_profile_int();
     test_profile_string();
+    test_profile_sections();
 }
-- 
1.4.1.1



More information about the wine-patches mailing list