nsprpub/pr/tests/mbcs.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.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 ** File: mbcs.c
michael@0 8 **
michael@0 9 ** Synopsis: mbcs {dirName}
michael@0 10 **
michael@0 11 ** where dirName is the directory to be traversed. dirName is required.
michael@0 12 **
michael@0 13 ** Description:
michael@0 14 ** mbcs.c tests use of multi-byte characters, as would be passed to
michael@0 15 ** NSPR funtions by internationalized applications.
michael@0 16 **
michael@0 17 ** mbcs.c, when run on any single-byte platform, should run correctly.
michael@0 18 ** In truth, running the mbcs test on a single-byte platform is
michael@0 19 ** really meaningless. mbcs.c, nor any NSPR library or test is not
michael@0 20 ** intended for use with any wide character set, including Unicode.
michael@0 21 ** mbcs.c should not be included in runtests.ksh because it requires
michael@0 22 ** extensive user intervention to set-up and run.
michael@0 23 **
michael@0 24 ** mbcs.c should be run on a platform using some form of multi-byte
michael@0 25 ** characters. The initial platform for this test is a Japanese
michael@0 26 ** language Windows NT 4.0 machine. ... Thank you Noriko Hoshi.
michael@0 27 **
michael@0 28 ** To run mbcs.c, the tester should create a directory tree containing
michael@0 29 ** some files in the same directory from which the test is run; i.e.
michael@0 30 ** the current working directory. The directory and files should be
michael@0 31 ** named such that when represented in the local multi-byte character
michael@0 32 ** set, one or more characters of the name is longer than a single
michael@0 33 ** byte.
michael@0 34 **
michael@0 35 */
michael@0 36
michael@0 37 #include <plgetopt.h>
michael@0 38 #include <nspr.h>
michael@0 39 #include <stdio.h>
michael@0 40 #include <stdlib.h>
michael@0 41 #include <string.h>
michael@0 42
michael@0 43 /*
michael@0 44 ** Test harness infrastructure
michael@0 45 */
michael@0 46 PRLogModuleInfo *lm;
michael@0 47 PRLogModuleLevel msgLevel = PR_LOG_NONE;
michael@0 48 PRIntn debug = 0;
michael@0 49 PRUint32 failed_already = 0;
michael@0 50 /* end Test harness infrastructure */
michael@0 51
michael@0 52 char *dirName = NULL; /* directory name to traverse */
michael@0 53
michael@0 54 /*
michael@0 55 ** Traverse directory
michael@0 56 */
michael@0 57 static void TraverseDirectory( unsigned char *dir )
michael@0 58 {
michael@0 59 PRDir *cwd;
michael@0 60 PRDirEntry *dirEntry;
michael@0 61 PRFileInfo info;
michael@0 62 PRStatus rc;
michael@0 63 PRInt32 err;
michael@0 64 PRFileDesc *fd;
michael@0 65 char nextDir[256];
michael@0 66 char file[256];
michael@0 67
michael@0 68 printf("Directory: %s\n", dir );
michael@0 69 cwd = PR_OpenDir( dir );
michael@0 70 if ( NULL == cwd ) {
michael@0 71 printf("PR_OpenDir() failed on directory: %s, with error: %d, %d\n",
michael@0 72 dir, PR_GetError(), PR_GetOSError());
michael@0 73 exit(1);
michael@0 74 }
michael@0 75 while( NULL != (dirEntry = PR_ReadDir( cwd, PR_SKIP_BOTH | PR_SKIP_HIDDEN ))) {
michael@0 76 sprintf( file, "%s/%s", dir, dirEntry->name );
michael@0 77 rc = PR_GetFileInfo( file, &info );
michael@0 78 if ( PR_FAILURE == rc ) {
michael@0 79 printf("PR_GetFileInfo() failed on file: %s, with error: %d, %d\n",
michael@0 80 dirEntry->name, PR_GetError(), PR_GetOSError());
michael@0 81 exit(1);
michael@0 82 }
michael@0 83 if ( PR_FILE_FILE == info.type ) {
michael@0 84 printf("File: %s \tsize: %ld\n", dirEntry->name, info.size );
michael@0 85 fd = PR_Open( file, PR_RDONLY, 0 );
michael@0 86 if ( NULL == fd ) {
michael@0 87 printf("PR_Open() failed. Error: %ld, OSError: %ld\n",
michael@0 88 PR_GetError(), PR_GetOSError());
michael@0 89 }
michael@0 90 rc = PR_Close( fd );
michael@0 91 if ( PR_FAILURE == rc ) {
michael@0 92 printf("PR_Close() failed. Error: %ld, OSError: %ld\n",
michael@0 93 PR_GetError(), PR_GetOSError());
michael@0 94 }
michael@0 95 } else if ( PR_FILE_DIRECTORY == info.type ) {
michael@0 96 sprintf( nextDir, "%s/%s", dir, dirEntry->name );
michael@0 97 TraverseDirectory(nextDir);
michael@0 98 } else {
michael@0 99 printf("type is not interesting for file: %s\n", dirEntry->name );
michael@0 100 /* keep going */
michael@0 101 }
michael@0 102 }
michael@0 103 /* assume end-of-file, actually could be error */
michael@0 104
michael@0 105 rc = PR_CloseDir( cwd );
michael@0 106 if ( PR_FAILURE == rc ) {
michael@0 107 printf("PR_CloseDir() failed on directory: %s, with error: %d, %d\n",
michael@0 108 dir, PR_GetError(), PR_GetOSError());
michael@0 109 }
michael@0 110
michael@0 111 } /* end TraverseDirectory() */
michael@0 112
michael@0 113 int main(int argc, char **argv)
michael@0 114 {
michael@0 115 { /* get command line options */
michael@0 116 /*
michael@0 117 ** Get command line options
michael@0 118 */
michael@0 119 PLOptStatus os;
michael@0 120 PLOptState *opt = PL_CreateOptState(argc, argv, "dv");
michael@0 121
michael@0 122 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
michael@0 123 {
michael@0 124 if (PL_OPT_BAD == os) continue;
michael@0 125 switch (opt->option)
michael@0 126 {
michael@0 127 case 'd': /* debug */
michael@0 128 debug = 1;
michael@0 129 msgLevel = PR_LOG_ERROR;
michael@0 130 break;
michael@0 131 case 'v': /* verbose mode */
michael@0 132 msgLevel = PR_LOG_DEBUG;
michael@0 133 break;
michael@0 134 default:
michael@0 135 dirName = strdup(opt->value);
michael@0 136 break;
michael@0 137 }
michael@0 138 }
michael@0 139 PL_DestroyOptState(opt);
michael@0 140 } /* end get command line options */
michael@0 141
michael@0 142 lm = PR_NewLogModule("Test"); /* Initialize logging */
michael@0 143
michael@0 144
michael@0 145 if ( dirName == NULL ) {
michael@0 146 printf("you gotta specify a directory as an operand!\n");
michael@0 147 exit(1);
michael@0 148 }
michael@0 149
michael@0 150 TraverseDirectory( dirName );
michael@0 151
michael@0 152 if (debug) printf("%s\n", (failed_already)? "FAIL" : "PASS");
michael@0 153 return( (failed_already == PR_TRUE )? 1 : 0 );
michael@0 154 } /* main() */
michael@0 155 /* end template.c */

mercurial