summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA')
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/CMakeLists.txt5
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.c92
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.c49
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/testinfo.dat13
7 files changed, 210 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/CMakeLists.txt
new file mode 100644
index 0000000000..ef14ea5352
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/CMakeLists.txt
new file mode 100644
index 0000000000..a1128c62b8
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ GetModuleFileNameA.c
+)
+
+add_executable(paltest_getmodulefilenamea_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_getmodulefilenamea_test1 coreclrpal)
+
+target_link_libraries(paltest_getmodulefilenamea_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.c b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.c
new file mode 100644
index 0000000000..d05f0ac6a9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.c
@@ -0,0 +1,92 @@
+// 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: getmodulefilenamea.c
+**
+** Purpose: Positive test the GetModuleFileName API.
+** Call GetModuleFileName to retrieve the specified
+** module full path and file name
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+#define MODULENAMEBUFFERSIZE 1024
+
+/* SHLEXT is defined only for Unix variants */
+
+#if defined(SHLEXT)
+#define ModuleName "librotor_pal"SHLEXT
+#define Delimiter "/"
+#else
+#define ModuleName "rotor_pal.dll"
+#define Delimiter "\\"
+#endif
+
+int __cdecl main(int argc, char *argv[])
+{
+ HMODULE ModuleHandle;
+ int err;
+ DWORD ModuleNameLength;
+ char ModuleFileNameBuf[MODULENAMEBUFFERSIZE]="";
+ char* TempBuf = NULL;
+ char* LastBuf = NULL;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+
+ //load a module
+ ModuleHandle = LoadLibrary(ModuleName);
+ if(!ModuleHandle)
+ {
+ Fail("Failed to call LoadLibrary API!\n");
+ }
+
+
+ //retrieve the specified module full path and file name
+ ModuleNameLength = GetModuleFileName(
+ ModuleHandle,//specified module handle
+ ModuleFileNameBuf,//buffer for module file name
+ MODULENAMEBUFFERSIZE);
+
+ //strip out all full path
+ TempBuf = strtok(ModuleFileNameBuf,Delimiter);
+ LastBuf = TempBuf;
+ while(NULL != TempBuf)
+ {
+ LastBuf = TempBuf;
+ TempBuf = strtok(NULL,Delimiter);
+ }
+
+
+ if(0 == ModuleNameLength || strcmp(ModuleName,LastBuf))
+ {
+ Trace("\nFailed to all GetModuleFileName API!\n");
+ err = FreeLibrary(ModuleHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to all FreeLibrary API!\n");
+ }
+ Fail("");
+ }
+
+ //decrement the reference count of the loaded dll
+ err = FreeLibrary(ModuleHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to all FreeLibrary API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/testinfo.dat
new file mode 100644
index 0000000000..8075e840ce
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = GetModuleFileNameA
+Name = Positive test for GetModuleFileNameA API
+TYPE = DEFAULT
+EXE1 = getmodulefilenamea
+Description
+=Test the GetModuleFileNameA to retrieve the specified module
+=full path and file name
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/CMakeLists.txt
new file mode 100644
index 0000000000..c35e9acc5e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ GetModuleFileNameA.c
+)
+
+add_executable(paltest_getmodulefilenamea_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_getmodulefilenamea_test2 coreclrpal)
+
+target_link_libraries(paltest_getmodulefilenamea_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.c b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.c
new file mode 100644
index 0000000000..e8aed6d30e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.c
@@ -0,0 +1,49 @@
+// 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: getmodulefilenamea.c
+**
+** Purpose: Positive test the GetModuleFileNameA API.
+** Call GetModuleFileName to retrieve current process
+** full path and file name by passing a NULL module handle
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+
+#define MODULENAMEBUFFERSIZE 1024
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ DWORD ModuleNameLength;
+ char ModuleFileNameBuf[MODULENAMEBUFFERSIZE]="";
+ int err;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+
+ //retrieve the current process full path and file name
+ //by passing a NULL module handle
+ ModuleNameLength = GetModuleFileName(
+ NULL, //a NULL handle
+ ModuleFileNameBuf,//buffer for module file name
+ MODULENAMEBUFFERSIZE);
+
+ if(0 == ModuleNameLength)
+ {
+ Fail("\nFailed to all GetModuleFileName API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/testinfo.dat
new file mode 100644
index 0000000000..45fdca6ae7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = GetModuleFileNameA
+Name = Positive test for GetModuleFileNameA API
+TYPE = DEFAULT
+EXE1 = getmodulefilenamea
+Description
+=Test the GetModuleFileNameA to retrieve current process full
+=full path and file name by passing a NULL module handle