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
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/
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
15 * The Original Code is the Netscape Portable Runtime (NSPR).
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
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.
36 * ***** END LICENSE BLOCK ***** */
41 ** Synopsis: mbcs {dirName}
43 ** where dirName is the directory to be traversed. dirName is required.
46 ** mbcs.c tests use of multi-byte characters, as would be passed to
47 ** NSPR funtions by internationalized applications.
49 ** mbcs.c, when run on any single-byte platform, should run correctly.
50 ** In truth, running the mbcs test on a single-byte platform is
51 ** really meaningless. mbcs.c, nor any NSPR library or test is not
52 ** intended for use with any wide character set, including Unicode.
53 ** mbcs.c should not be included in runtests.ksh because it requires
54 ** extensive user intervention to set-up and run.
56 ** mbcs.c should be run on a platform using some form of multi-byte
57 ** characters. The initial platform for this test is a Japanese
58 ** language Windows NT 4.0 machine. ... Thank you Noriko Hoshi.
60 ** To run mbcs.c, the tester should create a directory tree containing
61 ** some files in the same directory from which the test is run; i.e.
62 ** the current working directory. The directory and files should be
63 ** named such that when represented in the local multi-byte character
64 ** set, one or more characters of the name is longer than a single
76 ** Test harness infrastructure
79 PRLogModuleLevel msgLevel
= PR_LOG_NONE
;
81 PRUint32 failed_already
= 0;
82 /* end Test harness infrastructure */
84 char *dirName
= NULL
; /* directory name to traverse */
89 static void TraverseDirectory( unsigned char *dir
)
100 printf("Directory: %s\n", dir
);
101 cwd
= PR_OpenDir( dir
);
103 printf("PR_OpenDir() failed on directory: %s, with error: %d, %d\n",
104 dir
, PR_GetError(), PR_GetOSError());
107 while( NULL
!= (dirEntry
= PR_ReadDir( cwd
, PR_SKIP_BOTH
| PR_SKIP_HIDDEN
))) {
108 sprintf( file
, "%s/%s", dir
, dirEntry
->name
);
109 rc
= PR_GetFileInfo( file
, &info
);
110 if ( PR_FAILURE
== rc
) {
111 printf("PR_GetFileInfo() failed on file: %s, with error: %d, %d\n",
112 dirEntry
->name
, PR_GetError(), PR_GetOSError());
115 if ( PR_FILE_FILE
== info
.type
) {
116 printf("File: %s \tsize: %ld\n", dirEntry
->name
, info
.size
);
117 fd
= PR_Open( file
, PR_RDONLY
, 0 );
119 printf("PR_Open() failed. Error: %ld, OSError: %ld\n",
120 PR_GetError(), PR_GetOSError());
123 if ( PR_FAILURE
== rc
) {
124 printf("PR_Close() failed. Error: %ld, OSError: %ld\n",
125 PR_GetError(), PR_GetOSError());
127 } else if ( PR_FILE_DIRECTORY
== info
.type
) {
128 sprintf( nextDir
, "%s/%s", dir
, dirEntry
->name
);
129 TraverseDirectory(nextDir
);
131 printf("type is not interesting for file: %s\n", dirEntry
->name
);
135 /* assume end-of-file, actually could be error */
137 rc
= PR_CloseDir( cwd
);
138 if ( PR_FAILURE
== rc
) {
139 printf("PR_CloseDir() failed on directory: %s, with error: %d, %d\n",
140 dir
, PR_GetError(), PR_GetOSError());
143 } /* end TraverseDirectory() */
145 PRIntn
main(PRIntn argc
, char *argv
[])
147 { /* get command line options */
149 ** Get command line options
152 PLOptState
*opt
= PL_CreateOptState(argc
, argv
, "dv");
154 while (PL_OPT_EOL
!= (os
= PL_GetNextOpt(opt
)))
156 if (PL_OPT_BAD
== os
) continue;
159 case 'd': /* debug */
161 msgLevel
= PR_LOG_ERROR
;
163 case 'v': /* verbose mode */
164 msgLevel
= PR_LOG_DEBUG
;
167 dirName
= strdup(opt
->value
);
171 PL_DestroyOptState(opt
);
172 } /* end get command line options */
174 lm
= PR_NewLogModule("Test"); /* Initialize logging */
177 if ( dirName
== NULL
) {
178 printf("you gotta specify a directory as an operand!\n");
182 TraverseDirectory( dirName
);
184 if (debug
) printf("%s\n", (failed_already
)? "FAIL" : "PASS");
185 return( (failed_already
== PR_TRUE
)? 1 : 0 );