nsprpub/pr/tests/prftest.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/prftest.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * File:	prftest.c
    1.11 + * Description:
    1.12 + *     This is a simple test of the PR_snprintf() function defined
    1.13 + *     in prprf.c.
    1.14 + */
    1.15 +
    1.16 +#include "prlong.h"
    1.17 +#include "prprf.h"
    1.18 +
    1.19 +#include <string.h>
    1.20 +
    1.21 +#define BUF_SIZE 128
    1.22 +
    1.23 +int main(int argc, char **argv)
    1.24 +{
    1.25 +    PRInt16 i16;
    1.26 +    PRIntn n;
    1.27 +    PRInt32 i32;
    1.28 +    PRInt64 i64;
    1.29 +    char buf[BUF_SIZE];
    1.30 +    char answer[BUF_SIZE];
    1.31 +    int i, rv = 0;
    1.32 +
    1.33 +    i16 = -1;
    1.34 +    n = -1;
    1.35 +    i32 = -1;
    1.36 +    LL_I2L(i64, i32);
    1.37 +
    1.38 +    PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64);
    1.39 +    strcpy(answer, "ffff ");
    1.40 +    for (i = PR_BYTES_PER_INT * 2; i; i--) {
    1.41 +		strcat(answer, "f");
    1.42 +    }
    1.43 +    strcat(answer, " ffffffff ffffffffffffffff");
    1.44 +
    1.45 +    if (!strcmp(buf, answer)) {
    1.46 +		printf("PR_snprintf test 1 passed\n");
    1.47 +    } else {
    1.48 +		printf("PR_snprintf test 1 failed\n");
    1.49 +		printf("Converted string is %s\n", buf);
    1.50 +		printf("Should be %s\n", answer);
    1.51 +		rv = 1;
    1.52 +    }
    1.53 +
    1.54 +    i16 = -32;
    1.55 +    n = 30;
    1.56 +    i32 = 64;
    1.57 +    LL_I2L(i64, 333);
    1.58 +    PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32);
    1.59 +    if (!strcmp(buf, "30 -32 333 64")) {
    1.60 +		printf("PR_snprintf test 2 passed\n");
    1.61 +    } else {
    1.62 +		printf("PR_snprintf test 2 failed\n");
    1.63 +		printf("Converted string is %s\n", buf);
    1.64 +		printf("Should be 30 -32 333 64\n");
    1.65 +		rv = 1;
    1.66 +    }
    1.67 +
    1.68 +    return rv;
    1.69 +}

mercurial