[KERNEL32_WINETEST]
[reactos.git] / rostests / winetests / kernel32 / format_msg.c
index 1c4dd76..1f56440 100755 (executable)
@@ -125,6 +125,7 @@ static void test_message_from_string_wide(void)
     static const WCHAR s_sp002sp001[] = {' ',' ','0','0','0','2',',',' ',' ','0','0','1',0};
     static const WCHAR s_sp002sp003[] = {' ',' ','0','0','0','2',',',' ','0','0','0','0','3',0};
     static const WCHAR s_sp001004[]   = {' ',' ','0','0','1',',','0','0','0','0','0','4',0};
+    static const WCHAR s_null[]       = {'(','n','u','l','l',')',0};
 
     static const WCHAR init_buf[] = {'x', 'x', 'x', 'x', 'x', 'x'};
     static const WCHAR broken_buf[] = {'t','e','s','t','x','x'};
@@ -143,7 +144,7 @@ static void test_message_from_string_wide(void)
     {
         SetLastError(0xdeadbeef);
         memcpy(out, init_buf, sizeof(init_buf));
-        r = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, NULL, 0,
+        FormatMessageW(FORMAT_MESSAGE_FROM_STRING, NULL, 0,
             0, out, sizeof(out)/sizeof(WCHAR), NULL);
     }
 
@@ -283,6 +284,7 @@ static void test_message_from_string_wide(void)
     r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_14d, 0,
         0, out, sizeof(out)/sizeof(WCHAR), 1);
     ok(!lstrcmpW(s_14d, out), "failed out=%s\n", wine_dbgstr_w(out));
+    ok(r==4,"failed: r=%d\n", r);
 
     /* a single digit, left justified */
     r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_1_4d, 0,
@@ -380,6 +382,12 @@ static void test_message_from_string_wide(void)
     ok(!lstrcmpW(s_crlfcrlf, out), "failed out=%s\n", wine_dbgstr_w(out));
     ok(r==4,"failed: r=%d\n", r);
 
+    /* null string as argument */
+    r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_1, 0,
+        0, out, sizeof(out)/sizeof(WCHAR), NULL);
+    ok(!lstrcmpW(s_null, out),"failed out=[%s]\n", wine_dbgstr_w(out));
+    ok(r==6,"failed: r=%d\n",r);
+
     /* precision and width */
 
     r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_13s,
@@ -466,7 +474,7 @@ static void test_message_from_string(void)
     {
         SetLastError(0xdeadbeef);
         memcpy(out, init_buf, sizeof(init_buf));
-        r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, NULL, 0,
+        FormatMessageA(FORMAT_MESSAGE_FROM_STRING, NULL, 0,
             0, out, sizeof(out)/sizeof(CHAR), NULL);
     }
 
@@ -475,9 +483,7 @@ static void test_message_from_string(void)
     memcpy(out, init_buf, sizeof(init_buf));
     r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, "", 0,
         0, out, sizeof(out)/sizeof(CHAR), NULL);
-    ok(!memcmp(out, init_buf, sizeof(init_buf)) ||
-       broken(!strcmp("", out)), /* Win9x */
-       "Expected the buffer to be untouched\n");
+    ok(!memcmp(out, init_buf, sizeof(init_buf)), "Expected the buffer to be untouched\n");
     ok(r==0, "succeeded: r=%d\n", r);
     ok(GetLastError()==0xdeadbeef,
        "last error %u\n", GetLastError());
@@ -509,29 +515,17 @@ static void test_message_from_string(void)
     memcpy(out, init_buf, sizeof(init_buf));
     r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, "%1", 0,
         0, out, sizeof(out)/sizeof(CHAR), NULL);
-    ok(!memcmp(out, init_buf, sizeof(init_buf)) ||
-       broken(!strcmp("%1", out)), /* Win9x */
-       "Expected the buffer to be untouched\n");
-    ok(r==0 ||
-       broken(r==2), /* Win9x */
-       "succeeded: r=%d\n", r);
-    ok(GetLastError()==ERROR_INVALID_PARAMETER ||
-       broken(GetLastError()==0xdeadbeef), /* Win9x */
-       "last error %u\n", GetLastError());
+    ok(!memcmp(out, init_buf, sizeof(init_buf)), "Expected the buffer to be untouched\n");
+    ok(r==0, "succeeded: r=%d\n", r);
+    ok(GetLastError()==ERROR_INVALID_PARAMETER, "last error %u\n", GetLastError());
 
     SetLastError(0xdeadbeef);
     memcpy(out, init_buf, sizeof(init_buf));
     r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, "%1", 0,
         0, out, sizeof(out)/sizeof(CHAR), NULL);
