Commit 39899fd1 authored by Paul Graham's avatar Paul Graham Committed by Alexandre Julliard

kernel32: Fix failure reporting in WritePrivateProfile* and add tests.

Conformance tests based on work by Fabian Maurer, with some adaptations. Signed-off-by: 's avatarPaul Graham <development@omega-software.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 030e4db2
......@@ -1391,7 +1391,7 @@ BOOL WINAPI WritePrivateProfileStringW( LPCWSTR section, LPCWSTR entry,
SetLastError(ERROR_FILE_NOT_FOUND);
} else {
ret = PROFILE_SetString( section, entry, string, FALSE);
PROFILE_FlushFile();
if (ret) ret = PROFILE_FlushFile();
}
}
......@@ -1447,11 +1447,10 @@ BOOL WINAPI WritePrivateProfileSectionW( LPCWSTR section,
else if (PROFILE_Open( filename, TRUE )) {
if (!string) {/* delete the named section*/
ret = PROFILE_SetString(section,NULL,NULL, FALSE);
PROFILE_FlushFile();
} else {
PROFILE_DeleteAllKeys(section);
ret = TRUE;
while(*string) {
while(*string && ret) {
LPWSTR buf = HeapAlloc( GetProcessHeap(), 0, (strlenW(string)+1) * sizeof(WCHAR) );
strcpyW( buf, string );
if((p = strchrW( buf, '='))) {
......@@ -1461,8 +1460,8 @@ BOOL WINAPI WritePrivateProfileSectionW( LPCWSTR section,
HeapFree( GetProcessHeap(), 0, buf );
string += strlenW(string)+1;
}
PROFILE_FlushFile();
}
if (ret) ret = PROFILE_FlushFile();
}
RtlLeaveCriticalSection( &PROFILE_CritSect );
......@@ -1744,7 +1743,7 @@ BOOL WINAPI WritePrivateProfileStructW (LPCWSTR section, LPCWSTR key,
if (PROFILE_Open( filename, TRUE )) {
ret = PROFILE_SetString( section, key, outstring, FALSE);
PROFILE_FlushFile();
if (ret) ret = PROFILE_FlushFile();
}
RtlLeaveCriticalSection( &PROFILE_CritSect );
......
......@@ -25,6 +25,7 @@
#include "windef.h"
#include "winbase.h"
#include "windows.h"
#include "sddl.h"
#define KEY "ProfileInt"
#define SECTION "Test"
......@@ -534,6 +535,41 @@ static BOOL emptystr_ok(CHAR emptystr[MAX_PATH])
return TRUE;
}
static void test_profile_directory_readonly(void)
{
BOOL ret;
CHAR path_folder[MAX_PATH];
CHAR path_file[MAX_PATH];
const char *sddl_string_everyone_readonly = "D:PAI(A;;0x1200a9;;;WD)";
SECURITY_ATTRIBUTES attributes = {0};
char lpStruct[] = { 's', 't', 'r', 'i', 'n', 'g' };
attributes.nLength = sizeof(attributes);
ret = ConvertStringSecurityDescriptorToSecurityDescriptorA(sddl_string_everyone_readonly, SDDL_REVISION_1, &attributes.lpSecurityDescriptor, NULL);
ok(ret == TRUE, "ConvertStringSecurityDescriptorToSecurityDescriptor failed: %d\n", GetLastError());
GetTempPathA(MAX_PATH, path_folder);
lstrcatA(path_folder, "wine-test");
strcpy(path_file, path_folder);
lstrcatA(path_file, "\\tmp.ini");
ret = CreateDirectoryA(path_folder, &attributes);
ok(ret == TRUE, "CreateDirectoryA failed: %d\n", GetLastError());
ret = WritePrivateProfileStringA("App", "key", "string", path_file);
ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
ret = WritePrivateProfileSectionA("App", "key=string", path_file);
ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
ret = WritePrivateProfileStructA("App", "key", lpStruct, sizeof(lpStruct), path_file);
ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
ret = RemoveDirectoryA(path_folder);
ok(ret == TRUE, "RemoveDirectoryA failed: %d\n", GetLastError());
}
static void test_GetPrivateProfileString(const char *content, const char *descript)
{
DWORD ret, len;
......@@ -1132,6 +1168,7 @@ START_TEST(profile)
test_profile_existing();
test_profile_delete_on_close();
test_profile_refresh();
test_profile_directory_readonly();
test_GetPrivateProfileString(
"[section1]\r\n"
"name1=val1\r\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment