1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /***********************************************************************
10 ** Description: test PR_GetLibraryFilePathname.
12 ***********************************************************************/
20 PRBool debug_mode
= PR_FALSE
;
22 static PRStatus
RunTest(const char *name
, PRFuncPtr addr
)
27 pathname
= PR_GetLibraryFilePathname(name
, addr
);
28 if (pathname
== NULL
) {
29 fprintf(stderr
, "PR_GetLibraryFilePathname failed\n");
30 /* we let this test pass if this function is not implemented */
31 if (PR_GetError() == PR_NOT_IMPLEMENTED_ERROR
) {
38 printf("Pathname is %s\n", pathname
);
40 fd
= PR_OpenFile(pathname
, PR_RDONLY
, 0);
42 fprintf(stderr
, "PR_Open failed: %d\n", (int)PR_GetError());
45 if (PR_Close(fd
) == PR_FAILURE
) {
46 fprintf(stderr
, "PR_Close failed: %d\n", (int)PR_GetError());
53 int main(int argc
, char **argv
)
58 PRBool failed
= PR_FALSE
;
60 if (argc
>= 2 && strcmp(argv
[1], "-d") == 0) {
64 /* First test a library that is implicitly linked. */
66 name
= PR_Malloc(strlen("libnspr4.dll")+1);
67 strcpy(name
, "libnspr4.dll");
69 name
= PR_GetLibraryName(NULL
, "nspr4");
71 addr
= (PRFuncPtr
)PR_GetTCPMethods()->close
;
72 if (RunTest(name
, addr
) == PR_FAILURE
) {
75 PR_FreeLibraryName(name
);
77 /* Next test a library that is dynamically loaded. */
78 name
= PR_GetLibraryName("dll", "my");
80 printf("Loading library %s\n", name
);
82 lib
= PR_LoadLibrary(name
);
84 fprintf(stderr
, "PR_LoadLibrary failed\n");
87 PR_FreeLibraryName(name
);
88 name
= PR_GetLibraryName(NULL
, "my");
89 addr
= PR_FindFunctionSymbol(lib
, "My_GetValue");
90 if (RunTest(name
, addr
) == PR_FAILURE
) {
93 PR_FreeLibraryName(name
);
94 PR_UnloadLibrary(lib
);