-    ok(!memcmp(out, init_buf, sizeof(init_buf)) ||
-       broken(!strcmp("%1", out)), /* Win9x */
-       "Expected the buffer to be untouched\n");
-    ok(r==0 ||
-       broken(r==2), /* Win9x */
-       "succeeded: r=%d\n", r);
-    ok(GetLastError()==ERROR_INVALID_PARAMETER ||
-       broken(GetLastError()==0xdeadbeef), /* Win9x */
-       "last error %u\n", GetLastError());
+    ok(!memcmp(out, init_buf, sizeof(init_buf)), "Expected the buffer to be untouched\n");
+    ok(r==0, "succeeded: r=%d\n", r);
+    ok(GetLastError()==ERROR_INVALID_PARAMETER, "last error %u\n", GetLastError());
 
     /* using the format feature */
     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!s!", 0,
@@ -713,6 +707,12 @@ static void test_message_from_string(void)
     ok(!strcmp("\r\n\r\n", out),"failed out=[%s]\n",out);
     ok(r==4,"failed: r=%d\n",r);
 
+    /* null string as argument */
+    r = doit(FORMAT_MESSAGE_FROM_STRING, "%1", 0,
+        0, out, sizeof(out)/sizeof(CHAR), NULL);
+    ok(!strcmp("(null)", out),"failed out=[%s]\n",out);
+    ok(r==6,"failed: r=%d\n",r);
+
     /* precision and width */
 
     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!3s!",
@@ -765,12 +765,8 @@ static void test_message_from_string(void)
     /* line feed */
     r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "hi\n", 0,
         0, out, sizeof(out)/sizeof(CHAR));
-    ok(!strcmp("hi ", out) ||
-       broken(!strcmp("hi\r\n", out)), /* Win9x */
-       "failed out=[%s]\n",out);
-    ok(r==3 ||
-       broken(r==4), /* Win9x */
-       "failed: r=%d\n",r);
+    ok(!strcmp("hi ", out), "failed out=[%s]\n",out);
+    ok(r==3, "failed: r=%d\n",r);
 
     /* carriage return line feed */
     r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "hi\r\n", 0,
@@ -820,9 +816,7 @@ static void test_message_ignore_inserts(void)
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "%0test", 0, 0, out,
                          sizeof(out)/sizeof(CHAR), NULL);
     ok(ret == 0, "Expected FormatMessageA to return 0, got %d\n", ret);
-    ok(!memcmp(out, init_buf, sizeof(init_buf)) ||
-       broken(!strcmp("", out)), /* Win9x */
-       "Expected the output buffer to be untouched\n");
+    ok(!memcmp(out, init_buf, sizeof(init_buf)), "Expected the output buffer to be untouched\n");
     ok(GetLastError() == 0xdeadbeef, "Expected GetLastError() to return 0xdeadbeef, got %u\n", GetLastError());
 
     /* Insert sequences are ignored. */
@@ -834,12 +828,8 @@ static void test_message_ignore_inserts(void)
     /* Only the "%n", "%r", and "%t" escape sequences are processed. */
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "%%% %.%!", 0, 0, out,
                          sizeof(out)/sizeof(CHAR), NULL);
-    ok(ret == 8 ||
-       broken(ret == 7) /* Win9x */,
-       "Expected FormatMessageA to return 8, got %d\n", ret);
-    ok(!strcmp("%%% %.%!", out) ||
-       broken(!strcmp("%%% %.!", out)) /* Win9x */,
-       "Expected output string \"%%%%%% %%.%%!\", got %s\n", out);
+    ok(ret == 8, "Expected FormatMessageA to return 8, got %d\n", ret);
+    ok(!strcmp("%%% %.%!", out), "Expected output string \"%%%%%% %%.%%!\", got %s\n", out);
 
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "%n%r%t", 0, 0, out,
                          sizeof(out)/sizeof(CHAR), NULL);
@@ -871,12 +861,8 @@ static void test_message_ignore_inserts(void)
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS |
                          FORMAT_MESSAGE_MAX_WIDTH_MASK, "hi\n", 0, 0, out,
                          sizeof(out)/sizeof(CHAR), NULL);
-    ok(!strcmp("hi ", out) ||
-       broken(!strcmp("hi\r\n", out)), /* Win9x */
-       "Expected output string \"hi \", got %s\n", out);
-    ok(ret == 3 ||
-       broken(ret == 4), /* Win9x */
-       "Expected FormatMessageA to return 3, got %d\n", ret);
+    ok(!strcmp("hi ", out), "Expected output string \"hi \", got %s\n", out);
+    ok(ret == 3, "Expected FormatMessageA to return 3, got %d\n", ret);
 
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS |
                          FORMAT_MESSAGE_MAX_WIDTH_MASK, "hi\r\n", 0, 0, out,
@@ -1104,50 +1090,37 @@ static void test_message_null_buffer(void)
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 0, 0, NULL, 0, NULL);
     error = GetLastError();
     ok(!ret, "FormatMessageA returned %u\n", ret);
