kernel32/tests: Add line-wrapping tests for FormatMessage().

Francois Gouget fgouget at free.fr
Tue Jun 19 17:51:39 CDT 2012


---

Using FormatMessage to handle the line-wrapping instead of hardcoding it 
in the resources could probably simplify translations a bit.

 dlls/kernel32/tests/format_msg.c |  127 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 127 insertions(+)

diff --git a/dlls/kernel32/tests/format_msg.c b/dlls/kernel32/tests/format_msg.c
index 1f56440..50e13f4 100644
--- a/dlls/kernel32/tests/format_msg.c
+++ b/dlls/kernel32/tests/format_msg.c
@@ -997,6 +997,132 @@ static void test_message_ignore_inserts_wide(void)
     ok(!lstrcmpW(s_2sp, out), "Expected output string \"  \", got %s\n", wine_dbgstr_w(out));
 }
 
+static void test_message_wrap(void)
+{
+    DWORD ret;
+    int i;
+    CHAR in[300], out[300], ref[300];
+
+    /* No need for wrapping */
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 20,
+                         "short long line", 0, 0, out, sizeof(out), NULL);
+    ok(ret == 15, "Expected FormatMessageW to return 15, got %d\n", ret);
+    ok(!strcmp("short long line", out),"failed out=[%s]\n",out);
+
+    /* Wrap the last word */
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 11,
+                         "short long line", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 16, "Expected FormatMessageW to return 16, got %d\n", ret);
+    todo_wine ok(!strcmp("short long\r\nline", out),"failed out=[%s]\n",out);
+
+    /* Strictly less than 10 characters per line! */
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 10,
+                         "short long line", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 16, "Expected FormatMessageW to return 16, got %d\n", ret);
+    todo_wine ok(!strcmp("short\r\nlong line", out),"failed out=[%s]\n",out);
+
+    /* Word longer than the line */
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 8,
+                         "shortlongline", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 15, "Expected FormatMessageW to return 15, got %d\n", ret);
+    todo_wine ok(!strcmp("shortlon\r\ngline", out),"failed out=[%s]\n",out);
+
+    /* Wrap the line multiple times */
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 7,
+                         "short long line", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 17, "Expected FormatMessageW to return 17, got %d\n", ret);
+    todo_wine ok(!strcmp("short\r\nlong\r\nline", out),"failed out=[%s]\n",out);
+
+    /* '\n's in the source are ignored */
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 11,
+                         "short\nlong line", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 16, "Expected FormatMessageW to return 16, got %d\n", ret);
+    todo_wine ok(!strcmp("short long\r\nline", out),"failed out=[%s]\n",out);
+
+    /* '%n's are converted into line feeds */
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 11,
+                         "short%n%nlong line", 0, 0, out, sizeof(out), NULL);
+    ok(ret == 18, "Expected FormatMessageW to return 18, got %d\n", ret);
+    ok(!strcmp("short\r\n\r\nlong line", out),"failed out=[%s]\n",out);
+
+    /* '%n's count as starting a new line and combine with line wrapping */
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 10,
+                         "short%nlong line", 0, 0, out, sizeof(out), NULL);
+    ok(ret == 16, "Expected FormatMessageW to return 16, got %d\n", ret);
+    ok(!strcmp("short\r\nlong line", out),"failed out=[%s]\n",out);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 8,
+                         "short%nlong line", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 17, "Expected FormatMessageW to return 17, got %d\n", ret);
+    todo_wine ok(!strcmp("short\r\nlong\r\nline", out),"failed out=[%s]\n",out);
+
+    /* '%r's also count as starting a new line and all */
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 10,
+                         "short%rlong line", 0, 0, out, sizeof(out), NULL);
+    ok(ret == 15, "Expected FormatMessageW to return 15, got %d\n", ret);
+    ok(!strcmp("short\rlong line", out),"failed out=[%s]\n",out);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 8,
+                         "short%rlong line", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 16, "Expected FormatMessageW to return 16, got %d\n", ret);
+    todo_wine ok(!strcmp("short\rlong\r\nline", out),"failed out=[%s]\n",out);
+
+    /* IGNORE_INSERTS does not prevent line wrapping or disable '%n' */
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS | 8,
+                         "short%nlong line%1", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 19, "Expected FormatMessageW to return 19, got %d\n", ret);
+    todo_wine ok(!strcmp("short\r\nlong\r\nline%1", out),"failed out=[%s]\n",out);
+
+    /* MAX_WIDTH_MASK is the same as specifying an infinite line width */
+    strcpy(in, "first line%n");
+    strcpy(ref, "first line\r\n");
+    for (i=0; i < 26; i++)
+    {
+        strcat(in, "123456789 ");
+        strcat(ref, "123456789 ");
+    }
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK,
+                         in, 0, 0, out, sizeof(out), NULL);
+    ok(ret == 272, "Expected FormatMessageW to return 272, got %d\n", ret);
+    ok(!strcmp(ref, out),"failed out=[%s]\n",out);
+
+    /* Wrapping and non-space characters */
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 11,
+                         "short long\tline", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 16, "Expected FormatMessageW to return 16, got %d\n", ret);
+    todo_wine ok(!strcmp("short\r\nlong\tline", out),"failed out=[%s]\n",out);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 11,
+                         "short long-line", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 16, "Expected FormatMessageW to return 16, got %d\n", ret);
+    todo_wine ok(!strcmp("short\r\nlong-line", out),"failed out=[%s]\n",out);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 11,
+                         "short long_line", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 16, "Expected FormatMessageW to return 16, got %d\n", ret);
+    todo_wine ok(!strcmp("short\r\nlong_line", out),"failed out=[%s]\n",out);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 11,
+                         "short long.line", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 16, "Expected FormatMessageW to return 16, got %d\n", ret);
+    todo_wine ok(!strcmp("short\r\nlong.line", out),"failed out=[%s]\n",out);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 11,
+                         "short long,line", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 16, "Expected FormatMessageW to return 16, got %d\n", ret);
+    todo_wine ok(!strcmp("short\r\nlong,line", out),"failed out=[%s]\n",out);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 11,
+                         "short long!line", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 16, "Expected FormatMessageW to return 16, got %d\n", ret);
+    todo_wine ok(!strcmp("short\r\nlong!line", out),"failed out=[%s]\n",out);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | 11,
+                         "short long?line", 0, 0, out, sizeof(out), NULL);
+    todo_wine ok(ret == 16, "Expected FormatMessageW to return 16, got %d\n", ret);
+    todo_wine ok(!strcmp("short\r\nlong?line", out),"failed out=[%s]\n",out);
+}
+
 static void test_message_insufficient_buffer(void)
 {
     static const char init_buf[] = {'x', 'x', 'x', 'x', 'x'};
@@ -1593,6 +1719,7 @@ START_TEST(format_msg)
 
     test_message_from_string();
     test_message_ignore_inserts();
+    test_message_wrap();
     test_message_insufficient_buffer();
     test_message_null_buffer();
     test_message_allocate_buffer();
-- 
1.7.10



More information about the wine-patches mailing list