michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** File: prftest1.c michael@0: ** Description: michael@0: ** This is a simple test of the PR_snprintf() function defined michael@0: ** in prprf.c. michael@0: ** michael@0: ** Modification History: michael@0: ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag. michael@0: ** The debug mode will print all of the printfs associated with this test. michael@0: ** The regress mode will be the default mode. Since the regress tool limits michael@0: ** the output to a one line status:PASS or FAIL,all of the printf statements michael@0: ** have been handled with an if (debug_mode) statement. michael@0: ***********************************************************************/ michael@0: /*********************************************************************** michael@0: ** Includes michael@0: ***********************************************************************/ michael@0: /* Used to get the command line option */ michael@0: #include "plgetopt.h" michael@0: #include "prttools.h" michael@0: michael@0: #include "prinit.h" michael@0: #include "prlong.h" michael@0: #include "prprf.h" michael@0: michael@0: #include michael@0: michael@0: #define BUF_SIZE 128 michael@0: michael@0: /*********************************************************************** michael@0: ** PRIVATE FUNCTION: Test_Result michael@0: ** DESCRIPTION: Used in conjunction with the regress tool, prints out the michael@0: ** status of the test case. michael@0: ** INPUTS: PASS/FAIL michael@0: ** OUTPUTS: None michael@0: ** RETURN: None michael@0: ** SIDE EFFECTS: michael@0: ** michael@0: ** RESTRICTIONS: michael@0: ** None michael@0: ** MEMORY: NA michael@0: ** ALGORITHM: Determine what the status is and print accordingly. michael@0: ** michael@0: ***********************************************************************/ michael@0: michael@0: michael@0: static void Test_Result (int result) michael@0: { michael@0: if (result == PASS) michael@0: printf ("PASS\n"); michael@0: else michael@0: printf ("FAIL\n"); michael@0: } michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PRInt16 i16; michael@0: PRIntn n; michael@0: PRInt32 i32; michael@0: PRInt64 i64; michael@0: char buf[BUF_SIZE]; michael@0: char answer[BUF_SIZE]; michael@0: int i; michael@0: michael@0: /* The command line argument: -d is used to determine if the test is being run michael@0: in debug mode. The regress tool requires only one line output:PASS or FAIL. michael@0: All of the printfs associated with this test has been handled with a if (debug_mode) michael@0: test. michael@0: Usage: test_name -d michael@0: */ michael@0: PLOptStatus os; michael@0: PLOptState *opt = PL_CreateOptState(argc, argv, "d:"); michael@0: while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) michael@0: { michael@0: if (PL_OPT_BAD == os) continue; michael@0: switch (opt->option) michael@0: { michael@0: case 'd': /* debug mode */ michael@0: debug_mode = 1; michael@0: break; michael@0: default: michael@0: break; michael@0: } michael@0: } michael@0: PL_DestroyOptState(opt); michael@0: michael@0: /* main test */ michael@0: PR_STDIO_INIT(); michael@0: michael@0: i16 = -1; michael@0: n = -1; michael@0: i32 = -1; michael@0: LL_I2L(i64, i32); michael@0: michael@0: PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64); michael@0: strcpy(answer, "ffff "); michael@0: for (i = PR_BYTES_PER_INT * 2; i; i--) { michael@0: strcat(answer, "f"); michael@0: } michael@0: strcat(answer, " ffffffff ffffffffffffffff"); michael@0: michael@0: if (!strcmp(buf, answer)) { michael@0: if (debug_mode) printf("PR_snprintf test 1 passed\n"); michael@0: else Test_Result (PASS); michael@0: } else { michael@0: if (debug_mode) { michael@0: printf("PR_snprintf test 1 failed\n"); michael@0: printf("Converted string is %s\n", buf); michael@0: printf("Should be %s\n", answer); michael@0: } michael@0: else michael@0: Test_Result (FAIL); michael@0: } michael@0: michael@0: return 0; michael@0: }