[KERNEL32_WINETEST]
[reactos.git] / rostests / winetests / kernel32 / profile.c
index 2320270..211d0c6 100755 (executable)
@@ -146,6 +146,8 @@ static void test_profile_string(void)
     ret=GetPrivateProfileStringW(emptyW, keyW, emptyW, bufW,
                                  sizeof(bufW)/sizeof(bufW[0]), TESTFILE2W);
     todo_wine
+    ok(ret == 13, "expected 13, got %u\n", ret);
+    todo_wine
     ok(!lstrcmpW(valsectionW,bufW), "expected %s, got %s\n",
         wine_dbgstr_w(valsectionW), wine_dbgstr_w(bufW) );
 
@@ -153,6 +155,8 @@ static void test_profile_string(void)
     ret=GetPrivateProfileStringW(sW, emptyW, emptyW, bufW,
                                  sizeof(bufW)/sizeof(bufW[0]), TESTFILE2W);
     todo_wine
+    ok(ret == 10, "expected 10, got %u\n", ret);
+    todo_wine
     ok(!lstrcmpW(valnokeyW,bufW), "expected %s, got %s\n",
         wine_dbgstr_w(valnokeyW), wine_dbgstr_w(bufW) );
 
@@ -275,7 +279,7 @@ static void test_profile_sections_names(void)
     ok( (buf[ret-1] == 0 && buf[ret] == 0) ||
         broken(buf[ret-1] == 0 && buf[ret-2] == 0), /* Win9x, WinME */
         "returned buffer not terminated with double-null\n" );
-    
+
     /* Test with exactly fitting buffer */
     memset(buf, 0xc, sizeof(buf));
     ret = GetPrivateProfileSectionNamesA( buf, 28, testfile3 );
@@ -287,7 +291,7 @@ static void test_profile_sections_names(void)
         broken(buf[ret+1] == 0xc && buf[ret] == 0) || /* NT4, W2K, WinXP */
         broken(buf[ret-1] == 0 && buf[ret-2] == 0), /* Win9x, WinME */
         "returned buffer not terminated with double-null\n" );
-    
+
     /* Test with a buffer too small */
     memset(buf, 0xc, sizeof(buf));
     ret = GetPrivateProfileSectionNamesA( buf, 27, testfile3 );
@@ -298,7 +302,7 @@ static void test_profile_sections_names(void)
     ok( (buf[ret+1] == 0 && buf[ret] == 0) ||
         broken(buf[count] == 0 && buf[count+1] == 0), /* Win9x, WinME */
         "returned buffer not terminated with double-null\n" );
-    
+
     /* Tests on nonexistent file */
     memset(buf, 0xc, sizeof(buf));
     ret = GetPrivateProfileSectionNamesA( buf, 10, ".\\not_here.ini" );
@@ -328,7 +332,7 @@ static void test_profile_sections_names(void)
     ok( (bufW[ret+1] == 0 && bufW[ret] == 0) || /* W2K3 and higher */
         broken(bufW[ret+1] == 0xcccc && bufW[ret] == 0), /* NT4, W2K, WinXP */
         "returned buffer not terminated with double-null\n" );
-    
+
     /* Test with a buffer too small */
     memset(bufW, 0xcc, sizeof(bufW));
     ret = GetPrivateProfileSectionNamesW( bufW, 27, testfile3W );
@@ -444,8 +448,8 @@ static void test_profile_delete_on_close(void)
 
     h = CreateFile(testfile, GENERIC_WRITE, FILE_SHARE_READ, NULL,
                     CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
-    ok( WriteFile( h, contents, sizeof contents - 1, &size, NULL ),
-                    "Cannot write test file: %x\n", GetLastError() );
+    res = WriteFile( h, contents, sizeof contents - 1, &size, NULL );
+    ok( res, "Cannot write test file: %x\n", GetLastError() );
     ok( size == sizeof contents - 1, "Test file: partial write\n");
 
     SetLastError(0xdeadbeef);
@@ -468,8 +472,8 @@ static void test_profile_refresh(void)
 
     h = CreateFile(testfile, GENERIC_WRITE, FILE_SHARE_READ, NULL,
                     CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
-    ok( WriteFile( h, contents1, sizeof contents1 - 1, &size, NULL ),
-                    "Cannot write test file: %x\n", GetLastError() );
+    res = WriteFile( h, contents1, sizeof contents1 - 1, &size, NULL );
+    ok( res, "Cannot write test file: %x\n", GetLastError() );
     ok( size == sizeof contents1 - 1, "Test file: partial write\n");
 
     SetLastError(0xdeadbeef);
@@ -484,8 +488,8 @@ static void test_profile_refresh(void)
 
     h = CreateFile(testfile, GENERIC_WRITE, FILE_SHARE_READ, NULL,
                     CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
-    ok( WriteFile( h, contents2, sizeof contents2 - 1, &size, NULL ),
-                    "Cannot write test file: %x\n", GetLastError() );
+    res = WriteFile( h, contents2, sizeof contents2 - 1, &size, NULL );
+    ok( res, "Cannot write test file: %x\n", GetLastError() );
     ok( size == sizeof contents2 - 1, "Test file: partial write\n");
 
     SetLastError(0xdeadbeef);
@@ -496,6 +500,13 @@ static void test_profile_refresh(void)
 
     /* This also deletes the file */
     CloseHandle(h);
+
+    /* Cache must be invalidated if file no longer exists and default must be returned */
+    SetLastError(0xdeadbeef);
+    res = GetPrivateProfileInt(SECTION, KEY, 421, testfile);
+    ok( res == 421 ||
+        broken(res == 0 && GetLastError() == 0xdeadbeef), /* Win9x, WinME */
+        "Got %d instead of 421\n", res);
 }
 
 static void create_test_file(LPCSTR name, LPCSTR data, DWORD size)