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 (filemapping_memmgt\getprocaddress\test2) |
8 | ** |
9 | ** Purpose: This test tries to call GetProcAddress with |
10 | ** a NULL handle, with a NULL function name, with an empty |
11 | ** function name, with an invalid name and with an |
12 | ** invalid ordinal value. |
13 | ** |
14 | ** |
15 | **===========================================================================*/ |
16 | #include <palsuite.h> |
17 | |
18 | |
19 | /* SHLEXT is defined only for Unix variants */ |
20 | #if defined(SHLEXT) |
21 | #define lpModuleName "testlib"SHLEXT |
22 | #else |
23 | #define lpModuleName "testlib.dll" |
24 | #endif |
25 | |
26 | |
27 | /** |
28 | * main |
29 | */ |
30 | int __cdecl main(int argc, char *argv[]) |
31 | { |
32 | int err; |
33 | HMODULE hModule; |
34 | FARPROC procAddress; |
35 | |
36 | /* Initialize the PAL environment. */ |
37 | if(0 != PAL_Initialize(argc, argv)) |
38 | { |
39 | return FAIL; |
40 | } |
41 | |
42 | /* load a module */ |
43 | hModule = LoadLibrary(lpModuleName); |
44 | if(!hModule) |
45 | { |
46 | Fail("Unexpected error: " |
47 | "LoadLibrary(%s) failed.\n" , |
48 | lpModuleName); |
49 | } |
50 | |
51 | /* |
52 | * Test 1 |
53 | * |
54 | * Call GetProcAddress with a NULL handle |
55 | */ |
56 | procAddress = GetProcAddress(NULL,"SimpleFunction" ); |
57 | if(procAddress != NULL) |
58 | { |
59 | Trace("ERROR: GetProcAddress with a NULL handle " |
60 | "returned a non-NULL value when it should have " |
61 | "returned a NULL value with an error\n" ); |
62 | |
63 | /* Cleanup */ |
64 | err = FreeLibrary(hModule); |
65 | if(0 == err) |
66 | { |
67 | Fail("Unexpected error: Failed to FreeLibrary %s\n" , |
68 | lpModuleName); |
69 | } |
70 | Fail("" ); |
71 | } |
72 | |
73 | /** |
74 | * Test 2 |
75 | * |
76 | * Call GetProcAddress with a NULL function name |
77 | */ |
78 | |
79 | procAddress = GetProcAddress(hModule,NULL); |
80 | if(procAddress != NULL) |
81 | { |
82 | Trace("ERROR: GetProcAddress with a NULL function name " |
83 | "returned a non-NULL value when it should have " |
84 | "returned a NULL value with an error\n" ); |
85 | |
86 | /* Cleanup */ |
87 | err = FreeLibrary(hModule); |
88 | if(0 == err) |
89 | { |
90 | Fail("Unexpected error: Failed to FreeLibrary %s\n" , |
91 | lpModuleName); |
92 | } |
93 | Fail("" ); |
94 | } |
95 | |
96 | /** |
97 | * Test 3 |
98 | * |
99 | * Call GetProcAddress with an empty function name string |
100 | */ |
101 | |
102 | procAddress = GetProcAddress(hModule,"" ); |
103 | if(procAddress != NULL) |
104 | { |
105 | Trace("ERROR: GetProcAddress with an empty function name " |
106 | "returned a non-NULL value when it should have " |
107 | "returned a NULL value with an error\n" ); |
108 | |
109 | /* Cleanup */ |
110 | err = FreeLibrary(hModule); |
111 | if(0 == err) |
112 | { |
113 | Fail("Unexpected error: Failed to FreeLibrary %s\n" , |
114 | lpModuleName); |
115 | } |
116 | Fail("" ); |
117 | } |
118 | |
119 | /** |
120 | * Test 4 |
121 | * |
122 | * Call GetProcAddress with an invalid name |
123 | */ |
124 | |
125 | procAddress = GetProcAddress(hModule,"Simple Function" ); |
126 | if(procAddress != NULL) |
127 | { |
128 | Trace("ERROR: GetProcAddress with an invalid function name " |
129 | "returned a non-NULL value when it should have " |
130 | "returned a NULL value with an error\n" ); |
131 | |
132 | /* Cleanup */ |
133 | err = FreeLibrary(hModule); |
134 | if(0 == err) |
135 | { |
136 | Fail("Unexpected error: Failed to FreeLibrary %s\n" , |
137 | lpModuleName); |
138 | } |
139 | Fail("" ); |
140 | } |
141 | |
142 | /* cleanup */ |
143 | err = FreeLibrary(hModule); |
144 | if(0 == err) |
145 | { |
146 | Fail("Unexpected error: Failed to FreeLibrary %s\n" , |
147 | lpModuleName); |
148 | } |
149 | |
150 | PAL_Terminate(); |
151 | return PASS; |
152 | } |
153 | |