Debian Codegraph @

nsprpub/pr/tests/prftest2.c

raw
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 PR_STDIO_INIT();
73 i16 = -32;
74 n = 30;
75 i32 = 64;
76 LL_I2L(i64, 333);
77 PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32);
78 if (!strcmp(buf, "30 -32 333 64")) {
79 if (debug_mode) {
80 printf("PR_snprintf test 2 passed\n");
81 }
82 } else {
83 if (debug_mode) {
84 printf("PR_snprintf test 2 failed\n");
85 printf("Converted string is %s\n", buf);
86 printf("Should be 30 -32 333 64\n");
87 } else {
88 failed_already = 1;
89 }
90 }
91 if (failed_already) {
92 printf("FAILED\n");
93 return 1;
94 } else {
95 printf("PASSED\n");
96 return 0;
97 }
98 }