Wed, 31 Dec 2014 07:53:36 +0100
Correct small whitespace inconsistency, lost while renaming variables.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | ** File: prftest2.c |
michael@0 | 8 | ** Description: |
michael@0 | 9 | ** This is a simple test of the PR_snprintf() function defined |
michael@0 | 10 | ** in prprf.c. |
michael@0 | 11 | ** |
michael@0 | 12 | ** Modification History: |
michael@0 | 13 | ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag. |
michael@0 | 14 | ** The debug mode will print all of the printfs associated with this test. |
michael@0 | 15 | ** The regress mode will be the default mode. Since the regress tool limits |
michael@0 | 16 | ** the output to a one line status:PASS or FAIL,all of the printf statements |
michael@0 | 17 | ** have been handled with an if (debug_mode) statement. |
michael@0 | 18 | ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to |
michael@0 | 19 | ** recognize the return code from tha main program. |
michael@0 | 20 | ***********************************************************************/ |
michael@0 | 21 | /*********************************************************************** |
michael@0 | 22 | ** Includes |
michael@0 | 23 | ***********************************************************************/ |
michael@0 | 24 | /* Used to get the command line option */ |
michael@0 | 25 | #include "plgetopt.h" |
michael@0 | 26 | |
michael@0 | 27 | #include "prlong.h" |
michael@0 | 28 | #include "prinit.h" |
michael@0 | 29 | #include "prprf.h" |
michael@0 | 30 | |
michael@0 | 31 | #include <string.h> |
michael@0 | 32 | |
michael@0 | 33 | #define BUF_SIZE 128 |
michael@0 | 34 | |
michael@0 | 35 | PRIntn failed_already=0; |
michael@0 | 36 | PRIntn debug_mode; |
michael@0 | 37 | |
michael@0 | 38 | int main(int argc, char **argv) |
michael@0 | 39 | { |
michael@0 | 40 | PRInt16 i16; |
michael@0 | 41 | PRIntn n; |
michael@0 | 42 | PRInt32 i32; |
michael@0 | 43 | PRInt64 i64; |
michael@0 | 44 | char buf[BUF_SIZE]; |
michael@0 | 45 | |
michael@0 | 46 | /* The command line argument: -d is used to determine if the test is being run |
michael@0 | 47 | in debug mode. The regress tool requires only one line output:PASS or FAIL. |
michael@0 | 48 | All of the printfs associated with this test has been handled with a if (debug_mode) |
michael@0 | 49 | test. |
michael@0 | 50 | Usage: test_name -d |
michael@0 | 51 | */ |
michael@0 | 52 | PLOptStatus os; |
michael@0 | 53 | PLOptState *opt = PL_CreateOptState(argc, argv, "d:"); |
michael@0 | 54 | while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) |
michael@0 | 55 | { |
michael@0 | 56 | if (PL_OPT_BAD == os) continue; |
michael@0 | 57 | switch (opt->option) |
michael@0 | 58 | { |
michael@0 | 59 | case 'd': /* debug mode */ |
michael@0 | 60 | debug_mode = 1; |
michael@0 | 61 | break; |
michael@0 | 62 | default: |
michael@0 | 63 | break; |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | PL_DestroyOptState(opt); |
michael@0 | 67 | |
michael@0 | 68 | /* main test */ |
michael@0 | 69 | |
michael@0 | 70 | |
michael@0 | 71 | PR_STDIO_INIT(); |
michael@0 | 72 | i16 = -32; |
michael@0 | 73 | n = 30; |
michael@0 | 74 | i32 = 64; |
michael@0 | 75 | LL_I2L(i64, 333); |
michael@0 | 76 | PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32); |
michael@0 | 77 | if (!strcmp(buf, "30 -32 333 64")) { |
michael@0 | 78 | if (debug_mode) printf("PR_snprintf test 2 passed\n"); |
michael@0 | 79 | } else { |
michael@0 | 80 | if (debug_mode) { |
michael@0 | 81 | printf("PR_snprintf test 2 failed\n"); |
michael@0 | 82 | printf("Converted string is %s\n", buf); |
michael@0 | 83 | printf("Should be 30 -32 333 64\n"); |
michael@0 | 84 | } |
michael@0 | 85 | else failed_already=1; |
michael@0 | 86 | } |
michael@0 | 87 | if(failed_already) |
michael@0 | 88 | { |
michael@0 | 89 | printf("FAILED\n"); |
michael@0 | 90 | return 1; |
michael@0 | 91 | } |
michael@0 | 92 | else |
michael@0 | 93 | { |
michael@0 | 94 | printf("PASSED\n"); |
michael@0 | 95 | return 0; |
michael@0 | 96 | } |
michael@0 | 97 | } |