michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /*********************************************************************** michael@0: ** michael@0: ** Name: libfilename.c michael@0: ** michael@0: ** Description: test PR_GetLibraryFilePathname. michael@0: ** michael@0: ***********************************************************************/ michael@0: michael@0: #include "nspr.h" michael@0: #include "pprio.h" michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: PRBool debug_mode = PR_FALSE; michael@0: michael@0: static PRStatus RunTest(const char *name, PRFuncPtr addr) michael@0: { michael@0: char *pathname; michael@0: PRFileDesc *fd; michael@0: michael@0: pathname = PR_GetLibraryFilePathname(name, addr); michael@0: if (pathname == NULL) { michael@0: fprintf(stderr, "PR_GetLibraryFilePathname failed\n"); michael@0: /* we let this test pass if this function is not implemented */ michael@0: if (PR_GetError() == PR_NOT_IMPLEMENTED_ERROR) { michael@0: return PR_SUCCESS; michael@0: } michael@0: return PR_FAILURE; michael@0: } michael@0: michael@0: if (debug_mode) printf("Pathname is %s\n", pathname); michael@0: fd = PR_OpenFile(pathname, PR_RDONLY, 0); michael@0: if (fd == NULL) { michael@0: fprintf(stderr, "PR_Open failed: %d\n", (int)PR_GetError()); michael@0: return PR_FAILURE; michael@0: } michael@0: if (PR_Close(fd) == PR_FAILURE) { michael@0: fprintf(stderr, "PR_Close failed: %d\n", (int)PR_GetError()); michael@0: return PR_FAILURE; michael@0: } michael@0: PR_Free(pathname); michael@0: return PR_SUCCESS; michael@0: } michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: char *name; michael@0: PRFuncPtr addr; michael@0: PRLibrary *lib; michael@0: PRBool failed = PR_FALSE; michael@0: michael@0: if (argc >= 2 && strcmp(argv[1], "-d") == 0) { michael@0: debug_mode = PR_TRUE; michael@0: } michael@0: michael@0: /* First test a library that is implicitly linked. */ michael@0: #ifdef WINNT michael@0: name = PR_Malloc(strlen("libnspr4.dll")+1); michael@0: strcpy(name, "libnspr4.dll"); michael@0: #else michael@0: name = PR_GetLibraryName(NULL, "nspr4"); michael@0: #endif michael@0: addr = (PRFuncPtr)PR_GetTCPMethods()->close; michael@0: if (RunTest(name, addr) == PR_FAILURE) { michael@0: failed = PR_TRUE; michael@0: } michael@0: PR_FreeLibraryName(name); michael@0: michael@0: /* Next test a library that is dynamically loaded. */ michael@0: name = PR_GetLibraryName("dll", "my"); michael@0: if (debug_mode) printf("Loading library %s\n", name); michael@0: lib = PR_LoadLibrary(name); michael@0: if (!lib) { michael@0: fprintf(stderr, "PR_LoadLibrary failed\n"); michael@0: exit(1); michael@0: } michael@0: PR_FreeLibraryName(name); michael@0: name = PR_GetLibraryName(NULL, "my"); michael@0: addr = PR_FindFunctionSymbol(lib, "My_GetValue"); michael@0: if (RunTest(name, addr) == PR_FAILURE) { michael@0: failed = PR_TRUE; michael@0: } michael@0: PR_FreeLibraryName(name); michael@0: PR_UnloadLibrary(lib); michael@0: if (failed) { michael@0: printf("FAIL\n"); michael@0: return 1; michael@0: } michael@0: printf("PASS\n"); michael@0: return 0; michael@0: }