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(); }