nsprpub/pr/tests/mbcs.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/mbcs.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,155 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 +** File: mbcs.c
    1.11 +**
    1.12 +** Synopsis: mbcs {dirName}
    1.13 +**
    1.14 +** where dirName is the directory to be traversed. dirName is required.
    1.15 +**
    1.16 +** Description: 
    1.17 +** mbcs.c tests use of multi-byte characters, as would be passed to
    1.18 +** NSPR funtions by internationalized applications. 
    1.19 +**
    1.20 +** mbcs.c, when run on any single-byte platform, should run correctly.
    1.21 +** In truth, running the mbcs test on a single-byte platform is
    1.22 +** really meaningless. mbcs.c, nor any NSPR library or test is not
    1.23 +** intended for use with any wide character set, including Unicode.
    1.24 +** mbcs.c should not be included in runtests.ksh because it requires
    1.25 +** extensive user intervention to set-up and run.
    1.26 +**
    1.27 +** mbcs.c should be run on a platform using some form of multi-byte
    1.28 +** characters. The initial platform for this test is a Japanese
    1.29 +** language Windows NT 4.0 machine. ... Thank you Noriko Hoshi.
    1.30 +**
    1.31 +** To run mbcs.c, the tester should create a directory tree containing
    1.32 +** some files in the same directory from which the test is run; i.e.
    1.33 +** the current working directory. The directory and files should be
    1.34 +** named such that when represented in the local multi-byte character
    1.35 +** set, one or more characters of the name is longer than a single
    1.36 +** byte.
    1.37 +** 
    1.38 +*/
    1.39 +
    1.40 +#include <plgetopt.h> 
    1.41 +#include <nspr.h> 
    1.42 +#include <stdio.h>
    1.43 +#include <stdlib.h>
    1.44 +#include <string.h>
    1.45 +
    1.46 +/*
    1.47 +** Test harness infrastructure
    1.48 +*/
    1.49 +PRLogModuleInfo *lm;
    1.50 +PRLogModuleLevel msgLevel = PR_LOG_NONE;
    1.51 +PRIntn  debug = 0;
    1.52 +PRUint32  failed_already = 0;
    1.53 +/* end Test harness infrastructure */
    1.54 +
    1.55 +char *dirName =  NULL;  /* directory name to traverse */
    1.56 +
    1.57 +/*
    1.58 +** Traverse directory
    1.59 +*/
    1.60 +static void TraverseDirectory( unsigned char *dir )
    1.61 +{
    1.62 +    PRDir *cwd;
    1.63 +    PRDirEntry *dirEntry;
    1.64 +    PRFileInfo info;
    1.65 +    PRStatus rc;
    1.66 +    PRInt32 err;
    1.67 +    PRFileDesc *fd;
    1.68 +    char    nextDir[256];
    1.69 +    char    file[256];
    1.70 +
    1.71 +    printf("Directory: %s\n", dir );
    1.72 +    cwd = PR_OpenDir( dir );
    1.73 +    if ( NULL == cwd )  {
    1.74 +        printf("PR_OpenDir() failed on directory: %s, with error: %d, %d\n", 
    1.75 +            dir, PR_GetError(), PR_GetOSError());
    1.76 +        exit(1);
    1.77 +    }
    1.78 +    while( NULL != (dirEntry = PR_ReadDir( cwd, PR_SKIP_BOTH | PR_SKIP_HIDDEN )))  {
    1.79 +        sprintf( file, "%s/%s", dir, dirEntry->name );
    1.80 +        rc = PR_GetFileInfo( file, &info );
    1.81 +        if ( PR_FAILURE == rc ) {
    1.82 +            printf("PR_GetFileInfo() failed on file: %s, with error: %d, %d\n", 
    1.83 +                dirEntry->name, PR_GetError(), PR_GetOSError());
    1.84 +            exit(1);
    1.85 +        }
    1.86 +        if ( PR_FILE_FILE == info.type )  {
    1.87 +            printf("File: %s \tsize: %ld\n", dirEntry->name, info.size );
    1.88 +            fd = PR_Open( file, PR_RDONLY, 0 );
    1.89 +            if ( NULL == fd )  {
    1.90 +                printf("PR_Open() failed. Error: %ld, OSError: %ld\n", 
    1.91 +                    PR_GetError(), PR_GetOSError());
    1.92 +            }
    1.93 +            rc = PR_Close( fd );
    1.94 +            if ( PR_FAILURE == rc )  {
    1.95 +                printf("PR_Close() failed. Error: %ld, OSError: %ld\n", 
    1.96 +                    PR_GetError(), PR_GetOSError());
    1.97 +            }
    1.98 +        } else if ( PR_FILE_DIRECTORY == info.type ) {
    1.99 +            sprintf( nextDir, "%s/%s", dir, dirEntry->name );
   1.100 +            TraverseDirectory(nextDir);
   1.101 +        } else {
   1.102 +            printf("type is not interesting for file: %s\n", dirEntry->name );
   1.103 +            /* keep going */
   1.104 +        }
   1.105 +    }
   1.106 +    /* assume end-of-file, actually could be error */
   1.107 +
   1.108 +    rc = PR_CloseDir( cwd );
   1.109 +    if ( PR_FAILURE == rc ) {
   1.110 +        printf("PR_CloseDir() failed on directory: %s, with error: %d, %d\n", 
   1.111 +            dir, PR_GetError(), PR_GetOSError());
   1.112 +    }
   1.113 +
   1.114 +} /* end TraverseDirectory() */
   1.115 +
   1.116 +int main(int argc, char **argv)
   1.117 +{
   1.118 +    { /* get command line options */
   1.119 +        /*
   1.120 +        ** Get command line options
   1.121 +        */
   1.122 +        PLOptStatus os;
   1.123 +        PLOptState *opt = PL_CreateOptState(argc, argv, "dv");
   1.124 +
   1.125 +	    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
   1.126 +        {
   1.127 +		    if (PL_OPT_BAD == os) continue;
   1.128 +            switch (opt->option)
   1.129 +            {
   1.130 +            case 'd':  /* debug */
   1.131 +                debug = 1;
   1.132 +			    msgLevel = PR_LOG_ERROR;
   1.133 +                break;
   1.134 +            case 'v':  /* verbose mode */
   1.135 +			    msgLevel = PR_LOG_DEBUG;
   1.136 +                break;
   1.137 +             default:
   1.138 +                dirName = strdup(opt->value); 
   1.139 +                break; 
   1.140 +            }
   1.141 +        }
   1.142 +	    PL_DestroyOptState(opt);
   1.143 +    } /* end get command line options */
   1.144 +
   1.145 +    lm = PR_NewLogModule("Test");       /* Initialize logging */
   1.146 +
   1.147 +    
   1.148 +    if ( dirName == NULL )  {
   1.149 +        printf("you gotta specify a directory as an operand!\n");
   1.150 +        exit(1);
   1.151 +    }
   1.152 +
   1.153 +    TraverseDirectory( dirName );
   1.154 +
   1.155 +    if (debug) printf("%s\n", (failed_already)? "FAIL" : "PASS");
   1.156 +    return( (failed_already == PR_TRUE )? 1 : 0 );
   1.157 +}  /* main() */
   1.158 +/* end template.c */

mercurial