michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * File: prftest.c michael@0: * Description: michael@0: * This is a simple test of the PR_snprintf() function defined michael@0: * in prprf.c. michael@0: */ michael@0: michael@0: #include "prlong.h" michael@0: #include "prprf.h" michael@0: michael@0: #include michael@0: michael@0: #define BUF_SIZE 128 michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PRInt16 i16; michael@0: PRIntn n; michael@0: PRInt32 i32; michael@0: PRInt64 i64; michael@0: char buf[BUF_SIZE]; michael@0: char answer[BUF_SIZE]; michael@0: int i, rv = 0; michael@0: michael@0: i16 = -1; michael@0: n = -1; michael@0: i32 = -1; michael@0: LL_I2L(i64, i32); michael@0: michael@0: PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64); michael@0: strcpy(answer, "ffff "); michael@0: for (i = PR_BYTES_PER_INT * 2; i; i--) { michael@0: strcat(answer, "f"); michael@0: } michael@0: strcat(answer, " ffffffff ffffffffffffffff"); michael@0: michael@0: if (!strcmp(buf, answer)) { michael@0: printf("PR_snprintf test 1 passed\n"); michael@0: } else { michael@0: printf("PR_snprintf test 1 failed\n"); michael@0: printf("Converted string is %s\n", buf); michael@0: printf("Should be %s\n", answer); michael@0: rv = 1; michael@0: } michael@0: michael@0: i16 = -32; michael@0: n = 30; michael@0: i32 = 64; michael@0: LL_I2L(i64, 333); michael@0: PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32); michael@0: if (!strcmp(buf, "30 -32 333 64")) { michael@0: printf("PR_snprintf test 2 passed\n"); michael@0: } else { michael@0: printf("PR_snprintf test 2 failed\n"); michael@0: printf("Converted string is %s\n", buf); michael@0: printf("Should be 30 -32 333 64\n"); michael@0: rv = 1; michael@0: } michael@0: michael@0: return rv; michael@0: }