Commit f3bb4c13 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

added more tests on dnstime with wider coverage, and moved them to a

separate test file (some of them are currently failing, and so commented out)


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1089 e5f2f494-b856-4b98-b285-d166d9295462
parent a9ffdf73
......@@ -11,6 +11,7 @@ run_unittests_SOURCES += buffer_unittest.cc name_unittest.cc
run_unittests_SOURCES += messagerenderer_unittest.cc
run_unittests_SOURCES += rrclass_unittest.cc rrtype_unittest.cc
run_unittests_SOURCES += rrttl_unittest.cc
run_unittests_SOURCES += dnstime_unittest.cc
run_unittests_SOURCES += rdata_unittest.h rdata_unittest.cc
run_unittests_SOURCES += rdata_in_a_unittest.cc rdata_in_aaaa_unittest.cc
run_unittests_SOURCES += rdata_ns_unittest.cc rdata_soa_unittest.cc
......
// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// $Id$
#include <string>
#include <time.h>
#include <dns/dnstime.h>
#include <gtest/gtest.h>
using namespace std;
using namespace isc::dns;
namespace {
TEST(DNSTimeTest, fromText)
{
// We need test cases after overwrapping.
//DNSSECTimeFromText("99991231235959");
// These are bogus and should be rejected
//EXPECT_THROW(DNSSECTimeFromText("2011 101120000"), InvalidTime);
//EXPECT_THROW(DNSSECTimeFromText("201101011200-0"), InvalidTime);
// Short length
EXPECT_THROW(DNSSECTimeFromText("20100223"), InvalidTime);
// Leap year checks
EXPECT_THROW(DNSSECTimeFromText("20110229120000"), InvalidTime);
EXPECT_THROW(DNSSECTimeFromText("21000229120000"), InvalidTime);
EXPECT_NO_THROW(DNSSECTimeFromText("20000229120000"));
EXPECT_NO_THROW(DNSSECTimeFromText("20120229120000"));
// unusual case: this implementation allows SS=60 for "leap seconds"
EXPECT_NO_THROW(DNSSECTimeFromText("20110101120060"));
// Out of range parameters
EXPECT_THROW(DNSSECTimeFromText("19100223214617"), InvalidTime); // YY<1970
EXPECT_THROW(DNSSECTimeFromText("20110001120000"), InvalidTime); // MM=00
EXPECT_THROW(DNSSECTimeFromText("20111301120000"), InvalidTime); // MM=13
EXPECT_THROW(DNSSECTimeFromText("20110100120000"), InvalidTime); // DD=00
EXPECT_THROW(DNSSECTimeFromText("20110132120000"), InvalidTime); // DD=32
EXPECT_THROW(DNSSECTimeFromText("20110431120000"), InvalidTime); // 'Apr31'
EXPECT_THROW(DNSSECTimeFromText("20110101250000"), InvalidTime); // HH=25
EXPECT_THROW(DNSSECTimeFromText("20110101126000"), InvalidTime); // mm=60
EXPECT_THROW(DNSSECTimeFromText("20110101120061"), InvalidTime); // SS=61
}
TEST(DNSTimeTest, fromTime)
{
// Jan 1, Year 10,000. What should we do?
//EXPECT_EQ("", DNSSECTimeToText(253402300800));
}
}
......@@ -77,12 +77,6 @@ TEST_F(Rdata_RRSIG_Test, badText_RRSIG)
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc="), InvalidTime);
EXPECT_THROW(const generic::RRSIG sig("A 5 4 43200 "
"19100223214617 19100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc="), InvalidTime);
EXPECT_THROW(const generic::RRSIG sig("A 5 4 43200 "
"20100223214617 20100222214617 999999 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment