4#include <winpr/winpr.h>
5#include <winpr/tchar.h>
6#include <winpr/dsparse.h>
8static 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] = WINPR_C_ARRAY_INIT;
19 DsMakeSpnA(testServiceClass, testServiceName,
nullptr, 0,
nullptr, &SpnLength,
nullptr);
21 if (status != ERROR_INVALID_PARAMETER)
23 printf(
"DsMakeSpnA: expected ERROR_INVALID_PARAMETER\n");
29 DsMakeSpnA(testServiceClass, testServiceName,
nullptr, 0,
nullptr, &SpnLength,
nullptr);
31 if (status != ERROR_BUFFER_OVERFLOW)
33 printf(
"DsMakeSpnA: expected ERROR_BUFFER_OVERFLOW\n");
39 printf(
"DsMakeSpnA: SpnLength mismatch: Actual: %" PRIu32
", Expected: 37\n", SpnLength);
43 status = DsMakeSpnA(testServiceClass, testServiceName,
nullptr, 0,
nullptr, &SpnLength, Spn);
45 if (status != ERROR_SUCCESS)
47 printf(
"DsMakeSpnA: expected ERROR_SUCCESS\n");
51 if (strcmp(Spn, testSpn) != 0)
53 printf(
"DsMakeSpnA: SPN mismatch: Actual: %s, Expected: %s\n", Spn, testSpn);
57 printf(
"DsMakeSpnA: %s\n", Spn);
63static BOOL test_DsMakeSpnW(
void)
65 const CHAR ctestServiceClass[] = {
'H',
'T',
'T',
'P',
'\0' };
66 const CHAR ctestServiceName[] = {
'L',
'A',
'B',
'1',
'-',
'W',
'2',
'K',
'8',
'R',
'2',
67 '-',
'G',
'W',
'.',
'l',
'a',
'b',
'1',
'.',
'a',
'w',
68 'a',
'k',
'e',
'.',
'l',
'o',
'c',
'a',
'l',
'\0' };
69 const CHAR ctestSpn[] = {
'H',
'T',
'T',
'P',
'/',
'L',
'A',
'B',
'1',
'-',
'W',
'2',
'K',
70 '8',
'R',
'2',
'-',
'G',
'W',
'.',
'l',
'a',
'b',
'1',
'.',
'a',
71 'w',
'a',
'k',
'e',
'.',
'l',
'o',
'c',
'a',
'l',
'\0' };
72 WCHAR testServiceClass[ARRAYSIZE(ctestServiceClass)] = WINPR_C_ARRAY_INIT;
73 WCHAR testServiceName[ARRAYSIZE(ctestServiceName)] = WINPR_C_ARRAY_INIT;
74 WCHAR testSpn[ARRAYSIZE(ctestSpn)] = WINPR_C_ARRAY_INIT;
77 WCHAR Spn[100] = WINPR_C_ARRAY_INIT;
81 (void)ConvertUtf8NToWChar(ctestServiceClass, ARRAYSIZE(ctestServiceClass), testServiceClass,
82 ARRAYSIZE(testServiceClass));
83 (void)ConvertUtf8NToWChar(ctestServiceName, ARRAYSIZE(ctestServiceName), testServiceName,
84 ARRAYSIZE(testServiceName));
85 (void)ConvertUtf8NToWChar(ctestSpn, ARRAYSIZE(ctestSpn), testSpn, ARRAYSIZE(testSpn));
88 DsMakeSpnW(testServiceClass, testServiceName,
nullptr, 0,
nullptr, &SpnLength,
nullptr);
90 if (status != ERROR_INVALID_PARAMETER)
92 printf(
"DsMakeSpnW: expected ERROR_INVALID_PARAMETER\n");
98 DsMakeSpnW(testServiceClass, testServiceName,
nullptr, 0,
nullptr, &SpnLength,
nullptr);
100 if (status != ERROR_BUFFER_OVERFLOW)
102 printf(
"DsMakeSpnW: expected ERROR_BUFFER_OVERFLOW\n");
108 printf(
"DsMakeSpnW: SpnLength mismatch: Actual: %" PRIu32
", Expected: 37\n", SpnLength);
112 status = DsMakeSpnW(testServiceClass, testServiceName,
nullptr, 0,
nullptr, &SpnLength, Spn);
114 if (status != ERROR_SUCCESS)
116 printf(
"DsMakeSpnW: expected ERROR_SUCCESS\n");
120 if (_wcscmp(Spn, testSpn) != 0)
122 char buffer1[8192] = WINPR_C_ARRAY_INIT;
123 char buffer2[8192] = WINPR_C_ARRAY_INIT;
124 char* SpnA = buffer1;
125 char* testSpnA = buffer2;
127 (void)ConvertWCharToUtf8(Spn, SpnA, ARRAYSIZE(buffer1));
128 (void)ConvertWCharToUtf8(testSpn, testSpnA, ARRAYSIZE(buffer2));
129 printf(
"DsMakeSpnW: SPN mismatch: Actual: %s, Expected: %s\n", SpnA, testSpnA);
134 char buffer[8192] = WINPR_C_ARRAY_INIT;
137 (void)ConvertWCharToUtf8(Spn, SpnA, ARRAYSIZE(buffer));
138 printf(
"DsMakeSpnW: %s\n", SpnA);
145int TestDsMakeSpn(
int argc,
char* argv[])
150 if (!test_DsMakeSpnA())
152 if (!test_DsMakeSpnW())