[PATCH 3/3] wininet/tests: Added checks for bad return values and stop tests when it happens.

Morten Rønne morten.roenne at tdcadsl.dk
Thu Apr 5 01:53:22 CDT 2012


Added checks for bad return values and stop tests when it happens.
Using known bad values doesn't do any good, not even in tests.

This will remove various test crashes when people run the test on a full 
cache.

I have choosen this way to reduce the number of indentation changes, and 
since most checks after the one failing will be failing as well.

Morten Rønne
-------------- next part --------------
>From b0e647ff8392dd1b30c99ecb1557782bd9ecb328 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Morten=20R=C3=B8nne?= <morten.roenne at tdcadsl.dk>
Date: Fri, 30 Mar 2012 20:04:04 +0200
Subject: [PATCH 3/3] wininet/tests: Added checks for bad return values and
 stop tests when it happens. Using known bad values
 doesn't do any good, not even in tests.

---
 dlls/wininet/tests/urlcache.c |   73 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 72 insertions(+), 1 deletions(-)

diff --git a/dlls/wininet/tests/urlcache.c b/dlls/wininet/tests/urlcache.c
index 3b4627c..fd9092b 100644
--- a/dlls/wininet/tests/urlcache.c
+++ b/dlls/wininet/tests/urlcache.c
@@ -29,6 +29,8 @@
 
 #include "wine/test.h"
 
+#define bail_out    { ok(0, "Bailing out\n"); return; }
+
 #define TEST_URL    "http://urlcachetest.winehq.org/index.html"
 #define TEST_URL1   "Visited: user at http://urlcachetest.winehq.org/index.html"
 
@@ -60,7 +62,12 @@ static void test_find_url_cache_entriesA(void)
     hEnumHandle = FindFirstUrlCacheEntry(NULL, NULL, &cbCacheEntryInfo);
     ok(!hEnumHandle, "FindFirstUrlCacheEntry should have failed\n");
     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "FindFirstUrlCacheEntry should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
+    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) bail_out;
+
     lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo * sizeof(char));
+    if (lpCacheEntryInfo == NULL) bail_out;
+
+    ZeroMemory(lpCacheEntryInfo, cbCacheEntryInfo);
     cbCacheEntryInfoSaved = cbCacheEntryInfo;
     hEnumHandle = FindFirstUrlCacheEntry(NULL, lpCacheEntryInfo, &cbCacheEntryInfo);
     ok(hEnumHandle != NULL, "FindFirstUrlCacheEntry failed with error %d\n", GetLastError());
@@ -79,6 +86,9 @@ static void test_find_url_cache_entriesA(void)
             if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
             {
                 lpCacheEntryInfo = HeapReAlloc(GetProcessHeap(), 0, lpCacheEntryInfo, cbCacheEntryInfo);
+                if(lpCacheEntryInfo == NULL) break;
+
+                ZeroMemory(lpCacheEntryInfo, cbCacheEntryInfo);
                 cbCacheEntryInfoSaved = cbCacheEntryInfo;
                 ret = FindNextUrlCacheEntry(hEnumHandle, lpCacheEntryInfo, &cbCacheEntryInfo);
             }
@@ -121,8 +131,12 @@ static void test_GetUrlCacheEntryInfoExA(void)
     ok(!ret, "GetUrlCacheEntryInfoEx with zero-length buffer should fail\n");
     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
        "GetUrlCacheEntryInfoEx should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
+    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) bail_out;
 
     lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
+    if (lpCacheEntryInfo == NULL) bail_out;
+
+    ZeroMemory(lpCacheEntryInfo, cbCacheEntryInfo);
 
     SetLastError(0xdeadbeef);
     ret = GetUrlCacheEntryInfoEx(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo, NULL, NULL, NULL, 0x200);
