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 SetLastError() function |
10 | ** |
11 | ** |
12 | **=========================================================*/ |
13 | /* Depends on GetLastError() */ |
14 | |
15 | |
16 | #include <palsuite.h> |
17 | |
18 | int __cdecl main(int argc, char *argv[]) { |
19 | |
20 | /* Error value that we can set to test */ |
21 | const unsigned int FAKE_ERROR = 5; |
22 | const int NEGATIVE_ERROR = -1; |
23 | |
24 | /* |
25 | * Initialize the PAL and return FAILURE if this fails |
26 | */ |
27 | |
28 | if(0 != (PAL_Initialize(argc, argv))) |
29 | { |
30 | return FAIL; |
31 | } |
32 | |
33 | /* Set error */ |
34 | SetLastError(FAKE_ERROR); |
35 | |
36 | /* Check to make sure it returns the error value we just set */ |
37 | if(GetLastError() != FAKE_ERROR) |
38 | { |
39 | Fail("ERROR: The last error should have been '%d' but the error " |
40 | "returned was '%d'\n" ,FAKE_ERROR,GetLastError()); |
41 | } |
42 | |
43 | /* Set the error to a negative */ |
44 | SetLastError(NEGATIVE_ERROR); |
45 | |
46 | /* Check to make sure it returns the error value we just set */ |
47 | if((signed)GetLastError() != NEGATIVE_ERROR) |
48 | { |
49 | Fail("ERROR: The last error should have been '%d' but the error " |
50 | "returned was '%d'\n" ,NEGATIVE_ERROR,GetLastError()); |
51 | } |
52 | |
53 | |
54 | PAL_Terminate(); |
55 | return PASS; |
56 | } |
57 | |
58 | |
59 | |
60 | |