~ubuntu-branches/ubuntu/gutsy/virtualbox-ose/gutsy

« back to all changes in this revision

Viewing changes to src/libs/xpcom18a4/nsprpub/pr/tests/prftest1.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-09-08 16:44:58 UTC
  • Revision ID: james.westby@ubuntu.com-20070908164458-wao29470vqtr8ksy
Tags: upstream-1.5.0-dfsg2
ImportĀ upstreamĀ versionĀ 1.5.0-dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Mozilla Public License Version
 
6
 * 1.1 (the "License"); you may not use this file except in compliance with
 
7
 * the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/MPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is the Netscape Portable Runtime (NSPR).
 
16
 *
 
17
 * The Initial Developer of the Original Code is
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 1998-2000
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 * Alternatively, the contents of this file may be used under the terms of
 
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
28
 * of those above. If you wish to allow use of your version of this file only
 
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
30
 * use your version of this file under the terms of the MPL, indicate your
 
31
 * decision by deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
33
 * the provisions above, a recipient may use your version of this file under
 
34
 * the terms of any one of the MPL, the GPL or the LGPL.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
/*
 
39
** File:        prftest1.c
 
40
** Description:
 
41
**     This is a simple test of the PR_snprintf() function defined
 
42
**     in prprf.c.
 
43
**
 
44
** Modification History:
 
45
** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
 
46
**               The debug mode will print all of the printfs associated with this test.
 
47
**                       The regress mode will be the default mode. Since the regress tool limits
 
48
**           the output to a one line status:PASS or FAIL,all of the printf statements
 
49
**                       have been handled with an if (debug_mode) statement. 
 
50
***********************************************************************/
 
51
/***********************************************************************
 
52
** Includes
 
53
***********************************************************************/
 
54
/* Used to get the command line option */
 
55
#include "plgetopt.h"
 
56
#include "prttools.h"
 
57
 
 
58
#include "prinit.h"
 
59
#include "prlong.h"
 
60
#include "prprf.h"
 
61
 
 
62
#include <string.h>
 
63
 
 
64
#define BUF_SIZE 128
 
65
 
 
66
/***********************************************************************
 
67
** PRIVATE FUNCTION:    Test_Result
 
68
** DESCRIPTION: Used in conjunction with the regress tool, prints out the
 
69
**                              status of the test case.
 
70
** INPUTS:      PASS/FAIL
 
71
** OUTPUTS:     None
 
72
** RETURN:      None
 
73
** SIDE EFFECTS:
 
74
**      
 
75
** RESTRICTIONS:
 
76
**      None
 
77
** MEMORY:      NA
 
78
** ALGORITHM:   Determine what the status is and print accordingly.
 
79
**      
 
80
***********************************************************************/
 
81
 
 
82
 
 
83
static void Test_Result (int result)
 
84
{
 
85
        if (result == PASS)
 
86
                printf ("PASS\n");
 
87
        else
 
88
                printf ("FAIL\n");
 
89
}
 
90
 
 
91
int main(    int     argc,    char   *argv[])
 
92
{
 
93
    PRInt16 i16;
 
94
    PRIntn n;
 
95
    PRInt32 i32;
 
96
    PRInt64 i64;
 
97
    char buf[BUF_SIZE];
 
98
    char answer[BUF_SIZE];
 
99
    int i;
 
100
 
 
101
        /* The command line argument: -d is used to determine if the test is being run
 
102
        in debug mode. The regress tool requires only one line output:PASS or FAIL.
 
103
        All of the printfs associated with this test has been handled with a if (debug_mode)
 
104
        test.
 
105
        Usage: test_name -d
 
106
        */
 
107
        PLOptStatus os;
 
108
        PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
 
109
        while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
 
110
    {
 
111
                if (PL_OPT_BAD == os) continue;
 
112
        switch (opt->option)
 
113
        {
 
114
        case 'd':  /* debug mode */
 
115
                        debug_mode = 1;
 
116
            break;
 
117
         default:
 
118
            break;
 
119
        }
 
120
    }
 
121
        PL_DestroyOptState(opt);
 
122
 
 
123
        /* main test */
 
124
    PR_STDIO_INIT();
 
125
        
 
126
    i16 = -1;
 
127
    n = -1;
 
128
    i32 = -1;
 
129
    LL_I2L(i64, i32);
 
130
 
 
131
    PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64);
 
132
    strcpy(answer, "ffff ");
 
133
    for (i = PR_BYTES_PER_INT * 2; i; i--) {
 
134
        strcat(answer, "f");
 
135
    }
 
136
    strcat(answer, " ffffffff ffffffffffffffff");
 
137
 
 
138
    if (!strcmp(buf, answer)) {
 
139
        if (debug_mode) printf("PR_snprintf test 1 passed\n");
 
140
        else Test_Result (PASS);
 
141
    } else {
 
142
                if (debug_mode) {
 
143
                        printf("PR_snprintf test 1 failed\n");
 
144
                        printf("Converted string is %s\n", buf);
 
145
                        printf("Should be %s\n", answer);
 
146
                }
 
147
                else
 
148
                        Test_Result (FAIL);
 
149
    }
 
150
 
 
151
    return 0;
 
152
}