~ubuntu-branches/ubuntu/quantal/nspr/quantal-security

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/tests/parsetm.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-06-16 11:28:24 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090616112824-cg6qzhvt63lx7bub
Tags: 4.7.5-0ubuntu1
* New upstream version: 4.7.5 (LP: #387745)

* adjust patches to changed upstream code base
  - update debian/patches/99_configure.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
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
 * This test program should eventually become a full-blown test for
 
40
 * PR_ParseTimeString.  Right now it just verifies that PR_ParseTimeString
 
41
 * doesn't crash on an out-of-range time string (bug 480740).
 
42
 */
 
43
 
 
44
#include "prtime.h"
 
45
 
 
46
#include <time.h>
 
47
#include <stdio.h>
 
48
#include <stdlib.h>
 
49
#include <string.h>
 
50
 
 
51
PRBool debug_mode = PR_TRUE;
 
52
 
 
53
static char *dayOfWeek[] =
 
54
        { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
 
55
static char *month[] =
 
56
        { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
 
57
          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" };
 
58
 
 
59
static void PrintExplodedTime(const PRExplodedTime *et) {
 
60
    PRInt32 totalOffset;
 
61
    PRInt32 hourOffset, minOffset;
 
62
    const char *sign;
 
63
 
 
64
    /* Print day of the week, month, day, hour, minute, and second */
 
65
    if (debug_mode) printf("%s %s %ld %02ld:%02ld:%02ld ",
 
66
            dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
 
67
            et->tm_hour, et->tm_min, et->tm_sec);
 
68
 
 
69
    /* Print time zone */
 
70
    totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
 
71
    if (totalOffset == 0) {
 
72
        if (debug_mode) printf("UTC ");
 
73
    } else {
 
74
        sign = "+";
 
75
        if (totalOffset < 0) {
 
76
            totalOffset = -totalOffset;
 
77
            sign = "-";
 
78
        }
 
79
        hourOffset = totalOffset / 3600;
 
80
        minOffset = (totalOffset % 3600) / 60;
 
81
        if (debug_mode) 
 
82
            printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
 
83
    }
 
84
 
 
85
    /* Print year */
 
86
    if (debug_mode) printf("%hd", et->tm_year);
 
87
}
 
88
 
 
89
int main(int argc, char **argv)
 
90
{
 
91
    PRTime ct;
 
92
    PRExplodedTime et;
 
93
    PRStatus rv;
 
94
    char *sp1 = "Sat, 1 Jan 3001 00:00:00";  /* no time zone */
 
95
    char *sp2 = "Fri, 31 Dec 3000 23:59:60";  /* no time zone, not normalized */
 
96
 
 
97
#if _MSC_VER >= 1400
 
98
    /* Run this test in the US Pacific Time timezone. */
 
99
    _putenv_s("TZ", "PST8PDT");
 
100
    _tzset();
 
101
#endif
 
102
 
 
103
    rv = PR_ParseTimeString(sp1, PR_FALSE, &ct);
 
104
    printf("rv = %d\n", rv);
 
105
    PR_ExplodeTime(ct, PR_GMTParameters, &et);
 
106
    PrintExplodedTime(&et);
 
107
    printf("\n");
 
108
 
 
109
    rv = PR_ParseTimeString(sp2, PR_FALSE, &ct);
 
110
    printf("rv = %d\n", rv);
 
111
    PR_ExplodeTime(ct, PR_GMTParameters, &et);
 
112
    PrintExplodedTime(&et);
 
113
    printf("\n");
 
114
 
 
115
    return 0;
 
116
}