@@ -134,6 +148,7 @@ static void test_GetUrlCacheEntryInfoExA(void)
     ok(ret, "GetUrlCacheEntryInfoEx failed with error %d\n", GetLastError());
 
     if (ret) check_cache_entry_infoA("GetUrlCacheEntryInfoEx", lpCacheEntryInfo);
+    else bail_out;
 
     cbCacheEntryInfo = 100000;
     SetLastError(0xdeadbeef);
@@ -235,6 +250,9 @@ static void test_IsUrlCacheEntryExpiredA(void)
     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
        "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
     info = HeapAlloc(GetProcessHeap(), 0, size);
+    if (info == NULL) bail_out;
+
+    ZeroMemory(info, size);
     ret = GetUrlCacheEntryInfo(TEST_URL, info, &size);
     ok(ret, "GetUrlCacheEntryInfo failed: %d\n", GetLastError());
     GetSystemTimeAsFileTime(&info->ExpireTime);
@@ -354,9 +372,11 @@ static void test_urlcacheA(void)
 
     ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0);
     ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
+    if (!ret) bail_out;
 
     ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA1, 0);
     ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
+    if (!ret) bail_out;
 
     ok(lstrcmpiA(filenameA, filenameA1), "expected a different file name\n");
 
@@ -364,12 +384,19 @@ static void test_urlcacheA(void)
 
     ret = CommitUrlCacheEntry(TEST_URL1, NULL, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY, NULL, 0, "html", NULL);
     ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
+    if (!ret) bail_out;
+
     cbCacheEntryInfo = 0;
     ret = GetUrlCacheEntryInfo(TEST_URL1, NULL, &cbCacheEntryInfo);
     ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
        "GetUrlCacheEntryInfo should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
+    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) bail_out;
+
     lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
+    if (lpCacheEntryInfo == NULL) bail_out;
+
+    ZeroMemory(lpCacheEntryInfo, cbCacheEntryInfo);
     ret = GetUrlCacheEntryInfo(TEST_URL1, lpCacheEntryInfo, &cbCacheEntryInfo);
     ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
     ok(!memcmp(&lpCacheEntryInfo->ExpireTime, &filetime_zero, sizeof(FILETIME)),
@@ -391,12 +418,19 @@ static void test_urlcacheA(void)
     ret = CommitUrlCacheEntry(TEST_URL1, NULL, now, now, NORMAL_CACHE_ENTRY,
             (LPBYTE)ok_header, strlen(ok_header), NULL, NULL);
     ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
+    if (!ret) bail_out;
+
     cbCacheEntryInfo = 0;
     ret = GetUrlCacheEntryInfo(TEST_URL1, NULL, &cbCacheEntryInfo);
     ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
        "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
+    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) bail_out;
+
     lpCacheEntryInfo2 = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
+    if (lpCacheEntryInfo2 == NULL) bail_out;
+
+    ZeroMemory(lpCacheEntryInfo2, cbCacheEntryInfo);
     ret = GetUrlCacheEntryInfo(TEST_URL1, lpCacheEntryInfo2, &cbCacheEntryInfo);
     ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
     /* but it does change the time.. */
@@ -441,12 +475,17 @@ static void test_urlcacheA(void)
     ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
        "RetrieveUrlCacheEntryFile should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
+    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) bail_out;
 
     lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
+    if (lpCacheEntryInfo == NULL) bail_out;
+
+    ZeroMemory(lpCacheEntryInfo, cbCacheEntryInfo);
     ret = RetrieveUrlCacheEntryFile(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo, 0);
     ok(ret, "RetrieveUrlCacheEntryFile failed with error %d\n", GetLastError());
 
     if (ret) check_cache_entry_infoA("RetrieveUrlCacheEntryFile", lpCacheEntryInfo);
+    else bail_out;
 
     HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
 
@@ -486,9 +525,11 @@ static void test_urlcacheA(void)
     /* Creating two entries with the same URL */
     ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0);
     ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
+    if (!ret) bail_out;
 
     ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA1, 0);
     ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
+    if (!ret) bail_out;
 
     ok(lstrcmpiA(filenameA, filenameA1), "expected a different file name\n");
 