-    ok(error == ERROR_INSUFFICIENT_BUFFER ||
-       error == ERROR_INVALID_PARAMETER, /* win9x */
-       "last error %u\n", error);
+    ok(error == ERROR_INSUFFICIENT_BUFFER, "last error %u\n", error);
 
     SetLastError(0xdeadbeef);
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 0, 0, NULL, 1, NULL);
     error = GetLastError();
     ok(!ret, "FormatMessageA returned %u\n", ret);
-    ok(error == ERROR_INSUFFICIENT_BUFFER ||
-       error == ERROR_INVALID_PARAMETER, /* win9x */
-       "last error %u\n", error);
+    ok(error == ERROR_INSUFFICIENT_BUFFER, "last error %u\n", error);
 
     if (0) /* crashes on Windows */
     {
         SetLastError(0xdeadbeef);
-        ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 0, 0, NULL, 256, NULL);
-        error = GetLastError();
-        ok(!ret, "FormatMessageA returned %u\n", ret);
-        trace("last error %u\n", error);
+        FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 0, 0, NULL, 256, NULL);
     }
 
     SetLastError(0xdeadbeef);
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, 0, 0, NULL, 0, NULL);
     error = GetLastError();
     ok(!ret, "FormatMessageA returned %u\n", ret);
-    ok(error == ERROR_NOT_ENOUGH_MEMORY ||
-       error == ERROR_INVALID_PARAMETER, /* win9x */
-       "last error %u\n", error);
+    ok(error == ERROR_NOT_ENOUGH_MEMORY, "last error %u\n", error);
 
     SetLastError(0xdeadbeef);
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, 0, 0, NULL, 1, NULL);
     error = GetLastError();
     ok(!ret, "FormatMessageA returned %u\n", ret);
-    ok(error == ERROR_NOT_ENOUGH_MEMORY ||
-       error == ERROR_INVALID_PARAMETER, /* win9x */
-       "last error %u\n", error);
+    ok(error == ERROR_NOT_ENOUGH_MEMORY, "last error %u\n", error);
 
     SetLastError(0xdeadbeef);
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, 0, 0, NULL, 256, NULL);
     error = GetLastError();
     ok(!ret, "FormatMessageA returned %u\n", ret);
-    ok(error == ERROR_NOT_ENOUGH_MEMORY ||
-       error == ERROR_INVALID_PARAMETER, /* win9x */
-       "last error %u\n", error);
+    ok(error == ERROR_NOT_ENOUGH_MEMORY, "last error %u\n", error);
 }
 
 static void test_message_null_buffer_wide(void)
@@ -1296,7 +1269,7 @@ static void test_message_allocate_buffer_wide(void)
     if (0) /* crashes on Windows */
     {
         buf = (WCHAR *)0xdeadbeef;
-        ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
+        FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
                              NULL, 0, 0, (WCHAR *)&buf, 0, NULL);
     }
 
@@ -1393,18 +1366,14 @@ static void test_message_from_hmodule(void)
     /* Test a message string with an insertion without passing any variadic arguments. */
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 193 /* ERROR_BAD_EXE_FORMAT */,
                          MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out)/sizeof(CHAR), NULL);
-    ok(ret == 0 ||
-       broken(ret != 0), /* Win9x */
-       "FormatMessageA returned non-zero\n");
+    ok(ret == 0, "FormatMessageA returned non-zero\n");
 
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE |
                          FORMAT_MESSAGE_ARGUMENT_ARRAY, h, 193 /* ERROR_BAD_EXE_FORMAT */,
                          MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out)/sizeof(CHAR), NULL);
-    ok(ret == 0 ||
-       broken(ret != 0), /* Win9x */
-       "FormatMessageA returned non-zero\n");
+    ok(ret == 0, "FormatMessageA returned non-zero\n");
 
-    /*Test nonexistent messageID with varying language ID's Note: FormatMessageW behaves the same*/
+    /*Test nonexistent messageID with varying language IDs Note: FormatMessageW behaves the same*/
     SetLastError(0xdeadbeef);
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 3044,
                          MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out)/sizeof(CHAR), NULL);
@@ -1471,9 +1440,7 @@ static void test_message_invalid_flags(void)
     ptr = (char *)0xdeadbeef;
     ret = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER, "test", 0, 0, (char *)&ptr, 0, NULL);
     ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
-    ok(ptr == NULL ||
-       broken(ptr == (char *)0xdeadbeef), /* Win9x */
-       "Expected output pointer to be initialized to NULL, got %p\n", ptr);
+    ok(ptr == NULL, "Expected output pointer to be initialized to NULL, got %p\n", ptr);
     ok(GetLastError() == ERROR_INVALID_PARAMETER,
        "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
        GetLastError());