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