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: test2.c |
8 | ** |
9 | ** Purpose: Test for SetEnvironmentVariableA() 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 | #include <palsuite.h> |
19 | |
20 | int __cdecl main(int argc, char *argv[]) |
21 | { |
22 | |
23 | /* Define some buffers needed for the function */ |
24 | char* VariableBuffer = "PALTEST" ; |
25 | char* ValueBuffer = "testing" ; |
26 | int SetResult; |
27 | |
28 | if(0 != (PAL_Initialize(argc, argv))) |
29 | { |
30 | return FAIL; |
31 | } |
32 | |
33 | /* Check that it fails if the first param is NULL */ |
34 | |
35 | SetResult = SetEnvironmentVariable(NULL,ValueBuffer); |
36 | |
37 | if(SetResult != 0) |
38 | { |
39 | Fail("ERROR: SetEnvironmentVariable returned a success value, " |
40 | "even though it was passed NULL as the first parameter and " |
41 | "should have failed.\n" ); |
42 | } |
43 | |
44 | /* Check that it fails when both params are NULL */ |
45 | SetResult = SetEnvironmentVariable(NULL,NULL); |
46 | if(SetResult != 0) |
47 | { |
48 | Fail("ERROR: SetEnvironmentVariable returned a success value, even " |
49 | "though it was passed NULL as the first and second parameter and " |
50 | "should have failed.\n" ); |
51 | } |
52 | |
53 | |
54 | /* First, set the variable, which should be ok. Then call the |
55 | function with the second parameter NULL twice -- the first call should |
56 | pass, the second should fail. |
57 | */ |
58 | |
59 | SetResult = SetEnvironmentVariable(VariableBuffer,ValueBuffer); |
60 | if(SetResult == 0) |
61 | { |
62 | Fail("ERROR: SetEnvironmentVariable returned failure, when " |
63 | "attempting to set a valid variable.\n" ); |
64 | } |
65 | |
66 | SetResult = SetEnvironmentVariable(VariableBuffer,NULL); |
67 | if(SetResult == 0) |
68 | { |
69 | Fail("ERROR: SetEnvironmentVariable returned failure, when " |
70 | "attempting to delete a variable.\n" ); |
71 | } |
72 | |
73 | SetResult = SetEnvironmentVariable(VariableBuffer,NULL); |
74 | if(SetResult != 0) |
75 | { |
76 | Fail("ERROR: SetEnvironmentVariable returned success, when " |
77 | "attempting to delete a variable which doesn't exist.\n" ); |
78 | } |
79 | |
80 | PAL_Terminate(); |
81 | return PASS; |
82 | } |
83 | |
84 | |
85 | |
86 | |