@@ -515,7 +556,12 @@ static void test_urlcacheA(void)
     ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
        "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
+    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) bail_out;
+
     lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
+    if (lpCacheEntryInfo == NULL) bail_out;
+
+    ZeroMemory(lpCacheEntryInfo, cbCacheEntryInfo);
     ret = GetUrlCacheEntryInfo(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo);
     ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
     /* with the previous entry type retained.. */
@@ -560,8 +606,12 @@ static void test_urlcacheA(void)
     ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
        "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
+    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) bail_out;
 
     lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
+    if (lpCacheEntryInfo == NULL) bail_out;
+
+    ZeroMemory(lpCacheEntryInfo, cbCacheEntryInfo);
     ret = RetrieveUrlCacheEntryFile(TEST_URL, lpCacheEntryInfo,
             &cbCacheEntryInfo, 0);
     ok(ret, "RetrieveUrlCacheEntryFile failed with error %d\n", GetLastError());
@@ -580,7 +630,9 @@ static void test_urlcacheA(void)
     }
 
     lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
-    memset(lpCacheEntryInfo, 0, cbCacheEntryInfo);
+    if (lpCacheEntryInfo == NULL) bail_out;
+
+    ZeroMemory(lpCacheEntryInfo, cbCacheEntryInfo);
     ret = GetUrlCacheEntryInfo(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo);
     todo_wine
     ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
@@ -670,6 +722,8 @@ static void test_urlcacheA(void)
 
     ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0);
     ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
+    if (!ret) bail_out;
+
     create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
     ret = CommitUrlCacheEntry(TEST_URL, filenameA, filetime_zero, filetime_zero,
             NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY,
@@ -681,7 +735,12 @@ static void test_urlcacheA(void)
     ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
        "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
+    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) bail_out;
+
     lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
+    if (lpCacheEntryInfo == NULL) bail_out;
+
+    ZeroMemory(lpCacheEntryInfo, cbCacheEntryInfo);
     ret = GetUrlCacheEntryInfo(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo);
     ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
     ok(lpCacheEntryInfo->CacheEntryType & (NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY),
@@ -702,6 +761,8 @@ static void test_urlcacheA(void)
     /* Test once again, setting the exempt delta via SetUrlCacheEntryInfo */
     ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0);
     ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
+    if (!ret) bail_out;
+
     create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
     ret = CommitUrlCacheEntry(TEST_URL, filenameA, filetime_zero, filetime_zero,
             NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY,
@@ -713,7 +774,12 @@ static void test_urlcacheA(void)
     ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
        "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
+    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) bail_out;
+
     lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
+    if (lpCacheEntryInfo == NULL) bail_out;
+
+    ZeroMemory(lpCacheEntryInfo, cbCacheEntryInfo);
     ret = GetUrlCacheEntryInfo(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo);
     ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
     ok(lpCacheEntryInfo->CacheEntryType & (NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY),
@@ -745,6 +811,8 @@ static void test_urlcacheA(void)
 
     ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA1, 0);
     ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
+    if (!ret) bail_out;
+
     create_and_write_file(filenameA1, &zero_byte, sizeof(zero_byte));
 
     ret = CommitUrlCacheEntry(TEST_URL, filenameA1, filetime_zero, filetime_zero,
@@ -834,6 +902,9 @@ START_TEST(urlcache)
     pDeleteUrlCacheEntryA = (void*)GetProcAddress(hdll, "DeleteUrlCacheEntryA");
     pUnlockUrlCacheEntryFileA = (void*)GetProcAddress(hdll, "UnlockUrlCacheEntryFileA");
     test_urlcacheA();
+    if (filenameA[0]) DeleteFile(filenameA);
+    if (filenameA1[0]) DeleteFile(filenameA1);
+
     test_FindCloseUrlCache();
     test_GetDiskInfoA();
 }
-- 
1.7.5.4



More information about the wine-patches mailing list