Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
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: prftest1.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 | ***********************************************************************/ |
michael@0 | 19 | /*********************************************************************** |
michael@0 | 20 | ** Includes |
michael@0 | 21 | ***********************************************************************/ |
michael@0 | 22 | /* Used to get the command line option */ |
michael@0 | 23 | #include "plgetopt.h" |
michael@0 | 24 | #include "prttools.h" |
michael@0 | 25 | |
michael@0 | 26 | #include "prinit.h" |
michael@0 | 27 | #include "prlong.h" |
michael@0 | 28 | #include "prprf.h" |
michael@0 | 29 | |
michael@0 | 30 | #include <string.h> |
michael@0 | 31 | |
michael@0 | 32 | #define BUF_SIZE 128 |
michael@0 | 33 | |
michael@0 | 34 | /*********************************************************************** |
michael@0 | 35 | ** PRIVATE FUNCTION: Test_Result |
michael@0 | 36 | ** DESCRIPTION: Used in conjunction with the regress tool, prints out the |
michael@0 | 37 | ** status of the test case. |
michael@0 | 38 | ** INPUTS: PASS/FAIL |
michael@0 | 39 | ** OUTPUTS: None |
michael@0 | 40 | ** RETURN: None |
michael@0 | 41 | ** SIDE EFFECTS: |
michael@0 | 42 | ** |
michael@0 | 43 | ** RESTRICTIONS: |
michael@0 | 44 | ** None |
michael@0 | 45 | ** MEMORY: NA |
michael@0 | 46 | ** ALGORITHM: Determine what the status is and print accordingly. |
michael@0 | 47 | ** |
michael@0 | 48 | ***********************************************************************/ |
michael@0 | 49 | |
michael@0 | 50 | |
michael@0 | 51 | static void Test_Result (int result) |
michael@0 | 52 | { |
michael@0 | 53 | if (result == PASS) |
michael@0 | 54 | printf ("PASS\n"); |
michael@0 | 55 | else |
michael@0 | 56 | printf ("FAIL\n"); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | int main(int argc, char **argv) |
michael@0 | 60 | { |
michael@0 | 61 | PRInt16 i16; |
michael@0 | 62 | PRIntn n; |
michael@0 | 63 | PRInt32 i32; |
michael@0 | 64 | PRInt64 i64; |
michael@0 | 65 | char buf[BUF_SIZE]; |
michael@0 | 66 | char answer[BUF_SIZE]; |
michael@0 | 67 | int i; |
michael@0 | 68 | |
michael@0 | 69 | /* The command line argument: -d is used to determine if the test is being run |
michael@0 | 70 | in debug mode. The regress tool requires only one line output:PASS or FAIL. |
michael@0 | 71 | All of the printfs associated with this test has been handled with a if (debug_mode) |
michael@0 | 72 | test. |
michael@0 | 73 | Usage: test_name -d |
michael@0 | 74 | */ |
michael@0 | 75 | PLOptStatus os; |
michael@0 | 76 | PLOptState *opt = PL_CreateOptState(argc, argv, "d:"); |
michael@0 | 77 | while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) |
michael@0 | 78 | { |
michael@0 | 79 | if (PL_OPT_BAD == os) continue; |
michael@0 | 80 | switch (opt->option) |
michael@0 | 81 | { |
michael@0 | 82 | case 'd': /* debug mode */ |
michael@0 | 83 | debug_mode = 1; |
michael@0 | 84 | break; |
michael@0 | 85 | default: |
michael@0 | 86 | break; |
michael@0 | 87 | } |
michael@0 | 88 | } |
michael@0 | 89 | PL_DestroyOptState(opt); |
michael@0 | 90 | |
michael@0 | 91 | /* main test */ |
michael@0 | 92 | PR_STDIO_INIT(); |
michael@0 | 93 | |
michael@0 | 94 | i16 = -1; |
michael@0 | 95 | n = -1; |
michael@0 | 96 | i32 = -1; |
michael@0 | 97 | LL_I2L(i64, i32); |
michael@0 | 98 | |
michael@0 | 99 | PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64); |
michael@0 | 100 | strcpy(answer, "ffff "); |
michael@0 | 101 | for (i = PR_BYTES_PER_INT * 2; i; i--) { |
michael@0 | 102 | strcat(answer, "f"); |
michael@0 | 103 | } |
michael@0 | 104 | strcat(answer, " ffffffff ffffffffffffffff"); |
michael@0 | 105 | |
michael@0 | 106 | if (!strcmp(buf, answer)) { |
michael@0 | 107 | if (debug_mode) printf("PR_snprintf test 1 passed\n"); |
michael@0 | 108 | else Test_Result (PASS); |
michael@0 | 109 | } else { |
michael@0 | 110 | if (debug_mode) { |
michael@0 | 111 | printf("PR_snprintf test 1 failed\n"); |
michael@0 | 112 | printf("Converted string is %s\n", buf); |
michael@0 | 113 | printf("Should be %s\n", answer); |
michael@0 | 114 | } |
michael@0 | 115 | else |
michael@0 | 116 | Test_Result (FAIL); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | return 0; |
michael@0 | 120 | } |