Back to index

lightning-sunbird  0.9+nobinonly
prftest2.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:      prftest2.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 ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
00051 **                   recognize the return code from tha main program.
00052 ***********************************************************************/
00053 /***********************************************************************
00054 ** Includes
00055 ***********************************************************************/
00056 /* Used to get the command line option */
00057 #include "plgetopt.h"
00058 
00059 #include "prlong.h"
00060 #include "prinit.h"
00061 #include "prprf.h"
00062 
00063 #include <string.h>
00064 
00065 #define BUF_SIZE 128
00066 
00067 PRIntn failed_already=0;
00068 PRIntn debug_mode;
00069 
00070 int main(    int     argc,    char   *argv[])
00071 {
00072     PRInt16 i16;
00073     PRIntn n;
00074     PRInt32 i32;
00075     PRInt64 i64;
00076     char buf[BUF_SIZE];
00077 
00078        /* The command line argument: -d is used to determine if the test is being run
00079        in debug mode. The regress tool requires only one line output:PASS or FAIL.
00080        All of the printfs associated with this test has been handled with a if (debug_mode)
00081        test.
00082        Usage: test_name -d
00083        */
00084        PLOptStatus os;
00085        PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
00086        while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
00087     {
00088               if (PL_OPT_BAD == os) continue;
00089         switch (opt->option)
00090         {
00091         case 'd':  /* debug mode */
00092                      debug_mode = 1;
00093             break;
00094          default:
00095             break;
00096         }
00097     }
00098        PL_DestroyOptState(opt);
00099 
00100        /* main test */
00101        
00102 
00103     PR_STDIO_INIT();
00104     i16 = -32;
00105     n = 30;
00106     i32 = 64;
00107     LL_I2L(i64, 333);
00108     PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32);
00109     if (!strcmp(buf, "30 -32 333 64")) {
00110               if (debug_mode) printf("PR_snprintf test 2 passed\n");
00111     } else {
00112               if (debug_mode) {
00113                      printf("PR_snprintf test 2 failed\n");
00114                      printf("Converted string is %s\n", buf);
00115                      printf("Should be 30 -32 333 64\n");
00116               }
00117               else failed_already=1;
00118     }
00119        if(failed_already)
00120        {
00121         printf("FAILED\n");
00122               return 1;
00123        }
00124        else
00125        {
00126         printf("PASSED\n");
00127               return 0;
00128        }
00129 }