1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998-2000
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | /*
|
---|
39 | ** File: prftest2.c
|
---|
40 | ** Description:
|
---|
41 | ** This is a simple test of the PR_snprintf() function defined
|
---|
42 | ** in prprf.c.
|
---|
43 | **
|
---|
44 | ** Modification History:
|
---|
45 | ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
|
---|
46 | ** The debug mode will print all of the printfs associated with this test.
|
---|
47 | ** The regress mode will be the default mode. Since the regress tool limits
|
---|
48 | ** the output to a one line status:PASS or FAIL,all of the printf statements
|
---|
49 | ** have been handled with an if (debug_mode) statement.
|
---|
50 | ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
|
---|
51 | ** recognize the return code from tha main program.
|
---|
52 | ***********************************************************************/
|
---|
53 | /***********************************************************************
|
---|
54 | ** Includes
|
---|
55 | ***********************************************************************/
|
---|
56 | /* Used to get the command line option */
|
---|
57 | #include "plgetopt.h"
|
---|
58 |
|
---|
59 | #include "prlong.h"
|
---|
60 | #include "prinit.h"
|
---|
61 | #include "prprf.h"
|
---|
62 |
|
---|
63 | #include <string.h>
|
---|
64 |
|
---|
65 | #define BUF_SIZE 128
|
---|
66 |
|
---|
67 | PRIntn failed_already=0;
|
---|
68 | PRIntn debug_mode;
|
---|
69 |
|
---|
70 | int main( int argc, char *argv[])
|
---|
71 | {
|
---|
72 | PRInt16 i16;
|
---|
73 | PRIntn n;
|
---|
74 | PRInt32 i32;
|
---|
75 | PRInt64 i64;
|
---|
76 | char buf[BUF_SIZE];
|
---|
77 |
|
---|
78 | /* The command line argument: -d is used to determine if the test is being run
|
---|
79 | in debug mode. The regress tool requires only one line output:PASS or FAIL.
|
---|
80 | All of the printfs associated with this test has been handled with a if (debug_mode)
|
---|
81 | test.
|
---|
82 | Usage: test_name -d
|
---|
83 | */
|
---|
84 | PLOptStatus os;
|
---|
85 | PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
|
---|
86 | while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
|
---|
87 | {
|
---|
88 | if (PL_OPT_BAD == os) continue;
|
---|
89 | switch (opt->option)
|
---|
90 | {
|
---|
91 | case 'd': /* debug mode */
|
---|
92 | debug_mode = 1;
|
---|
93 | break;
|
---|
94 | default:
|
---|
95 | break;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | PL_DestroyOptState(opt);
|
---|
99 |
|
---|
100 | /* main test */
|
---|
101 |
|
---|
102 |
|
---|
103 | PR_STDIO_INIT();
|
---|
104 | i16 = -32;
|
---|
105 | n = 30;
|
---|
106 | i32 = 64;
|
---|
107 | LL_I2L(i64, 333);
|
---|
108 | PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32);
|
---|
109 | if (!strcmp(buf, "30 -32 333 64")) {
|
---|
110 | if (debug_mode) printf("PR_snprintf test 2 passed\n");
|
---|
111 | } else {
|
---|
112 | if (debug_mode) {
|
---|
113 | printf("PR_snprintf test 2 failed\n");
|
---|
114 | printf("Converted string is %s\n", buf);
|
---|
115 | printf("Should be 30 -32 333 64\n");
|
---|
116 | }
|
---|
117 | else failed_already=1;
|
---|
118 | }
|
---|
119 | if(failed_already)
|
---|
120 | {
|
---|
121 | printf("FAILED\n");
|
---|
122 | return 1;
|
---|
123 | }
|
---|
124 | else
|
---|
125 | {
|
---|
126 | printf("PASSED\n");
|
---|
127 | return 0;
|
---|
128 | }
|
---|
129 | }
|
---|