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/. */
9 ** This is a simple test of the PR_snprintf() function defined
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 ***********************************************************************/
19 /***********************************************************************
21 ***********************************************************************/
22 /* Used to get the command line option */
34 /***********************************************************************
35 ** PRIVATE FUNCTION: Test_Result
36 ** DESCRIPTION: Used in conjunction with the regress tool, prints out the
37 ** status of the test case.
46 ** ALGORITHM: Determine what the status is and print accordingly.
48 ***********************************************************************/
51 static void Test_Result (int result)
59 int main(int argc, char **argv)
66 char answer[BUF_SIZE];
69 /* The command line argument: -d is used to determine if the test is being run
70 in debug mode. The regress tool requires only one line output:PASS or FAIL.
71 All of the printfs associated with this test has been handled with a if (debug_mode)
76 PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
77 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
79 if (PL_OPT_BAD == os) continue;
82 case 'd': /* debug mode */
89 PL_DestroyOptState(opt);
99 PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64);
100 strcpy(answer, "ffff ");
101 for (i = PR_BYTES_PER_INT * 2; i; i--) {
104 strcat(answer, " ffffffff ffffffffffffffff");
106 if (!strcmp(buf, answer)) {
107 if (debug_mode) printf("PR_snprintf test 1 passed\n");
108 else Test_Result (PASS);
111 printf("PR_snprintf test 1 failed\n");
112 printf("Converted string is %s\n", buf);
113 printf("Should be %s\n", answer);