prftest2.c (2766B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 /* 7 ** File: prftest2.c 8 ** Description: 9 ** This is a simple test of the PR_snprintf() function defined 10 ** in prprf.c. 11 ** 12 ** Modification History: 13 ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag. 14 ** The debug mode will print all of the printfs associated with this 15 *test. 16 ** The regress mode will be the default mode. Since the regress tool 17 *limits 18 ** the output to a one line status:PASS or FAIL,all of the printf 19 *statements 20 ** have been handled with an if (debug_mode) statement. 21 ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been 22 *updated to 23 ** recognize the return code from tha main program. 24 ***********************************************************************/ 25 /*********************************************************************** 26 ** Includes 27 ***********************************************************************/ 28 /* Used to get the command line option */ 29 #include "plgetopt.h" 30 31 #include "prlong.h" 32 #include "prinit.h" 33 #include "prprf.h" 34 35 #include <string.h> 36 37 #define BUF_SIZE 128 38 39 PRIntn failed_already = 0; 40 PRIntn debug_mode; 41 42 int main(int argc, char** argv) { 43 PRInt16 i16; 44 PRIntn n; 45 PRInt32 i32; 46 PRInt64 i64; 47 char buf[BUF_SIZE]; 48 49 /* The command line argument: -d is used to determine if the test is being run 50 in debug mode. The regress tool requires only one line output:PASS or FAIL. 51 All of the printfs associated with this test has been handled with a if 52 (debug_mode) test. Usage: test_name -d 53 */ 54 PLOptStatus os; 55 PLOptState* opt = PL_CreateOptState(argc, argv, "d:"); 56 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) { 57 if (PL_OPT_BAD == os) { 58 continue; 59 } 60 switch (opt->option) { 61 case 'd': /* debug mode */ 62 debug_mode = 1; 63 break; 64 default: 65 break; 66 } 67 } 68 PL_DestroyOptState(opt); 69 70 /* main test */ 71 72 i16 = -32; 73 n = 30; 74 i32 = 64; 75 LL_I2L(i64, 333); 76 PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32); 77 if (!strcmp(buf, "30 -32 333 64")) { 78 if (debug_mode) { 79 printf("PR_snprintf test 2 passed\n"); 80 } 81 } else { 82 if (debug_mode) { 83 printf("PR_snprintf test 2 failed\n"); 84 printf("Converted string is %s\n", buf); 85 printf("Should be 30 -32 333 64\n"); 86 } else { 87 failed_already = 1; 88 } 89 } 90 if (failed_already) { 91 printf("FAILED\n"); 92 return 1; 93 } else { 94 printf("PASSED\n"); 95 return 0; 96 } 97 }