home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / prftest1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.8 KB  |  134 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:    prftest1.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. ***********************************************************************/
  32. /***********************************************************************
  33. ** Includes
  34. ***********************************************************************/
  35. /* Used to get the command line option */
  36. #include "plgetopt.h"
  37. #include "prttools.h"
  38.  
  39. #include "prinit.h"
  40. #include "prlong.h"
  41. #include "prprf.h"
  42.  
  43. #include <string.h>
  44.  
  45. #define BUF_SIZE 128
  46.  
  47. /***********************************************************************
  48. ** PRIVATE FUNCTION:    Test_Result
  49. ** DESCRIPTION: Used in conjunction with the regress tool, prints out the
  50. **                status of the test case.
  51. ** INPUTS:      PASS/FAIL
  52. ** OUTPUTS:     None
  53. ** RETURN:      None
  54. ** SIDE EFFECTS:
  55. **      
  56. ** RESTRICTIONS:
  57. **      None
  58. ** MEMORY:      NA
  59. ** ALGORITHM:   Determine what the status is and print accordingly.
  60. **      
  61. ***********************************************************************/
  62.  
  63.  
  64. static void Test_Result (int result)
  65. {
  66.     if (result == PASS)
  67.         printf ("PASS\n");
  68.     else
  69.         printf ("FAIL\n");
  70. }
  71.  
  72. int main(    int     argc,    char   *argv[])
  73. {
  74.     PRInt16 i16;
  75.     PRIntn n;
  76.     PRInt32 i32;
  77.     PRInt64 i64;
  78.     char buf[BUF_SIZE];
  79.     char answer[BUF_SIZE];
  80.     int i;
  81.  
  82.     /* The command line argument: -d is used to determine if the test is being run
  83.     in debug mode. The regress tool requires only one line output:PASS or FAIL.
  84.     All of the printfs associated with this test has been handled with a if (debug_mode)
  85.     test.
  86.     Usage: test_name -d
  87.     */
  88.     PLOptStatus os;
  89.     PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
  90.     while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
  91.     {
  92.         if (PL_OPT_BAD == os) continue;
  93.         switch (opt->option)
  94.         {
  95.         case 'd':  /* debug mode */
  96.             debug_mode = 1;
  97.             break;
  98.          default:
  99.             break;
  100.         }
  101.     }
  102.     PL_DestroyOptState(opt);
  103.  
  104.     /* main test */
  105.     PR_STDIO_INIT();
  106.     
  107.     i16 = -1;
  108.     n = -1;
  109.     i32 = -1;
  110.     LL_I2L(i64, i32);
  111.  
  112.     PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64);
  113.     strcpy(answer, "ffff ");
  114.     for (i = PR_BYTES_PER_INT * 2; i; i--) {
  115.     strcat(answer, "f");
  116.     }
  117.     strcat(answer, " ffffffff ffffffffffffffff");
  118.  
  119.     if (!strcmp(buf, answer)) {
  120.     if (debug_mode) printf("PR_snprintf test 1 passed\n");
  121.     else Test_Result (PASS);
  122.     } else {
  123.         if (debug_mode) {
  124.             printf("PR_snprintf test 1 failed\n");
  125.             printf("Converted string is %s\n", buf);
  126.             printf("Should be %s\n", answer);
  127.         }
  128.         else
  129.             Test_Result (FAIL);
  130.     }
  131.  
  132.     return 0;
  133. }
  134.