Bug 1825055 [wpt PR 39247] - Add support for allowing elements with display:contents...
[gecko.git] / nsprpub / pr / tests / libfilename.c
blob09d0980de3b30f0995e73723ba06c8d893571b00
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 /***********************************************************************
7 **
8 ** Name: libfilename.c
9 **
10 ** Description: test PR_GetLibraryFilePathname.
12 ***********************************************************************/
14 #include "nspr.h"
15 #include "pprio.h"
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
20 PRBool debug_mode = PR_FALSE;
22 static PRStatus RunTest(const char *name, PRFuncPtr addr)
24 char *pathname;
25 PRFileDesc *fd;
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) {
32 return PR_SUCCESS;
34 return PR_FAILURE;
37 if (debug_mode) {
38 printf("Pathname is %s\n", pathname);
40 fd = PR_OpenFile(pathname, PR_RDONLY, 0);
41 if (fd == NULL) {
42 fprintf(stderr, "PR_Open failed: %d\n", (int)PR_GetError());
43 return PR_FAILURE;
45 if (PR_Close(fd) == PR_FAILURE) {
46 fprintf(stderr, "PR_Close failed: %d\n", (int)PR_GetError());
47 return PR_FAILURE;
49 PR_Free(pathname);
50 return PR_SUCCESS;
53 int main(int argc, char **argv)
55 char *name;
56 PRFuncPtr addr;
57 PRLibrary *lib;
58 PRBool failed = PR_FALSE;
60 if (argc >= 2 && strcmp(argv[1], "-d") == 0) {
61 debug_mode = PR_TRUE;
64 /* First test a library that is implicitly linked. */
65 #ifdef WINNT
66 name = PR_Malloc(strlen("libnspr4.dll")+1);
67 strcpy(name, "libnspr4.dll");
68 #else
69 name = PR_GetLibraryName(NULL, "nspr4");
70 #endif
71 addr = (PRFuncPtr)PR_GetTCPMethods()->close;
72 if (RunTest(name, addr) == PR_FAILURE) {
73 failed = PR_TRUE;
75 PR_FreeLibraryName(name);
77 /* Next test a library that is dynamically loaded. */
78 name = PR_GetLibraryName("dll", "my");
79 if (debug_mode) {
80 printf("Loading library %s\n", name);
82 lib = PR_LoadLibrary(name);
83 if (!lib) {
84 fprintf(stderr, "PR_LoadLibrary failed\n");
85 exit(1);
87 PR_FreeLibraryName(name);
88 name = PR_GetLibraryName(NULL, "my");
89 addr = PR_FindFunctionSymbol(lib, "My_GetValue");
90 if (RunTest(name, addr) == PR_FAILURE) {
91 failed = PR_TRUE;
93 PR_FreeLibraryName(name);
94 PR_UnloadLibrary(lib);
95 if (failed) {
96 printf("FAIL\n");
97 return 1;
99 printf("PASS\n");
100 return 0;