1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/tests/prftest2.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 +** File: prftest2.c 1.11 +** Description: 1.12 +** This is a simple test of the PR_snprintf() function defined 1.13 +** in prprf.c. 1.14 +** 1.15 +** Modification History: 1.16 +** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag. 1.17 +** The debug mode will print all of the printfs associated with this test. 1.18 +** The regress mode will be the default mode. Since the regress tool limits 1.19 +** the output to a one line status:PASS or FAIL,all of the printf statements 1.20 +** have been handled with an if (debug_mode) statement. 1.21 +** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to 1.22 +** recognize the return code from tha main program. 1.23 +***********************************************************************/ 1.24 +/*********************************************************************** 1.25 +** Includes 1.26 +***********************************************************************/ 1.27 +/* Used to get the command line option */ 1.28 +#include "plgetopt.h" 1.29 + 1.30 +#include "prlong.h" 1.31 +#include "prinit.h" 1.32 +#include "prprf.h" 1.33 + 1.34 +#include <string.h> 1.35 + 1.36 +#define BUF_SIZE 128 1.37 + 1.38 +PRIntn failed_already=0; 1.39 +PRIntn debug_mode; 1.40 + 1.41 +int main(int argc, char **argv) 1.42 +{ 1.43 + PRInt16 i16; 1.44 + PRIntn n; 1.45 + PRInt32 i32; 1.46 + PRInt64 i64; 1.47 + char buf[BUF_SIZE]; 1.48 + 1.49 + /* The command line argument: -d is used to determine if the test is being run 1.50 + in debug mode. The regress tool requires only one line output:PASS or FAIL. 1.51 + All of the printfs associated with this test has been handled with a if (debug_mode) 1.52 + test. 1.53 + Usage: test_name -d 1.54 + */ 1.55 + PLOptStatus os; 1.56 + PLOptState *opt = PL_CreateOptState(argc, argv, "d:"); 1.57 + while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) 1.58 + { 1.59 + if (PL_OPT_BAD == os) continue; 1.60 + switch (opt->option) 1.61 + { 1.62 + case 'd': /* debug mode */ 1.63 + debug_mode = 1; 1.64 + break; 1.65 + default: 1.66 + break; 1.67 + } 1.68 + } 1.69 + PL_DestroyOptState(opt); 1.70 + 1.71 + /* main test */ 1.72 + 1.73 + 1.74 + PR_STDIO_INIT(); 1.75 + i16 = -32; 1.76 + n = 30; 1.77 + i32 = 64; 1.78 + LL_I2L(i64, 333); 1.79 + PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32); 1.80 + if (!strcmp(buf, "30 -32 333 64")) { 1.81 + if (debug_mode) printf("PR_snprintf test 2 passed\n"); 1.82 + } else { 1.83 + if (debug_mode) { 1.84 + printf("PR_snprintf test 2 failed\n"); 1.85 + printf("Converted string is %s\n", buf); 1.86 + printf("Should be 30 -32 333 64\n"); 1.87 + } 1.88 + else failed_already=1; 1.89 + } 1.90 + if(failed_already) 1.91 + { 1.92 + printf("FAILED\n"); 1.93 + return 1; 1.94 + } 1.95 + else 1.96 + { 1.97 + printf("PASSED\n"); 1.98 + return 0; 1.99 + } 1.100 +}