nsprpub/pr/tests/formattm.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/formattm.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     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 +/* A test program for PR_FormatTime and PR_FormatTimeUSEnglish */
    1.10 +
    1.11 +#include "prtime.h"
    1.12 +
    1.13 +#include <stdio.h>
    1.14 +
    1.15 +int main(int argc, char **argv)
    1.16 +{
    1.17 +    char buffer[256];
    1.18 +    char small_buffer[8];
    1.19 +    PRTime now;
    1.20 +    PRExplodedTime tod;
    1.21 +
    1.22 +    now = PR_Now();
    1.23 +    PR_ExplodeTime(now, PR_LocalTimeParameters, &tod);
    1.24 +
    1.25 +    if (PR_FormatTime(buffer, sizeof(buffer),
    1.26 +            "%a %b %d %H:%M:%S %Z %Y", &tod) != 0) {
    1.27 +        printf("%s\n", buffer);
    1.28 +    } else {
    1.29 +        fprintf(stderr, "PR_FormatTime(buffer) failed\n");
    1.30 +        return 1;
    1.31 +    }
    1.32 +
    1.33 +    small_buffer[0] = '?';
    1.34 +    if (PR_FormatTime(small_buffer, sizeof(small_buffer),
    1.35 +            "%a %b %d %H:%M:%S %Z %Y", &tod) == 0) {
    1.36 +        if (small_buffer[0] != '\0') {
    1.37 +            fprintf(stderr, "PR_FormatTime(small_buffer) did not output "
    1.38 +                            "an empty string on failure\n");
    1.39 +            return 1;
    1.40 +        }
    1.41 +        printf("%s\n", small_buffer);
    1.42 +    } else {
    1.43 +        fprintf(stderr, "PR_FormatTime(small_buffer) succeeded "
    1.44 +                        "unexpectedly\n");
    1.45 +        return 1;
    1.46 +    }
    1.47 +
    1.48 +    (void)PR_FormatTimeUSEnglish(buffer, sizeof(buffer),
    1.49 +        "%a %b %d %H:%M:%S %Z %Y", &tod);
    1.50 +    printf("%s\n", buffer);
    1.51 +
    1.52 +    return 0;
    1.53 +}

mercurial