diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
commit | db20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch) | |
tree | e5435159cd1bf0519276363a6fe1663d1721bed3 /src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.cpp | |
parent | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff) | |
download | coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2 coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip |
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.cpp')
-rw-r--r-- | src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.cpp | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.cpp b/src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.cpp new file mode 100644 index 0000000000..ee825e6439 --- /dev/null +++ b/src/pal/tests/palsuite/loader/LoadLibraryA/test6/loadlibrarya.cpp @@ -0,0 +1,172 @@ +// 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: loadlibrary.c (test 6) +** +** Purpose: Positive test the LoadLibrary API. Test will verify +** that it is unable to load the library twice. Once by +** using the full path name and secondly by using the +** short name. +** + +** +**============================================================*/ +#include <palsuite.h> + +/*Define platform specific information*/ +#if defined(SHLEXT) +#define LibraryName "dlltest"SHLEXT +#define GETATTACHCOUNTNAME "GetAttachCount" +#else +typedef int (*dllfunct)(); +#define LibraryName "dlltest.dll" +#define GETATTACHCOUNTNAME "_GetAttachCount@0" +#endif + + +/* Helper function to test the loaded library. + */ +BOOL PALAPI TestDll(HMODULE hLib) +{ + int RetVal; + char FunctName[] = GETATTACHCOUNTNAME; + FARPROC DllFunc; + + /* Access a function from the loaded library. + */ + DllFunc = GetProcAddress(hLib, FunctName); + if(DllFunc == NULL) + { + Trace("ERROR: Unable to load function \"%s\" from library \"%s\"\n", + FunctName, + LibraryName); + return (FALSE); + } + + /* Verify that the DLL_PROCESS_ATTACH is only + * accessed once.*/ + RetVal = DllFunc(); + if (RetVal != 1) + { + Trace("ERROR: Unable to receive correct information from DLL! " + ":expected \"1\", returned \"%d\"\n", + RetVal); + return (FALSE); + } + + return (TRUE); +} + +int __cdecl main(int argc, char *argv[]) +{ + HANDLE hFullLib; + HANDLE hShortLib; + int iRetVal = FAIL; + char fullPath[_MAX_DIR]; + char drive[_MAX_DRIVE]; + char dir[_MAX_DIR]; + char fname[_MAX_FNAME]; + char ext[_MAX_EXT]; + + + + /* Initialize the PAL. */ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /* Initalize the buffer. + */ + memset(fullPath, 0, _MAX_DIR); + + /* Get the full path to the library (DLL). + */ + + if (NULL != _fullpath(fullPath,argv[0],_MAX_DIR)) { + + _splitpath(fullPath,drive,dir,fname,ext); + _makepath(fullPath,drive,dir,LibraryName,""); + + + } else { + Fail("ERROR: conversion from relative path \" %s \" to absolute path failed. _fullpath returned NULL\n",argv[0]); + } + + /* Call Load library with the short name of + * the dll. + */ + hShortLib = LoadLibrary(LibraryName); + if(hShortLib == NULL) + { + Fail("ERROR:%u:Unable to load library %s\n", + GetLastError(), + LibraryName); + } + + /* Test the loaded library. + */ + if (!TestDll(hShortLib)) + { + iRetVal = FAIL; + goto cleanUpOne; + } + + /* Call Load library with the full name of + * the dll. + */ + hFullLib = LoadLibrary(fullPath); + if(hFullLib == NULL) + { + Trace("ERROR:%u:Unable to load library %s\n", + GetLastError(), + fullPath); + iRetVal = FAIL; + goto cleanUpTwo; + } + + /* Test the loaded library. + */ + if (!TestDll(hFullLib)) + { + iRetVal = FAIL; + goto cleanUpTwo; + } + + /* Test Succeeded. + */ + iRetVal = PASS; + +cleanUpTwo: + + /* Call the FreeLibrary API. + */ + if (!FreeLibrary(hFullLib)) + { + Trace("ERROR:%u: Unable to free library \"%s\"\n", + GetLastError(), + fullPath); + iRetVal = FAIL; + } + +cleanUpOne: + + /* Call the FreeLibrary API. + */ + if (!FreeLibrary(hShortLib)) + { + Trace("ERROR:%u: Unable to free library \"%s\"\n", + GetLastError(), + LibraryName); + iRetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_Terminate(); + return iRetVal; + +} |