summarylogtreecommitdiffstats
path: root/1006_test-unicode-endianess.patch
blob: 82ce2e3ca02063db117f66343cf56eb7fd443572 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
The testsuite stores the expected result in little endian UTF-16, while
all the functions UTF conversion functions use the WCHAR type and assume
native endian. Convert the expected results to little endian on big
endian machines.

--- a/winpr/libwinpr/crt/test/TestUnicodeConversion.c
+++ b/winpr/libwinpr/crt/test/TestUnicodeConversion.c
@@ -4,6 +4,18 @@
 #include <winpr/error.h>
 #include <winpr/windows.h>
 
+#if defined(WIN32) || defined(WIN64)
+  #ifndef __LITTLE_ENDIAN
+    #define __LITTLE_ENDIAN 1234
+    #define __BIG_ENDIAN    4321
+  #endif
+  #ifndef __BYTE_ORDER
+    #define __BYTE_ORDER __LITTLE_ENDIAN
+  #endif
+#else
+  #include <endian.h>
+#endif
+
 /* Letters */
 
 static BYTE c_cedilla_UTF8[] = "\xC3\xA7\x00";
@@ -108,6 +120,22 @@
 	}
 }
 
+void utf16_le_to_ne(BYTE *data, int length)
+{
+#if __BYTE_ORDER == __BIG_ENDIAN
+	int i;
+
+	for (i = 0; i < length / 2; i++)
+	{
+		BYTE c;
+
+		c = data[i * 2];
+		data[i * 2] = data[i * 2 + 1];
+		data[i * 2 + 1] = c;
+	}
+#endif
+}
+
 int convert_utf8_to_utf16(BYTE* lpMultiByteStr, BYTE* expected_lpWideCharStr, int expected_cchWideChar)
 {
 	int length;
@@ -247,6 +275,7 @@
 	/* Letters */
 
 	printf("Letters\n");
+	utf16_le_to_ne(c_cedilla_UTF16, sizeof(c_cedilla_UTF16));
 
 	if (convert_utf8_to_utf16(c_cedilla_UTF8, c_cedilla_UTF16, c_cedilla_cchWideChar) < 1)
 		return -1;
@@ -257,6 +286,8 @@
 	/* English */
 
 	printf("English\n");
+	utf16_le_to_ne(en_Hello_UTF16, sizeof(en_Hello_UTF16));
+	utf16_le_to_ne(en_HowAreYou_UTF16, sizeof(en_HowAreYou_UTF16));
 
 	if (convert_utf8_to_utf16(en_Hello_UTF8, en_Hello_UTF16, en_Hello_cchWideChar) < 1)
 		return -1;
@@ -271,6 +302,8 @@
 	/* French */
 
 	printf("French\n");
+	utf16_le_to_ne(fr_Hello_UTF16, sizeof(fr_Hello_UTF16));
+	utf16_le_to_ne(fr_HowAreYou_UTF16, sizeof(fr_HowAreYou_UTF16));
 
 	if (convert_utf8_to_utf16(fr_Hello_UTF8, fr_Hello_UTF16, fr_Hello_cchWideChar) < 1)
 		return -1;
@@ -285,6 +318,8 @@
 	/* Russian */
 
 	printf("Russian\n");
+	utf16_le_to_ne(ru_Hello_UTF16, sizeof(ru_Hello_UTF16));
+	utf16_le_to_ne(ru_HowAreYou_UTF16, sizeof(ru_HowAreYou_UTF16));
 
 	if (convert_utf8_to_utf16(ru_Hello_UTF8, ru_Hello_UTF16, ru_Hello_cchWideChar) < 1)
 		return -1;
@@ -299,6 +334,8 @@
 	/* Arabic */
 
 	printf("Arabic\n");
+	utf16_le_to_ne(ar_Hello_UTF16, sizeof(ar_Hello_UTF16));
+	utf16_le_to_ne(ar_HowAreYou_UTF16, sizeof(ar_HowAreYou_UTF16));
 
 	if (convert_utf8_to_utf16(ar_Hello_UTF8, ar_Hello_UTF16, ar_Hello_cchWideChar) < 1)
 		return -1;
@@ -313,6 +350,8 @@
 	/* Chinese */
 
 	printf("Chinese\n");
+	utf16_le_to_ne(ch_Hello_UTF16, sizeof(ch_Hello_UTF16));
+	utf16_le_to_ne(ch_HowAreYou_UTF16, sizeof(ch_HowAreYou_UTF16));
 
 	if (convert_utf8_to_utf16(ch_Hello_UTF8, ch_Hello_UTF16, ch_Hello_cchWideChar) < 1)
 		return -1;