tor-browser

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

prftest.c (1530B)


      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:    prftest.c
      8 * Description:
      9 *     This is a simple test of the PR_snprintf() function defined
     10 *     in prprf.c.
     11 */
     12 
     13 #include "prlong.h"
     14 #include "prprf.h"
     15 
     16 #include <string.h>
     17 
     18 #define BUF_SIZE 128
     19 
     20 int main(int argc, char** argv) {
     21  PRInt16 i16;
     22  PRIntn n;
     23  PRInt32 i32;
     24  PRInt64 i64;
     25  char buf[BUF_SIZE];
     26  char answer[BUF_SIZE];
     27  int i, rv = 0;
     28 
     29  i16 = -1;
     30  n = -1;
     31  i32 = -1;
     32  LL_I2L(i64, i32);
     33 
     34  PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64);
     35  strcpy(answer, "ffff ");
     36  for (i = PR_BYTES_PER_INT * 2; i; i--) {
     37    strcat(answer, "f");
     38  }
     39  strcat(answer, " ffffffff ffffffffffffffff");
     40 
     41  if (!strcmp(buf, answer)) {
     42    printf("PR_snprintf test 1 passed\n");
     43  } else {
     44    printf("PR_snprintf test 1 failed\n");
     45    printf("Converted string is %s\n", buf);
     46    printf("Should be %s\n", answer);
     47    rv = 1;
     48  }
     49 
     50  i16 = -32;
     51  n = 30;
     52  i32 = 64;
     53  LL_I2L(i64, 333);
     54  PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32);
     55  if (!strcmp(buf, "30 -32 333 64")) {
     56    printf("PR_snprintf test 2 passed\n");
     57  } else {
     58    printf("PR_snprintf test 2 failed\n");
     59    printf("Converted string is %s\n", buf);
     60    printf("Should be 30 -32 333 64\n");
     61    rv = 1;
     62  }
     63 
     64  return rv;
     65 }