nsprpub/pr/tests/libfilename.c

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

     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.
    11 **
    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)
    23 {
    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;
    33         }
    34         return PR_FAILURE;
    35     }
    37     if (debug_mode) printf("Pathname is %s\n", pathname);
    38     fd = PR_OpenFile(pathname, PR_RDONLY, 0);
    39     if (fd == NULL) {
    40         fprintf(stderr, "PR_Open failed: %d\n", (int)PR_GetError());
    41         return PR_FAILURE;
    42     }
    43     if (PR_Close(fd) == PR_FAILURE) {
    44         fprintf(stderr, "PR_Close failed: %d\n", (int)PR_GetError());
    45         return PR_FAILURE;
    46     }
    47     PR_Free(pathname);
    48     return PR_SUCCESS;
    49 }
    51 int main(int argc, char **argv)
    52 {
    53     char *name;
    54     PRFuncPtr addr;
    55     PRLibrary *lib;
    56     PRBool failed = PR_FALSE;
    58     if (argc >= 2 && strcmp(argv[1], "-d") == 0) {
    59         debug_mode = PR_TRUE;
    60     }
    62     /* First test a library that is implicitly linked. */
    63 #ifdef WINNT
    64     name = PR_Malloc(strlen("libnspr4.dll")+1);
    65     strcpy(name, "libnspr4.dll");
    66 #else
    67     name = PR_GetLibraryName(NULL, "nspr4");
    68 #endif
    69     addr = (PRFuncPtr)PR_GetTCPMethods()->close;
    70     if (RunTest(name, addr) == PR_FAILURE) {
    71         failed = PR_TRUE;
    72     }
    73     PR_FreeLibraryName(name);
    75     /* Next test a library that is dynamically loaded. */
    76     name = PR_GetLibraryName("dll", "my");
    77     if (debug_mode) printf("Loading library %s\n", name);
    78     lib = PR_LoadLibrary(name);
    79     if (!lib) {
    80         fprintf(stderr, "PR_LoadLibrary failed\n");
    81         exit(1);
    82     }
    83     PR_FreeLibraryName(name);
    84     name = PR_GetLibraryName(NULL, "my");
    85     addr = PR_FindFunctionSymbol(lib, "My_GetValue");
    86     if (RunTest(name, addr) == PR_FAILURE) {
    87         failed = PR_TRUE;
    88     }
    89     PR_FreeLibraryName(name);
    90     PR_UnloadLibrary(lib);
    91     if (failed) {
    92         printf("FAIL\n");
    93         return 1;
    94     }
    95     printf("PASS\n");
    96     return 0;
    97 }

mercurial