nsprpub/pr/tests/prftest2.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     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 test.
    15 **			 The regress mode will be the default mode. Since the regress tool limits
    16 **           the output to a one line status:PASS or FAIL,all of the printf statements
    17 **			 have been handled with an if (debug_mode) statement.
    18 ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
    19 **			recognize the return code from tha main program.
    20 ***********************************************************************/
    21 /***********************************************************************
    22 ** Includes
    23 ***********************************************************************/
    24 /* Used to get the command line option */
    25 #include "plgetopt.h"
    27 #include "prlong.h"
    28 #include "prinit.h"
    29 #include "prprf.h"
    31 #include <string.h>
    33 #define BUF_SIZE 128
    35 PRIntn failed_already=0;
    36 PRIntn debug_mode;
    38 int main(int argc, char **argv)
    39 {
    40     PRInt16 i16;
    41     PRIntn n;
    42     PRInt32 i32;
    43     PRInt64 i64;
    44     char buf[BUF_SIZE];
    46 	/* The command line argument: -d is used to determine if the test is being run
    47 	in debug mode. The regress tool requires only one line output:PASS or FAIL.
    48 	All of the printfs associated with this test has been handled with a if (debug_mode)
    49 	test.
    50 	Usage: test_name -d
    51 	*/
    52 	PLOptStatus os;
    53 	PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
    54 	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    55     {
    56 		if (PL_OPT_BAD == os) continue;
    57         switch (opt->option)
    58         {
    59         case 'd':  /* debug mode */
    60 			debug_mode = 1;
    61             break;
    62          default:
    63             break;
    64         }
    65     }
    66 	PL_DestroyOptState(opt);
    68 	/* main test */
    71     PR_STDIO_INIT();
    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) printf("PR_snprintf test 2 passed\n");
    79     } else {
    80 		if (debug_mode) {
    81 			printf("PR_snprintf test 2 failed\n");
    82 			printf("Converted string is %s\n", buf);
    83 			printf("Should be 30 -32 333 64\n");
    84 		}
    85 		else failed_already=1;
    86     }
    87 	if(failed_already)
    88 	{
    89         printf("FAILED\n");
    90 		return 1;
    91 	}
    92 	else
    93 	{
    94         printf("PASSED\n");
    95 		return 0;
    96 	}
    97 }

mercurial