4 #include <winpr/winpr.h>
5 #include <winpr/tchar.h>
6 #include <winpr/dsparse.h>
8 static BOOL test_DsMakeSpnA(
void)
10 LPCSTR testServiceClass =
"HTTP";
11 LPCSTR testServiceName =
"LAB1-W2K8R2-GW.lab1.awake.local";
12 LPCSTR testSpn =
"HTTP/LAB1-W2K8R2-GW.lab1.awake.local";
14 CHAR Spn[100] = { 0 };
18 status = DsMakeSpnA(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, NULL);
20 if (status != ERROR_INVALID_PARAMETER)
22 printf(
"DsMakeSpnA: expected ERROR_INVALID_PARAMETER\n");
27 status = DsMakeSpnA(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, NULL);
29 if (status != ERROR_BUFFER_OVERFLOW)
31 printf(
"DsMakeSpnA: expected ERROR_BUFFER_OVERFLOW\n");
37 printf(
"DsMakeSpnA: SpnLength mismatch: Actual: %" PRIu32
", Expected: 37\n", SpnLength);
41 status = DsMakeSpnA(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, Spn);
43 if (status != ERROR_SUCCESS)
45 printf(
"DsMakeSpnA: expected ERROR_SUCCESS\n");
49 if (strcmp(Spn, testSpn) != 0)
51 printf(
"DsMakeSpnA: SPN mismatch: Actual: %s, Expected: %s\n", Spn, testSpn);
55 printf(
"DsMakeSpnA: %s\n", Spn);
61 static BOOL test_DsMakeSpnW(
void)
63 const CHAR ctestServiceClass[] = {
'H',
'T',
'T',
'P',
'\0' };
64 const CHAR ctestServiceName[] = {
'L',
'A',
'B',
'1',
'-',
'W',
'2',
'K',
'8',
'R',
'2',
65 '-',
'G',
'W',
'.',
'l',
'a',
'b',
'1',
'.',
'a',
'w',
66 'a',
'k',
'e',
'.',
'l',
'o',
'c',
'a',
'l',
'\0' };
67 const CHAR ctestSpn[] = {
'H',
'T',
'T',
'P',
'/',
'L',
'A',
'B',
'1',
'-',
'W',
'2',
'K',
68 '8',
'R',
'2',
'-',
'G',
'W',
'.',
'l',
'a',
'b',
'1',
'.',
'a',
69 'w',
'a',
'k',
'e',
'.',
'l',
'o',
'c',
'a',
'l',
'\0' };
70 WCHAR testServiceClass[ARRAYSIZE(ctestServiceClass)] = { 0 };
71 WCHAR testServiceName[ARRAYSIZE(ctestServiceName)] = { 0 };
72 WCHAR testSpn[ARRAYSIZE(ctestSpn)] = { 0 };
75 WCHAR Spn[100] = { 0 };
79 (void)ConvertUtf8NToWChar(ctestServiceClass, ARRAYSIZE(ctestServiceClass), testServiceClass,
80 ARRAYSIZE(testServiceClass));
81 (void)ConvertUtf8NToWChar(ctestServiceName, ARRAYSIZE(ctestServiceName), testServiceName,
82 ARRAYSIZE(testServiceName));
83 (void)ConvertUtf8NToWChar(ctestSpn, ARRAYSIZE(ctestSpn), testSpn, ARRAYSIZE(testSpn));
85 status = DsMakeSpnW(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, NULL);
87 if (status != ERROR_INVALID_PARAMETER)
89 printf(
"DsMakeSpnW: expected ERROR_INVALID_PARAMETER\n");
94 status = DsMakeSpnW(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, NULL);
96 if (status != ERROR_BUFFER_OVERFLOW)
98 printf(
"DsMakeSpnW: expected ERROR_BUFFER_OVERFLOW\n");
104 printf(
"DsMakeSpnW: SpnLength mismatch: Actual: %" PRIu32
", Expected: 37\n", SpnLength);
108 status = DsMakeSpnW(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, Spn);
110 if (status != ERROR_SUCCESS)
112 printf(
"DsMakeSpnW: expected ERROR_SUCCESS\n");
116 if (_wcscmp(Spn, testSpn) != 0)
118 char buffer1[8192] = { 0 };
119 char buffer2[8192] = { 0 };
120 char* SpnA = buffer1;
121 char* testSpnA = buffer2;
123 (void)ConvertWCharToUtf8(Spn, SpnA, ARRAYSIZE(buffer1));
124 (void)ConvertWCharToUtf8(testSpn, testSpnA, ARRAYSIZE(buffer2));
125 printf(
"DsMakeSpnW: SPN mismatch: Actual: %s, Expected: %s\n", SpnA, testSpnA);
130 char buffer[8192] = { 0 };
133 (void)ConvertWCharToUtf8(Spn, SpnA, ARRAYSIZE(buffer));
134 printf(
"DsMakeSpnW: %s\n", SpnA);
141 int TestDsMakeSpn(
int argc,
char* argv[])
146 if (!test_DsMakeSpnA())
148 if (!test_DsMakeSpnW())