summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.cpp')
-rw-r--r--src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.cpp b/src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.cpp
new file mode 100644
index 0000000000..e8aebf77e9
--- /dev/null
+++ b/src/pal/tests/palsuite/loader/LoadLibraryW/test2/loadlibraryw.cpp
@@ -0,0 +1,62 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*=============================================================
+**
+** Source: loadlibraryw.c
+**
+** Purpose: Negative test the LoadLibraryW API.
+** Call LoadLibraryW with a not exist module Name
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ HMODULE ModuleHandle;
+ int err;
+ WCHAR *pwModuleName;
+ const char *pModuleName = "Not-exist-module-name";
+
+ /* Initialize the PAL environment */
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ return FAIL;
+ }
+
+ /* convert a normal string to a wide one */
+ pwModuleName = convert((char *)pModuleName);
+
+
+ /*try to load a not exist module */
+ ModuleHandle = LoadLibraryW(pwModuleName);
+
+ /* free the memory */
+ free(pwModuleName);
+
+ if(NULL != ModuleHandle)
+ {
+ Trace("Failed to call LoadLibraryW with a not exist mudule name, "
+ "a NULL module handle is expected, but no NULL module handle "
+ "is returned, error code=%u\n", GetLastError());
+
+ /* decrement the reference count of the loaded module */
+ err = FreeLibrary(ModuleHandle);
+ if(0 == err)
+ {
+ Trace("\nFailed to all FreeLibrary API to decrement "
+ "the reference count of the loaded module, "
+ "error code = %u\n", GetLastError());
+
+ }
+
+ Fail("");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}