Back to index

lightning-sunbird  0.9+nobinonly
prftest.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:      prftest.c
00040  * Description:
00041  *     This is a simple test of the PR_snprintf() function defined
00042  *     in prprf.c.
00043  */
00044 
00045 #include "prlong.h"
00046 #include "prprf.h"
00047 
00048 #include <string.h>
00049 
00050 #define BUF_SIZE 128
00051 
00052 int main() {
00053     PRInt16 i16;
00054     PRIntn n;
00055     PRInt32 i32;
00056     PRInt64 i64;
00057     char buf[BUF_SIZE];
00058     char answer[BUF_SIZE];
00059     int i, rv = 0;
00060 
00061     i16 = -1;
00062     n = -1;
00063     i32 = -1;
00064     LL_I2L(i64, i32);
00065 
00066     PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64);
00067     strcpy(answer, "ffff ");
00068     for (i = PR_BYTES_PER_INT * 2; i; i--) {
00069               strcat(answer, "f");
00070     }
00071     strcat(answer, " ffffffff ffffffffffffffff");
00072 
00073     if (!strcmp(buf, answer)) {
00074               printf("PR_snprintf test 1 passed\n");
00075     } else {
00076               printf("PR_snprintf test 1 failed\n");
00077               printf("Converted string is %s\n", buf);
00078               printf("Should be %s\n", answer);
00079               rv = 1;
00080     }
00081 
00082     i16 = -32;
00083     n = 30;
00084     i32 = 64;
00085     LL_I2L(i64, 333);
00086     PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32);
00087     if (!strcmp(buf, "30 -32 333 64")) {
00088               printf("PR_snprintf test 2 passed\n");
00089     } else {
00090               printf("PR_snprintf test 2 failed\n");
00091               printf("Converted string is %s\n", buf);
00092               printf("Should be 30 -32 333 64\n");
00093               rv = 1;
00094     }
00095 
00096     return rv;
00097 }