Back to index

lightning-sunbird  0.9+nobinonly
mbcs.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039 ** File: mbcs.c
00040 **
00041 ** Synopsis: mbcs {dirName}
00042 **
00043 ** where dirName is the directory to be traversed. dirName is required.
00044 **
00045 ** Description: 
00046 ** mbcs.c tests use of multi-byte characters, as would be passed to
00047 ** NSPR funtions by internationalized applications. 
00048 **
00049 ** mbcs.c, when run on any single-byte platform, should run correctly.
00050 ** In truth, running the mbcs test on a single-byte platform is
00051 ** really meaningless. mbcs.c, nor any NSPR library or test is not
00052 ** intended for use with any wide character set, including Unicode.
00053 ** mbcs.c should not be included in runtests.ksh because it requires
00054 ** extensive user intervention to set-up and run.
00055 **
00056 ** mbcs.c should be run on a platform using some form of multi-byte
00057 ** characters. The initial platform for this test is a Japanese
00058 ** language Windows NT 4.0 machine. ... Thank you Noriko Hoshi.
00059 **
00060 ** To run mbcs.c, the tester should create a directory tree containing
00061 ** some files in the same directory from which the test is run; i.e.
00062 ** the current working directory. The directory and files should be
00063 ** named such that when represented in the local multi-byte character
00064 ** set, one or more characters of the name is longer than a single
00065 ** byte.
00066 ** 
00067 */
00068 
00069 #include <plgetopt.h> 
00070 #include <nspr.h> 
00071 #include <stdio.h>
00072 #include <stdlib.h>
00073 #include <string.h>
00074 
00075 /*
00076 ** Test harness infrastructure
00077 */
00078 PRLogModuleInfo *lm;
00079 PRLogModuleLevel msgLevel = PR_LOG_NONE;
00080 PRIntn  debug = 0;
00081 PRUint32  failed_already = 0;
00082 /* end Test harness infrastructure */
00083 
00084 char *dirName =  NULL;  /* directory name to traverse */
00085 
00086 /*
00087 ** Traverse directory
00088 */
00089 static void TraverseDirectory( unsigned char *dir )
00090 {
00091     PRDir *cwd;
00092     PRDirEntry *dirEntry;
00093     PRFileInfo info;
00094     PRStatus rc;
00095     PRInt32 err;
00096     PRFileDesc *fd;
00097     char    nextDir[256];
00098     char    file[256];
00099 
00100     printf("Directory: %s\n", dir );
00101     cwd = PR_OpenDir( dir );
00102     if ( NULL == cwd )  {
00103         printf("PR_OpenDir() failed on directory: %s, with error: %d, %d\n", 
00104             dir, PR_GetError(), PR_GetOSError());
00105         exit(1);
00106     }
00107     while( NULL != (dirEntry = PR_ReadDir( cwd, PR_SKIP_BOTH | PR_SKIP_HIDDEN )))  {
00108         sprintf( file, "%s/%s", dir, dirEntry->name );
00109         rc = PR_GetFileInfo( file, &info );
00110         if ( PR_FAILURE == rc ) {
00111             printf("PR_GetFileInfo() failed on file: %s, with error: %d, %d\n", 
00112                 dirEntry->name, PR_GetError(), PR_GetOSError());
00113             exit(1);
00114         }
00115         if ( PR_FILE_FILE == info.type )  {
00116             printf("File: %s \tsize: %ld\n", dirEntry->name, info.size );
00117             fd = PR_Open( file, PR_RDONLY, 0 );
00118             if ( NULL == fd )  {
00119                 printf("PR_Open() failed. Error: %ld, OSError: %ld\n", 
00120                     PR_GetError(), PR_GetOSError());
00121             }
00122             rc = PR_Close( fd );
00123             if ( PR_FAILURE == rc )  {
00124                 printf("PR_Close() failed. Error: %ld, OSError: %ld\n", 
00125                     PR_GetError(), PR_GetOSError());
00126             }
00127         } else if ( PR_FILE_DIRECTORY == info.type ) {
00128             sprintf( nextDir, "%s/%s", dir, dirEntry->name );
00129             TraverseDirectory(nextDir);
00130         } else {
00131             printf("type is not interesting for file: %s\n", dirEntry->name );
00132             /* keep going */
00133         }
00134     }
00135     /* assume end-of-file, actually could be error */
00136 
00137     rc = PR_CloseDir( cwd );
00138     if ( PR_FAILURE == rc ) {
00139         printf("PR_CloseDir() failed on directory: %s, with error: %d, %d\n", 
00140             dir, PR_GetError(), PR_GetOSError());
00141     }
00142 
00143 } /* end TraverseDirectory() */
00144 
00145 PRIntn main(PRIntn argc, char *argv[])
00146 {
00147     { /* get command line options */
00148         /*
00149         ** Get command line options
00150         */
00151         PLOptStatus os;
00152         PLOptState *opt = PL_CreateOptState(argc, argv, "dv");
00153 
00154            while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
00155         {
00156                   if (PL_OPT_BAD == os) continue;
00157             switch (opt->option)
00158             {
00159             case 'd':  /* debug */
00160                 debug = 1;
00161                          msgLevel = PR_LOG_ERROR;
00162                 break;
00163             case 'v':  /* verbose mode */
00164                          msgLevel = PR_LOG_DEBUG;
00165                 break;
00166              default:
00167                 dirName = strdup(opt->value); 
00168                 break; 
00169             }
00170         }
00171            PL_DestroyOptState(opt);
00172     } /* end get command line options */
00173 
00174     lm = PR_NewLogModule("Test");       /* Initialize logging */
00175 
00176     
00177     if ( dirName == NULL )  {
00178         printf("you gotta specify a directory as an operand!\n");
00179         exit(1);
00180     }
00181 
00182     TraverseDirectory( dirName );
00183 
00184     if (debug) printf("%s\n", (failed_already)? "FAIL" : "PASS");
00185     return( (failed_already == PR_TRUE )? 1 : 0 );
00186 }  /* main() */
00187 /* end template.c */