michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** File: mbcs.c michael@0: ** michael@0: ** Synopsis: mbcs {dirName} michael@0: ** michael@0: ** where dirName is the directory to be traversed. dirName is required. michael@0: ** michael@0: ** Description: michael@0: ** mbcs.c tests use of multi-byte characters, as would be passed to michael@0: ** NSPR funtions by internationalized applications. michael@0: ** michael@0: ** mbcs.c, when run on any single-byte platform, should run correctly. michael@0: ** In truth, running the mbcs test on a single-byte platform is michael@0: ** really meaningless. mbcs.c, nor any NSPR library or test is not michael@0: ** intended for use with any wide character set, including Unicode. michael@0: ** mbcs.c should not be included in runtests.ksh because it requires michael@0: ** extensive user intervention to set-up and run. michael@0: ** michael@0: ** mbcs.c should be run on a platform using some form of multi-byte michael@0: ** characters. The initial platform for this test is a Japanese michael@0: ** language Windows NT 4.0 machine. ... Thank you Noriko Hoshi. michael@0: ** michael@0: ** To run mbcs.c, the tester should create a directory tree containing michael@0: ** some files in the same directory from which the test is run; i.e. michael@0: ** the current working directory. The directory and files should be michael@0: ** named such that when represented in the local multi-byte character michael@0: ** set, one or more characters of the name is longer than a single michael@0: ** byte. michael@0: ** michael@0: */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: /* michael@0: ** Test harness infrastructure michael@0: */ michael@0: PRLogModuleInfo *lm; michael@0: PRLogModuleLevel msgLevel = PR_LOG_NONE; michael@0: PRIntn debug = 0; michael@0: PRUint32 failed_already = 0; michael@0: /* end Test harness infrastructure */ michael@0: michael@0: char *dirName = NULL; /* directory name to traverse */ michael@0: michael@0: /* michael@0: ** Traverse directory michael@0: */ michael@0: static void TraverseDirectory( unsigned char *dir ) michael@0: { michael@0: PRDir *cwd; michael@0: PRDirEntry *dirEntry; michael@0: PRFileInfo info; michael@0: PRStatus rc; michael@0: PRInt32 err; michael@0: PRFileDesc *fd; michael@0: char nextDir[256]; michael@0: char file[256]; michael@0: michael@0: printf("Directory: %s\n", dir ); michael@0: cwd = PR_OpenDir( dir ); michael@0: if ( NULL == cwd ) { michael@0: printf("PR_OpenDir() failed on directory: %s, with error: %d, %d\n", michael@0: dir, PR_GetError(), PR_GetOSError()); michael@0: exit(1); michael@0: } michael@0: while( NULL != (dirEntry = PR_ReadDir( cwd, PR_SKIP_BOTH | PR_SKIP_HIDDEN ))) { michael@0: sprintf( file, "%s/%s", dir, dirEntry->name ); michael@0: rc = PR_GetFileInfo( file, &info ); michael@0: if ( PR_FAILURE == rc ) { michael@0: printf("PR_GetFileInfo() failed on file: %s, with error: %d, %d\n", michael@0: dirEntry->name, PR_GetError(), PR_GetOSError()); michael@0: exit(1); michael@0: } michael@0: if ( PR_FILE_FILE == info.type ) { michael@0: printf("File: %s \tsize: %ld\n", dirEntry->name, info.size ); michael@0: fd = PR_Open( file, PR_RDONLY, 0 ); michael@0: if ( NULL == fd ) { michael@0: printf("PR_Open() failed. Error: %ld, OSError: %ld\n", michael@0: PR_GetError(), PR_GetOSError()); michael@0: } michael@0: rc = PR_Close( fd ); michael@0: if ( PR_FAILURE == rc ) { michael@0: printf("PR_Close() failed. Error: %ld, OSError: %ld\n", michael@0: PR_GetError(), PR_GetOSError()); michael@0: } michael@0: } else if ( PR_FILE_DIRECTORY == info.type ) { michael@0: sprintf( nextDir, "%s/%s", dir, dirEntry->name ); michael@0: TraverseDirectory(nextDir); michael@0: } else { michael@0: printf("type is not interesting for file: %s\n", dirEntry->name ); michael@0: /* keep going */ michael@0: } michael@0: } michael@0: /* assume end-of-file, actually could be error */ michael@0: michael@0: rc = PR_CloseDir( cwd ); michael@0: if ( PR_FAILURE == rc ) { michael@0: printf("PR_CloseDir() failed on directory: %s, with error: %d, %d\n", michael@0: dir, PR_GetError(), PR_GetOSError()); michael@0: } michael@0: michael@0: } /* end TraverseDirectory() */ michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: { /* get command line options */ michael@0: /* michael@0: ** Get command line options michael@0: */ michael@0: PLOptStatus os; michael@0: PLOptState *opt = PL_CreateOptState(argc, argv, "dv"); michael@0: michael@0: while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) michael@0: { michael@0: if (PL_OPT_BAD == os) continue; michael@0: switch (opt->option) michael@0: { michael@0: case 'd': /* debug */ michael@0: debug = 1; michael@0: msgLevel = PR_LOG_ERROR; michael@0: break; michael@0: case 'v': /* verbose mode */ michael@0: msgLevel = PR_LOG_DEBUG; michael@0: break; michael@0: default: michael@0: dirName = strdup(opt->value); michael@0: break; michael@0: } michael@0: } michael@0: PL_DestroyOptState(opt); michael@0: } /* end get command line options */ michael@0: michael@0: lm = PR_NewLogModule("Test"); /* Initialize logging */ michael@0: michael@0: michael@0: if ( dirName == NULL ) { michael@0: printf("you gotta specify a directory as an operand!\n"); michael@0: exit(1); michael@0: } michael@0: michael@0: TraverseDirectory( dirName ); michael@0: michael@0: if (debug) printf("%s\n", (failed_already)? "FAIL" : "PASS"); michael@0: return( (failed_already == PR_TRUE )? 1 : 0 ); michael@0: } /* main() */ michael@0: /* end template.c */