VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/tests/libfilename.c@ 1

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2003
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/***********************************************************************
39**
40** Name: libfilename.c
41**
42** Description: test PR_GetLibraryFilePathname.
43**
44***********************************************************************/
45
46#include "nspr.h"
47#include "pprio.h"
48#include <stdio.h>
49#include <stdlib.h>
50#include <string.h>
51
52PRBool debug_mode = PR_FALSE;
53
54static PRStatus RunTest(const char *name, PRFuncPtr addr)
55{
56 char *pathname;
57 PRFileDesc *fd;
58
59 pathname = PR_GetLibraryFilePathname(name, addr);
60 if (pathname == NULL) {
61 fprintf(stderr, "PR_GetLibraryFilePathname failed\n");
62 /* we let this test pass if this function is not implemented */
63 if (PR_GetError() == PR_NOT_IMPLEMENTED_ERROR) {
64 return PR_SUCCESS;
65 }
66 return PR_FAILURE;
67 }
68
69 if (debug_mode) printf("Pathname is %s\n", pathname);
70 fd = PR_OpenFile(pathname, PR_RDONLY, 0);
71 if (fd == NULL) {
72 fprintf(stderr, "PR_Open failed: %d\n", (int)PR_GetError());
73 return PR_FAILURE;
74 }
75 if (PR_Close(fd) == PR_FAILURE) {
76 fprintf(stderr, "PR_Close failed: %d\n", (int)PR_GetError());
77 return PR_FAILURE;
78 }
79 PR_Free(pathname);
80 return PR_SUCCESS;
81}
82
83int main(int argc, char *argv[])
84{
85 char *name;
86 PRFuncPtr addr;
87 PRLibrary *lib;
88 PRBool failed = PR_FALSE;
89
90 if (argc >= 2 && strcmp(argv[1], "-d") == 0) {
91 debug_mode = PR_TRUE;
92 }
93
94 /* First test a library that is implicitly linked. */
95#ifdef WINNT
96 name = PR_Malloc(strlen("libnspr4.dll")+1);
97 strcpy(name, "libnspr4.dll");
98#else
99 name = PR_GetLibraryName(NULL, "nspr4");
100#endif
101 addr = (PRFuncPtr)PR_GetTCPMethods()->close;
102 if (RunTest(name, addr) == PR_FAILURE) {
103 failed = PR_TRUE;
104 }
105 PR_FreeLibraryName(name);
106
107 /* Next test a library that is dynamically loaded. */
108 name = PR_GetLibraryName("dll", "my");
109 if (debug_mode) printf("Loading library %s\n", name);
110 lib = PR_LoadLibrary(name);
111 if (!lib) {
112 fprintf(stderr, "PR_LoadLibrary failed\n");
113 exit(1);
114 }
115 PR_FreeLibraryName(name);
116 name = PR_GetLibraryName(NULL, "my");
117 addr = PR_FindFunctionSymbol(lib, "My_GetValue");
118 if (RunTest(name, addr) == PR_FAILURE) {
119 failed = PR_TRUE;
120 }
121 PR_FreeLibraryName(name);
122 PR_UnloadLibrary(lib);
123 if (failed) {
124 printf("FAIL\n");
125 return 1;
126 }
127 printf("PASS\n");
128 return 0;
129}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette