Back to index

lightning-sunbird  0.9+nobinonly
prftest1.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039 ** File:      prftest1.c
00040 ** Description:
00041 **     This is a simple test of the PR_snprintf() function defined
00042 **     in prprf.c.
00043 **
00044 ** Modification History:
00045 ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
00046 **              The debug mode will print all of the printfs associated with this test.
00047 **                    The regress mode will be the default mode. Since the regress tool limits
00048 **           the output to a one line status:PASS or FAIL,all of the printf statements
00049 **                    have been handled with an if (debug_mode) statement. 
00050 ***********************************************************************/
00051 /***********************************************************************
00052 ** Includes
00053 ***********************************************************************/
00054 /* Used to get the command line option */
00055 #include "plgetopt.h"
00056 #include "prttools.h"
00057 
00058 #include "prinit.h"
00059 #include "prlong.h"
00060 #include "prprf.h"
00061 
00062 #include <string.h>
00063 
00064 #define BUF_SIZE 128
00065 
00066 /***********************************************************************
00067 ** PRIVATE FUNCTION:    Test_Result
00068 ** DESCRIPTION: Used in conjunction with the regress tool, prints out the
00069 **                          status of the test case.
00070 ** INPUTS:      PASS/FAIL
00071 ** OUTPUTS:     None
00072 ** RETURN:      None
00073 ** SIDE EFFECTS:
00074 **      
00075 ** RESTRICTIONS:
00076 **      None
00077 ** MEMORY:      NA
00078 ** ALGORITHM:   Determine what the status is and print accordingly.
00079 **      
00080 ***********************************************************************/
00081 
00082 
00083 static void Test_Result (int result)
00084 {
00085        if (result == PASS)
00086               printf ("PASS\n");
00087        else
00088               printf ("FAIL\n");
00089 }
00090 
00091 int main(    int     argc,    char   *argv[])
00092 {
00093     PRInt16 i16;
00094     PRIntn n;
00095     PRInt32 i32;
00096     PRInt64 i64;
00097     char buf[BUF_SIZE];
00098     char answer[BUF_SIZE];
00099     int i;
00100 
00101        /* The command line argument: -d is used to determine if the test is being run
00102        in debug mode. The regress tool requires only one line output:PASS or FAIL.
00103        All of the printfs associated with this test has been handled with a if (debug_mode)
00104        test.
00105        Usage: test_name -d
00106        */
00107        PLOptStatus os;
00108        PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
00109        while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
00110     {
00111               if (PL_OPT_BAD == os) continue;
00112         switch (opt->option)
00113         {
00114         case 'd':  /* debug mode */
00115                      debug_mode = 1;
00116             break;
00117          default:
00118             break;
00119         }
00120     }
00121        PL_DestroyOptState(opt);
00122 
00123        /* main test */
00124     PR_STDIO_INIT();
00125        
00126     i16 = -1;
00127     n = -1;
00128     i32 = -1;
00129     LL_I2L(i64, i32);
00130 
00131     PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64);
00132     strcpy(answer, "ffff ");
00133     for (i = PR_BYTES_PER_INT * 2; i; i--) {
00134        strcat(answer, "f");
00135     }
00136     strcat(answer, " ffffffff ffffffffffffffff");
00137 
00138     if (!strcmp(buf, answer)) {
00139        if (debug_mode) printf("PR_snprintf test 1 passed\n");
00140        else Test_Result (PASS);
00141     } else {
00142               if (debug_mode) {
00143                      printf("PR_snprintf test 1 failed\n");
00144                      printf("Converted string is %s\n", buf);
00145                      printf("Should be %s\n", answer);
00146               }
00147               else
00148                      Test_Result (FAIL);
00149     }
00150 
00151     return 0;
00152 }