1 /*
2 * PROJECT: ReactOS Spooler Router API Tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Tests for ReallocSplStr
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 #include <spoolss.h>
14
15 #include <pseh/pseh2.h>
16
START_TEST(ReallocSplStr)17 START_TEST(ReallocSplStr)
18 {
19 const WCHAR wszTestString1[] = L"Test";
20 const WCHAR wszTestString2[] = L"New";
21
22 DWORD dwResult;
23 PWSTR pwszBackup;
24 PWSTR pwszTest;
25
26 // Verify that ReallocSplStr raises an exception if all parameters are NULL.
27 _SEH2_TRY
28 {
29 dwResult = 0;
30 ReallocSplStr(NULL, NULL);
31 }
32 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
33 {
34 dwResult = _SEH2_GetExceptionCode();
35 }
36 _SEH2_END;
37
38 ok(dwResult == EXCEPTION_ACCESS_VIOLATION, "dwResult is %lx!\n", dwResult);
39
40 // Allocate a string for testing.
41 pwszTest = AllocSplStr(wszTestString1);
42 if (!pwszTest)
43 {
44 skip("AllocSplStr failed with error %lu!\n", GetLastError());
45 return;
46 }
47
48 // Verify that ReallocSplStr frees the old string even if pwszInput is NULL.
49 ok(ReallocSplStr(&pwszTest, NULL), "ReallocSplStr is FALSE!\n");
50 ok(pwszTest == NULL, "pwszTest is %p\n", pwszTest);
51
52 // Now verify that ReallocSplStr copies the new string into a new block and frees the old one.
53 pwszBackup = pwszTest;
54 ok(ReallocSplStr(&pwszTest, wszTestString2), "ReallocSplStr is FALSE!\n");
55 ok(wcscmp(pwszTest, wszTestString2) == 0, "New string was not copied into pwszTest!\n");
56
57 _SEH2_TRY
58 {
59 dwResult = (DWORD)wcscmp(pwszBackup, wszTestString1);
60 }
61 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
62 {
63 dwResult = _SEH2_GetExceptionCode();
64 }
65 _SEH2_END;
66
67 ok(dwResult == EXCEPTION_ACCESS_VIOLATION, "dwResult is %lx!\n", dwResult);
68 }
69