1 /*
2  * PROJECT:     ReactOS Spooler Router API Tests
3  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE:     Tests for PackStrings
5  * COPYRIGHT:   Copyright 2015-2017 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 #include <spoolss.h>
14 
15 typedef struct _EXAMPLE_STRUCT
16 {
17     PWSTR String1;
18     PWSTR String2;
19 }
20 EXAMPLE_STRUCT, *PEXAMPLE_STRUCT;
21 
22 START_TEST(PackStrings)
23 {
24     PCWSTR Source1[] = { L"Test", L"String" };
25     PCWSTR Source2[] = { L"Test", NULL };
26 
27     BYTE Buffer[50];
28     PBYTE pEnd;
29     PEXAMPLE_STRUCT pStruct = (PEXAMPLE_STRUCT)Buffer;
30     DWORD Offsets[] = {
31         FIELD_OFFSET(EXAMPLE_STRUCT, String1),
32         FIELD_OFFSET(EXAMPLE_STRUCT, String2),
33         MAXDWORD
34     };
35 
36     // Try a usual case with two strings. Verify that they are copied in reverse order.
37     pEnd = PackStrings(Source1, Buffer, Offsets, &Buffer[sizeof(Buffer)]);
38     ok(wcscmp(pStruct->String1, Source1[0]) == 0, "String1 and Source1[0] don't match!\n");
39     ok(wcscmp(pStruct->String2, Source1[1]) == 0, "String2 and Source1[1] don't match!\n");
40     ok(wcscmp((PWSTR)pEnd, Source1[1]) == 0, "pEnd and Source1[1] don't match!\n");
41 
42     // Now verify that the corresponding pointer is set to NULL if a string is NULL.
43     pEnd = PackStrings(Source2, Buffer, Offsets, &Buffer[sizeof(Buffer)]);
44     ok(wcscmp(pStruct->String1, Source2[0]) == 0, "String1 and Source2[0] don't match!\n");
45     ok(!pStruct->String2, "String2 is %p!\n", pStruct->String2);
46     ok(wcscmp((PWSTR)pEnd, Source2[0]) == 0, "pEnd and Source2[0] don't match!\n");
47 }
48