tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_date.c (2364B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 /*
      5 * test_date.c
      6 *
      7 * Test Date Type
      8 *
      9 */
     10 
     11 #include "testutil.h"
     12 #include "testutil_nss.h"
     13 
     14 static void *plContext = NULL;
     15 
     16 static void
     17 createDates(char *goodInput, char *diffInput,
     18            PKIX_PL_Date **goodDate,
     19            PKIX_PL_Date **equalDate,
     20            PKIX_PL_Date **diffDate)
     21 {
     22 
     23    subTest("PKIX_PL_Date_Create <goodDate>");
     24    *goodDate = createDate(goodInput, plContext);
     25 
     26    subTest("PKIX_PL_Date_Create <equalDate>");
     27    *equalDate = createDate(goodInput, plContext);
     28 
     29    subTest("PKIX_PL_Date_Create <diffDate>");
     30    *diffDate = createDate(diffInput, plContext);
     31 }
     32 
     33 static void
     34 testDestroy(void *goodObject, void *equalObject, void *diffObject)
     35 {
     36    PKIX_TEST_STD_VARS();
     37 
     38    subTest("PKIX_PL_Date_Destroy");
     39 
     40    PKIX_TEST_DECREF_BC(goodObject);
     41    PKIX_TEST_DECREF_BC(equalObject);
     42    PKIX_TEST_DECREF_BC(diffObject);
     43 
     44 cleanup:
     45 
     46    PKIX_TEST_RETURN();
     47 }
     48 
     49 static void
     50 testDate(char *goodInput, char *diffInput)
     51 {
     52 
     53    PKIX_PL_Date *goodDate = NULL;
     54    PKIX_PL_Date *equalDate = NULL;
     55    PKIX_PL_Date *diffDate = NULL;
     56 
     57    /*
     58     * The ASCII rep of the date will vary by platform and locale
     59     * This particular string was generated on a SPARC running Solaris 9
     60     * in an English locale
     61     */
     62    /* char *expectedAscii = "Mon Mar 29 08:48:47 2004"; */
     63    char *expectedAscii = "Mon Mar 29, 2004";
     64 
     65    PKIX_TEST_STD_VARS();
     66 
     67    createDates(goodInput, diffInput,
     68                &goodDate, &equalDate, &diffDate);
     69 
     70    PKIX_TEST_EQ_HASH_TOSTR_DUP(goodDate, equalDate, diffDate, expectedAscii, Date, PKIX_TRUE);
     71 
     72    testDestroy(goodDate, equalDate, diffDate);
     73 
     74    PKIX_TEST_RETURN();
     75 }
     76 
     77 int
     78 test_date(int argc, char *argv[])
     79 {
     80 
     81    char *goodInput = NULL;
     82    char *diffInput = NULL;
     83    PKIX_UInt32 actualMinorVersion;
     84    PKIX_UInt32 j = 0;
     85 
     86    PKIX_TEST_STD_VARS();
     87 
     88    startTests("Date");
     89 
     90    PKIX_TEST_EXPECT_NO_ERROR(
     91        PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
     92 
     93    goodInput = "040329134847Z";
     94    diffInput = "050329135847Z";
     95    testDate(goodInput, diffInput);
     96 
     97 cleanup:
     98 
     99    PKIX_Shutdown(plContext);
    100 
    101    PKIX_TEST_RETURN();
    102 
    103    endTests("Date");
    104 
    105    return (0);
    106 }