[SPOOLSS]
[reactos.git] / rostests / apitests / spoolss / PackStrings.c
1 /*
2 * PROJECT: ReactOS Spooler Router API Tests
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Tests for PackStrings
5 * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <windef.h>
12 #include <winbase.h>
13
14 PBYTE WINAPI PackStrings(PCWSTR*, PBYTE, PDWORD, PBYTE);
15
16 typedef struct _EXAMPLE_STRUCT
17 {
18 PWSTR String1;
19 PWSTR String2;
20 }
21 EXAMPLE_STRUCT, *PEXAMPLE_STRUCT;
22
23 START_TEST(PackStrings)
24 {
25 PCWSTR Source1[] = { L"Test", L"String" };
26 PCWSTR Source2[] = { L"Test", NULL };
27
28 BYTE Buffer[50];
29 PBYTE pEnd;
30 PEXAMPLE_STRUCT pStruct = (PEXAMPLE_STRUCT)Buffer;
31 DWORD Offsets[] = {
32 FIELD_OFFSET(EXAMPLE_STRUCT, String1),
33 FIELD_OFFSET(EXAMPLE_STRUCT, String2),
34 MAXDWORD
35 };
36
37 // Try a usual case with two strings. Verify that they are copied in reverse order.
38 pEnd = PackStrings(Source1, Buffer, Offsets, &Buffer[sizeof(Buffer)]);
39 ok(wcscmp(pStruct->String1, Source1[0]) == 0, "String1 and Source1[0] don't match!\n");
40 ok(wcscmp(pStruct->String2, Source1[1]) == 0, "String2 and Source1[1] don't match!\n");
41 ok(wcscmp((PWSTR)pEnd, Source1[1]) == 0, "pEnd and Source1[1] don't match!\n");
42
43 // Now verify that the corresponding pointer is set to NULL if a string is NULL.
44 pEnd = PackStrings(Source2, Buffer, Offsets, &Buffer[sizeof(Buffer)]);
45 ok(wcscmp(pStruct->String1, Source2[0]) == 0, "String1 and Source2[0] don't match!\n");
46 ok(!pStruct->String2, "String2 is %p!\n", pStruct->String2);
47 ok(wcscmp((PWSTR)pEnd, Source2[0]) == 0, "pEnd and Source2[0] don't match!\n");
48 }