|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * File: prftest.c |
|
8 * Description: |
|
9 * This is a simple test of the PR_snprintf() function defined |
|
10 * in prprf.c. |
|
11 */ |
|
12 |
|
13 #include "prlong.h" |
|
14 #include "prprf.h" |
|
15 |
|
16 #include <string.h> |
|
17 |
|
18 #define BUF_SIZE 128 |
|
19 |
|
20 int main(int argc, char **argv) |
|
21 { |
|
22 PRInt16 i16; |
|
23 PRIntn n; |
|
24 PRInt32 i32; |
|
25 PRInt64 i64; |
|
26 char buf[BUF_SIZE]; |
|
27 char answer[BUF_SIZE]; |
|
28 int i, rv = 0; |
|
29 |
|
30 i16 = -1; |
|
31 n = -1; |
|
32 i32 = -1; |
|
33 LL_I2L(i64, i32); |
|
34 |
|
35 PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64); |
|
36 strcpy(answer, "ffff "); |
|
37 for (i = PR_BYTES_PER_INT * 2; i; i--) { |
|
38 strcat(answer, "f"); |
|
39 } |
|
40 strcat(answer, " ffffffff ffffffffffffffff"); |
|
41 |
|
42 if (!strcmp(buf, answer)) { |
|
43 printf("PR_snprintf test 1 passed\n"); |
|
44 } else { |
|
45 printf("PR_snprintf test 1 failed\n"); |
|
46 printf("Converted string is %s\n", buf); |
|
47 printf("Should be %s\n", answer); |
|
48 rv = 1; |
|
49 } |
|
50 |
|
51 i16 = -32; |
|
52 n = 30; |
|
53 i32 = 64; |
|
54 LL_I2L(i64, 333); |
|
55 PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32); |
|
56 if (!strcmp(buf, "30 -32 333 64")) { |
|
57 printf("PR_snprintf test 2 passed\n"); |
|
58 } else { |
|
59 printf("PR_snprintf test 2 failed\n"); |
|
60 printf("Converted string is %s\n", buf); |
|
61 printf("Should be 30 -32 333 64\n"); |
|
62 rv = 1; |
|
63 } |
|
64 |
|
65 return rv; |
|
66 } |