home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / prftest2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.3 KB  |  111 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:    prftest2.c
  21. ** Description:
  22. **     This is a simple test of the PR_snprintf() function defined
  23. **     in prprf.c.
  24. **
  25. ** Modification History:
  26. ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
  27. **             The debug mode will print all of the printfs associated with this test.
  28. **             The regress mode will be the default mode. Since the regress tool limits
  29. **           the output to a one line status:PASS or FAIL,all of the printf statements
  30. **             have been handled with an if (debug_mode) statement.
  31. ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
  32. **            recognize the return code from tha main program.
  33. ***********************************************************************/
  34. /***********************************************************************
  35. ** Includes
  36. ***********************************************************************/
  37. /* Used to get the command line option */
  38. #include "plgetopt.h"
  39.  
  40. #include "prlong.h"
  41. #include "prinit.h"
  42. #include "prprf.h"
  43.  
  44. #include <string.h>
  45.  
  46. #define BUF_SIZE 128
  47.  
  48. PRIntn failed_already=0;
  49. PRIntn debug_mode;
  50.  
  51. int main(    int     argc,    char   *argv[])
  52. {
  53.     PRInt16 i16;
  54.     PRIntn n;
  55.     PRInt32 i32;
  56.     PRInt64 i64;
  57.     char buf[BUF_SIZE];
  58.  
  59.     /* The command line argument: -d is used to determine if the test is being run
  60.     in debug mode. The regress tool requires only one line output:PASS or FAIL.
  61.     All of the printfs associated with this test has been handled with a if (debug_mode)
  62.     test.
  63.     Usage: test_name -d
  64.     */
  65.     PLOptStatus os;
  66.     PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
  67.     while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
  68.     {
  69.         if (PL_OPT_BAD == os) continue;
  70.         switch (opt->option)
  71.         {
  72.         case 'd':  /* debug mode */
  73.             debug_mode = 1;
  74.             break;
  75.          default:
  76.             break;
  77.         }
  78.     }
  79.     PL_DestroyOptState(opt);
  80.  
  81.     /* main test */
  82.     
  83.  
  84.     PR_STDIO_INIT();
  85.     i16 = -32;
  86.     n = 30;
  87.     i32 = 64;
  88.     LL_I2L(i64, 333);
  89.     PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32);
  90.     if (!strcmp(buf, "30 -32 333 64")) {
  91.         if (debug_mode) printf("PR_snprintf test 2 passed\n");
  92.     } else {
  93.         if (debug_mode) {
  94.             printf("PR_snprintf test 2 failed\n");
  95.             printf("Converted string is %s\n", buf);
  96.             printf("Should be 30 -32 333 64\n");
  97.         }
  98.         else failed_already=1;
  99.     }
  100.     if(failed_already)
  101.     {
  102.         printf("FAILED\n");
  103.         return 1;
  104.     }
  105.     else
  106.     {
  107.         printf("PASSED\n");
  108.         return 1;
  109.     }
  110. }
  111.