home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / prftest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.0 KB  |  78 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20.  * File:    prftest.c
  21.  * Description:
  22.  *     This is a simple test of the PR_snprintf() function defined
  23.  *     in prprf.c.
  24.  */
  25.  
  26. #include "prlong.h"
  27. #include "prprf.h"
  28.  
  29. #include <string.h>
  30.  
  31. #define BUF_SIZE 128
  32.  
  33. int main() {
  34.     PRInt16 i16;
  35.     PRIntn n;
  36.     PRInt32 i32;
  37.     PRInt64 i64;
  38.     char buf[BUF_SIZE];
  39.     char answer[BUF_SIZE];
  40.     int i;
  41.  
  42.     PR_STDIO_INIT();
  43.     i16 = -1;
  44.     n = -1;
  45.     i32 = -1;
  46.     LL_I2L(i64, i32);
  47.  
  48.     PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64);
  49.     strcpy(answer, "ffff ");
  50.     for (i = PR_BYTES_PER_INT * 2; i; i--) {
  51.     strcat(answer, "f");
  52.     }
  53.     strcat(answer, " ffffffff ffffffffffffffff");
  54.  
  55.     if (!strcmp(buf, answer)) {
  56.     printf("PR_snprintf test 1 passed\n");
  57.     } else {
  58.     printf("PR_snprintf test 1 failed\n");
  59.     printf("Converted string is %s\n", buf);
  60.     printf("Should be %s\n", answer);
  61.     }
  62.  
  63.     i16 = -32;
  64.     n = 30;
  65.     i32 = 64;
  66.     LL_I2L(i64, 333);
  67.     PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32);
  68.     if (!strcmp(buf, "30 -32 333 64")) {
  69.     printf("PR_snprintf test 2 passed\n");
  70.     } else {
  71.     printf("PR_snprintf test 2 failed\n");
  72.     printf("Converted string is %s\n", buf);
  73.     printf("Should be 30 -32 333 64\n");
  74.     }
  75.  
  76.     return 0;
  77. }
  78.