[PATCH 3/6] ws2_32/tests: Expand tests for WSAStringToAddress().

Zebediah Figura zfigura at codeweavers.com
Mon Aug 2 19:37:39 CDT 2021


Adapted from RtlIpv4StringToAddress() tests.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 dlls/ws2_32/tests/protocol.c | 101 ++++++++++++++++++++++++++++++-----
 1 file changed, 89 insertions(+), 12 deletions(-)

diff --git a/dlls/ws2_32/tests/protocol.c b/dlls/ws2_32/tests/protocol.c
index 27ef6ff92aa..b2a933d4f51 100644
--- a/dlls/ws2_32/tests/protocol.c
+++ b/dlls/ws2_32/tests/protocol.c
@@ -1093,14 +1093,91 @@ static void test_WSAStringToAddress(void)
     }
     ipv4_tests[] =
     {
-        { "0.0.0.0", 0 },
-        { "127.127.127.127", 0x7f7f7f7f },
-        { "255.255.255.255", 0xffffffff },
-        { "127.127.127.127:65535", 0x7f7f7f7f, 65535 },
-        { "255.255.255.255:65535", 0xffffffff, 65535 },
-        { "2001::1", 0xd1070000, 0, WSAEINVAL },
-        { "1.2.3.", 0, 0, WSAEINVAL },
-        { "", 0, 0, WSAEINVAL },
+        { "",                       0,          0, WSAEINVAL },
+        { " ",                      0,          0, WSAEINVAL },
+        { "1.1.1.1",                0x01010101 },
+        { "0.0.0.0",                0 },
+        { "127.127.127.127",        0x7f7f7f7f },
+        { "127.127.127.127:",       0x7f7f7f7f, 0, WSAEINVAL },
+        { "127.127.127.127:0",      0x7f7f7f7f, 0, WSAEINVAL },
+        { "127.127.127.127:123",    0x7f7f7f7f, 123 },
+        { "127.127.127.127:65535",  0x7f7f7f7f, 65535 },
+        { "127.127.127.127:65537",  0x7f7f7f7f, 0, WSAEINVAL },
+        { "127.127.127.127::1",     0x7f7f7f7f, 0, WSAEINVAL },
+        { "127.127.127.127:0xAbCd", 0x7f7f7f7f, 43981 },
+        { "127.127.127.127:0XaBcD", 0x7f7f7f7f, 43981 },
+        { "127.127.127.127:0x",     0x7f7f7f7f, 0, WSAEINVAL },
+        { "127.127.127.127:0x10000",0x7f7f7f7f, 0, WSAEINVAL },
+        { "127.127.127.127:010",    0x7f7f7f7f, 8 },
+        { "127.127.127.127:007",    0x7f7f7f7f, 7 },
+        { "127.127.127.127:08",     0x7f7f7f7f, 0, WSAEINVAL },
+        { "127.127.127.127:008",    0x7f7f7f7f, 0, WSAEINVAL },
+        { "127.127.127.127:0a",     0x7f7f7f7f, 0, WSAEINVAL },
+        { "127.127.127.127:0o10",   0x7f7f7f7f, 0, WSAEINVAL },
+        { "127.127.127.127:0b10",   0x7f7f7f7f, 0, WSAEINVAL },
+        { "255.255.255.255",        0xffffffff },
+        { "255.255.255.255:123",    0xffffffff, 123 },
+        { "255.255.255.255:65535",  0xffffffff, 65535 },
+        { "255.255.255.256",        0,          0, WSAEINVAL },
+        { "a",                      0,          0, WSAEINVAL },
+        { "1.1.1.0xaA",             0x010101aa },
+        { "1.1.1.0XaA",             0x010101aa },
+        { "1.1.1.0x",               0,          0, WSAEINVAL },
+        { "1.1.1.0xff",             0x010101ff },
+        { "1.1.1.0x100",            0,          0, WSAEINVAL },
+        { "1.1.1.010",              0x01010108 },
+        { "1.1.1.00",               0x01010100 },
+        { "1.1.1.007",              0x01010107 },
+        { "1.1.1.08",               0,          0, WSAEINVAL },
+        { "1.1.1.008",              0x01010100, 0, WSAEINVAL },
+        { "1.1.1.0a",               0x01010100, 0, WSAEINVAL },
+        { "1.1.1.0o10",             0x01010100, 0, WSAEINVAL },
+        { "1.1.1.0b10",             0x01010100, 0, WSAEINVAL },
+        { "1.1.1.-2",               0,          0, WSAEINVAL },
+        { "1",                      0x00000001 },
+        { "-1",                     0,          0, WSAEINVAL },
+        { "1:1",                    0x00000001, 1 },
+        { "1.2",                    0x01000002 },
+        { "1.2:1",                  0x01000002, 1 },
+        { "1000.2000",              0,          0, WSAEINVAL },
+        { "1.2.",                   0,          0, WSAEINVAL },
+        { "1..2",                   0,          0, WSAEINVAL },
+        { "1...2",                  0,          0, WSAEINVAL },
+        { "1.2.3",                  0x01020003 },
+        { "1.2.3.",                 0,          0, WSAEINVAL },
+        { "1.2.3:1",                0x01020003, 1 },
+        { "203569230",              0x0c22384e },
+        { "203569230:123",          0x0c22384e, 123 },
+        { "2001::1",                0x000007d1, 0, WSAEINVAL },
+        { "1.223756",               0x01036a0c },
+        { "3.4.756",                0x030402f4 },
+        { "756.3.4",                0,          0, WSAEINVAL },
+        { "3.756.4",                0,          0, WSAEINVAL },
+        { "3.4.756.1",              0,          0, WSAEINVAL },
+        { "3.4.65536",              0,          0, WSAEINVAL },
+        { "3.4.5.6.7",              0,          0, WSAEINVAL },
+        { "3.4.5.+6",               0,          0, WSAEINVAL },
+        { " 3.4.5.6",               0,          0, WSAEINVAL },
+        { "\t3.4.5.6",              0,          0, WSAEINVAL },
+        { "3.4.5.6 ",               0x03040506, 0, WSAEINVAL },
+        { "3.4.5.6:7 ",             0x03040506, 0, WSAEINVAL },
+        { "3.4.5.6: 7",             0x03040506, 0, WSAEINVAL },
+        { "3. 4.5.6",               0,          0, WSAEINVAL },
+        { ".",                      0,          0, WSAEINVAL },
+        { "[0.1.2.3]",              0,          0, WSAEINVAL },
+        { "0x00010203",             0x00010203 },
+        { "0X00010203",             0x00010203 },
+        { "0x00010203:10",          0x00010203, 10 },
+        { "0x1234",                 0x00001234 },
+        { "0x123456789",            0x23456789 },
+        { "0x00010Q03",             0x00000010, 0, WSAEINVAL },
+        { "x00010203",              0,          0, WSAEINVAL },
+        { "1234BEEF",               0x000004d2, 0, WSAEINVAL },
+        { "017700000001",           0x7f000001 },
+        { "0777",                   0x000001ff },
+        { "0777:10",                0x000001ff, 10 },
+        { "::1",                    0,          0, WSAEINVAL },
+        { ":1",                     0,          0, WSAEINVAL },
     };
     static struct
     {
@@ -1167,12 +1244,12 @@ static void test_WSAStringToAddress(void)
             ok( sockaddr.sin_family == expected_family,
                 "WSAStringToAddress(%s) gave family %d, expected %d\n",
                 wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_family, expected_family );
-            ok( sockaddr.sin_addr.s_addr == ipv4_tests[j].address,
+            ok( sockaddr.sin_addr.s_addr == htonl( ipv4_tests[j].address ),
                 "WSAStringToAddress(%s) gave address %08x, expected %08x\n",
-                wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_addr.s_addr, ipv4_tests[j].address );
-            ok( sockaddr.sin_port == ipv4_tests[j].port,
+                wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_addr.s_addr, htonl( ipv4_tests[j].address) );
+            ok( sockaddr.sin_port == htons( ipv4_tests[j].port ),
                 "WSAStringToAddress(%s) gave port %04x, expected %04x\n",
-                wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_port, ipv4_tests[j].port );
+                wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_port, htons( ipv4_tests[j].port ) );
             ok( len == expected_len,
                 "WSAStringToAddress(%s) gave length %d, expected %d\n",
                 wine_dbgstr_a( ipv4_tests[j].input ), len, expected_len );
-- 
2.32.0




More information about the wine-devel mailing list