c6fa4ad0747a8eeba88c35c243f6a35225c05620
[platform/core/dotnet/diagnostics.git] /
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: pal_registerlibraryw_unregisterlibraryw_neg.c
8 **
9 ** Purpose: Negative test the PAL_RegisterLibrary API.
10 **          Call PAL_RegisterLibrary to map a non-existant module
11 **          into the calling process address space. 
12 **
13 **
14 **============================================================*/
15 #define UNICODE
16 #include <palsuite.h>
17
18 int __cdecl main(int argc, char *argv[])
19 {
20     HMODULE ModuleHandle;
21     char ModuleName[64];
22     WCHAR *wpModuleName = NULL;
23     int err;
24
25     /*Initialize the PAL environment*/
26     err = PAL_Initialize(argc, argv);
27     if(0 != err)
28     {
29         return FAIL;
30     }
31
32     memset(ModuleName, 0, 64);
33     sprintf_s(ModuleName, _countof(ModuleName), "%s", "not_exist_module_name");
34
35     /*convert a normal string to a wide one*/
36     wpModuleName = convert(ModuleName);
37
38     /*load a not exist module*/
39     ModuleHandle = PAL_RegisterLibrary(wpModuleName);
40
41     /*free the memory*/
42     free(wpModuleName);
43
44     if(NULL != ModuleHandle)
45     {
46         Trace("ERROR: PAL_RegisterLibrary successfully mapped "
47               "a module that does not exist into the calling process\n");
48
49         /*decrement the reference count of the loaded DLL*/
50         err = PAL_UnregisterLibrary(ModuleHandle);
51         if(0 == err)
52         {
53             Trace("\nFailed to call PAL_UnregisterLibrary API to decrement the "
54                 "count of the loaded DLL module!\n");
55         }
56         Fail("");
57
58     }
59
60     PAL_Terminate();
61     return PASS;
62 }