In Windows, when invoked with filename = NULL, these functions:
WritePrivateProfileStringW, WritePrivateProfileSectionW, GetPrivateProfileSectionNamesW, GetPrivateProfileStringW
Behave as if filename is "win.ini". Then if a map to "win.ini" (and the section if applicable) exists in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping it gets used.
Since in a freshly installed Wine and Windows a map to "win.ini" exists this test only verifies that default mapping behavior. It does not verify actual writting/reading to C:\windows\win.ini.
Signed-off-by: Carlos Rivera carlos@superkaos.org --- v2: fixed broken tests, fixed the wording of the commit. dlls/kernel32/tests/profile.c | 93 +++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+)
diff --git a/dlls/kernel32/tests/profile.c b/dlls/kernel32/tests/profile.c index f981558548..b7d239043b 100644 --- a/dlls/kernel32/tests/profile.c +++ b/dlls/kernel32/tests/profile.c @@ -1588,6 +1588,98 @@ static void test_registry_mapping(void) ok(ret, "got error %u\n", GetLastError()); }
+static void test_null_filename(void) +{ + /* Some profile functions assume filename is win.ini if filename is passed as NULL + then if a map for win.ini exists in IniFileMapping they use it */ + + HKEY mapping_key, mapped_key; + char buffer[1024]; + char* p; + int found = 0; + LSTATUS ret; + + if (GetFileAttributesA("C:/windows/win.ini") != INVALID_FILE_ATTRIBUTES) + { + ret = MoveFileA("C:/windows/win.ini", "C:/windows/winini.bak"); + + if (!ret) + { + skip("Failed to move C:/windows/win.ini out of the way to prevent possibly destructive tests.\n"); + return; + } + } + + ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, + "Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\win.ini", + 0, KEY_READ | KEY_WRITE | KEY_WOW64_64KEY, &mapping_key); + + if (ret) + { + skip("Failed to find a win.ini IniFileMapping registry entry\n"); + return; + } + + ret = RegSetValueExA(mapping_key, "section1", 0, REG_SZ, (BYTE *)"USR:section1_map", sizeof("USR:section1_map")); + ok(!ret, "got error %u\n", ret); + ret = WritePrivateProfileStringA(NULL, NULL, NULL, "win.ini"); + todo_wine ok(ret, "got error %u\n", GetLastError()); + + ret = WritePrivateProfileStringA("section1", "name1", "42", NULL); + ok(ret, "got error %u\n", ret); + + ret = DeleteFileA("C:/windows/win.ini"); + ok(!ret, "expected failure\n"); + + ret = RegOpenKeyExA(HKEY_CURRENT_USER, "section1_map", 0, KEY_READ | KEY_WRITE, &mapped_key); + check_registry_value(mapped_key, "name1", "42"); + + check_profile_string("section1", "name1", NULL, "42"); + + memset(buffer, 0xc, sizeof(buffer)); + ret = GetPrivateProfileSectionNamesA(buffer, sizeof(buffer), NULL); + ok(ret, "got error %u\n", ret); + + if (ret) + { + p = buffer; + while (p < (buffer + sizeof(buffer) - 1)) + { + int len = sizeof(buffer) - (p - buffer); + + if (!strncmp("section1", p, len)) + { + found = 1; + break; + } + while (*p++ && p < (buffer + sizeof(buffer) - 1)); + } + } + + ok(found, + "Expected "section1" in buffer, but buffer is %s\n", + debugstr_an(buffer, (ret + 2 >= sizeof(buffer) ? sizeof(buffer) : ret + 1))); + + ret = WritePrivateProfileSectionA("section1", "name2=mango\0", NULL); + ok(ret, "got error %u\n", ret); + + check_registry_value(mapped_key, "name2", "mango"); + + ret = DeleteFileA("C:/windows/win.ini"); + ok(!ret, "expected failure\n"); + + MoveFileA("C:/windows/winini.bak", "C:/windows/win.ini"); + + ret = RegDeleteValueA(mapping_key, "section1"); + ok(!ret, "got error %u\n", ret); + + ret = RegDeleteKeyA(HKEY_CURRENT_USER, "section1_map"); + ok(!ret, "got error %u\n", ret); + + RegCloseKey(mapped_key); + RegCloseKey(mapping_key); +}; + START_TEST(profile) { test_profile_int(); @@ -1617,4 +1709,5 @@ START_TEST(profile) test_WritePrivateProfileString(); test_profile_struct(); test_registry_mapping(); + test_null_filename(); }
So do in open_file_mapping_key as PROFILE_Open does.
Signed-off-by: Carlos Rivera carlos@superkaos.org --- v2: fixed the wording of the commit. dlls/kernel32/profile.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/dlls/kernel32/profile.c b/dlls/kernel32/profile.c index 43b303fa25..c987c3f6b9 100644 --- a/dlls/kernel32/profile.c +++ b/dlls/kernel32/profile.c @@ -1028,6 +1028,9 @@ static HKEY open_file_mapping_key( const WCHAR *filename ) static HKEY mapping_key; HKEY key;
+ if (!filename) + filename = wininiW; + EnterCriticalSection( &PROFILE_CritSect );
if (!mapping_key && RegOpenKeyExW( HKEY_LOCAL_MACHINE, mapping_pathW, 0, KEY_WOW64_64KEY, &mapping_key ))
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=78145
Your paranoid android.
=== debiant (32 bit Chinese:China report) ===
kernel32: process.c:1609: Test failed: Console:winBottom expected 24, but got 23
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=78144
Your paranoid android.
=== debiant (32 bit report) ===
kernel32: profile.c:222: Test succeeded inside todo block: expected ERROR_FILE_NOT_FOUND, got 2 profile.c:1632: Test failed: expected failure profile.c:1635: Test failed: got error 6 profile.c:1635: Test failed: expected "42", got "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc" profile.c:1635: Test failed: got type 9041992 profile.c:1637: Test failed: expected len 2, got 7 profile.c:1637: Test failed: expected "42", got "default" profile.c:1641: Test failed: got error 0 profile.c:1659: Test failed: Expected "section1" in buffer, but buffer is "\x00" profile.c:1666: Test failed: got error 6 profile.c:1666: Test failed: expected "mango", got "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\x01" profile.c:1666: Test failed: got type 13 profile.c:1677: Test failed: got error 2
=== debiant (32 bit French report) ===
kernel32: profile.c:222: Test succeeded inside todo block: expected ERROR_FILE_NOT_FOUND, got 2 profile.c:1632: Test failed: expected failure profile.c:1635: Test failed: got error 6 profile.c:1635: Test failed: expected "42", got "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc" profile.c:1635: Test failed: got type 9041992 profile.c:1637: Test failed: expected len 2, got 7 profile.c:1637: Test failed: expected "42", got "default" profile.c:1641: Test failed: got error 0 profile.c:1659: Test failed: Expected "section1" in buffer, but buffer is "\x00" profile.c:1666: Test failed: got error 6 profile.c:1666: Test failed: expected "mango", got "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\x01" profile.c:1666: Test failed: got type 13 profile.c:1677: Test failed: got error 2
=== debiant (32 bit Japanese:Japan report) ===
kernel32: profile.c:222: Test succeeded inside todo block: expected ERROR_FILE_NOT_FOUND, got 2 profile.c:1632: Test failed: expected failure profile.c:1635: Test failed: got error 6 profile.c:1635: Test failed: expected "42", got "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc" profile.c:1635: Test failed: got type 9041992 profile.c:1637: Test failed: expected len 2, got 7 profile.c:1637: Test failed: expected "42", got "default" profile.c:1641: Test failed: got error 0 profile.c:1659: Test failed: Expected "section1" in buffer, but buffer is "\x00" profile.c:1666: Test failed: got error 6 profile.c:1666: Test failed: expected "mango", got "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\x01" profile.c:1666: Test failed: got type 13 profile.c:1677: Test failed: got error 2
=== debiant (32 bit Chinese:China report) ===
kernel32: profile.c:222: Test succeeded inside todo block: expected ERROR_FILE_NOT_FOUND, got 2 profile.c:1632: Test failed: expected failure profile.c:1635: Test failed: got error 6 profile.c:1635: Test failed: expected "42", got "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc" profile.c:1635: Test failed: got type 9041992 profile.c:1637: Test failed: expected len 2, got 7 profile.c:1637: Test failed: expected "42", got "default" profile.c:1641: Test failed: got error 0 profile.c:1659: Test failed: Expected "section1" in buffer, but buffer is "\x00" profile.c:1666: Test failed: got error 6 profile.c:1666: Test failed: expected "mango", got "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\x01" profile.c:1666: Test failed: got type 13 profile.c:1677: Test failed: got error 2
=== debiant (32 bit WoW report) ===
kernel32: profile.c:222: Test succeeded inside todo block: expected ERROR_FILE_NOT_FOUND, got 2 profile.c:1632: Test failed: expected failure profile.c:1635: Test failed: got error 6 profile.c:1635: Test failed: expected "42", got "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc" profile.c:1635: Test failed: got type 9041992 profile.c:1637: Test failed: expected len 2, got 7 profile.c:1637: Test failed: expected "42", got "default" profile.c:1641: Test failed: got error 0 profile.c:1659: Test failed: Expected "section1" in buffer, but buffer is "\x00" profile.c:1666: Test failed: got error 6 profile.c:1666: Test failed: expected "mango", got "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\x01" profile.c:1666: Test failed: got type 13 profile.c:1677: Test failed: got error 2
=== debiant (64 bit WoW report) ===
kernel32: profile.c:222: Test succeeded inside todo block: expected ERROR_FILE_NOT_FOUND, got 2 profile.c:1632: Test failed: expected failure profile.c:1635: Test failed: got error 6 profile.c:1635: Test failed: expected "42", got "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc" profile.c:1635: Test failed: got type 9041992 profile.c:1637: Test failed: expected len 2, got 7 profile.c:1637: Test failed: expected "42", got "default" profile.c:1641: Test failed: got error 0 profile.c:1659: Test failed: Expected "section1" in buffer, but buffer is "\x00" profile.c:1666: Test failed: got error 6 profile.c:1666: Test failed: expected "mango", got "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\x01" profile.c:1666: Test failed: got type 13 profile.c:1677: Test failed: got error 2