tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

prftest1.c (3325B)


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