1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*============================================================
6**
7** Source: test.c
8**
9** Purpose: Test for SetEnvironmentVariableW() function
10** Test to see that passing NULL to the first param fails.
11** Test that passing NULL to both params fails.
12** Set an environment variable, then pass NULL to the second param
13** to delete it. Then make the same call again, to check that it fails.
14**
15**
16**=========================================================*/
17
18#define UNICODE
19
20#include <palsuite.h>
21
22int __cdecl main(int argc, char *argv[])
23{
24
25 /* Define some buffers needed for the function */
26 WCHAR VariableBuffer[] = {'P','A','L','T','E','S','T','\0'};
27 WCHAR ValueBuffer[] = {'T','e','s','t','i','n','g','\0'};
28 int SetResult;
29
30 /*
31 * Initialize the PAL and return FAILURE if this fails
32 */
33
34 if(0 != (PAL_Initialize(argc, argv)))
35 {
36 return FAIL;
37 }
38
39 SetResult = SetEnvironmentVariable(NULL,ValueBuffer);
40
41 /* Check that it fails if the first param is NULL */
42 if(SetResult != 0)
43 {
44 Fail("ERROR: SetEnvironmentVariable returned a success value, "
45 "even though it was passed NULL as the first parameter and "
46 "should have failed.\n");
47 }
48
49 /* Check that it fails when both params are NULL */
50 SetResult = SetEnvironmentVariable(NULL,NULL);
51 if(SetResult != 0)
52 {
53 Fail("ERROR: SetEnvironmentVariable returned a success value, even "
54 "though it was passed NULL as the first and second parameter and "
55 "should have failed.\n");
56 }
57
58 /* First, set the variable, which should be ok. Then call the
59 function with the second parameter NULL twice -- the first call should
60 pass, the second should fail.
61 */
62 SetResult = SetEnvironmentVariable(VariableBuffer,ValueBuffer);
63 if(SetResult == 0)
64 {
65 Fail("ERROR: SetEnvironmentVariable returned failure, when "
66 "attempting to set a valid variable.\n");
67 }
68
69 SetResult = SetEnvironmentVariable(VariableBuffer,NULL);
70 if(SetResult == 0)
71 {
72 Fail("ERROR: SetEnvironmentVariable returned failure, when "
73 "attempting to delete a variable.\n");
74 }
75
76 SetResult = SetEnvironmentVariable(VariableBuffer,NULL);
77 if(SetResult != 0)
78 {
79 Fail("ERROR: SetEnvironmentVariable returned success, when "
80 "attempting to delete a variable which doesn't exist.\n");
81 }
82
83 PAL_Terminate();
84 return PASS;
85}
86
87
88
89