1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/*
* test_sccsdate.cc: Part of GNU CSSC.
*
*
* Copyright (C) 2010 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Unit tests for sccsdate.h.
*
*/
#include "sccsdate.h"
#include "quit.h"
#include <gtest/gtest.h>
TEST(SccsdateTest, NullConstructor)
{
const sccs_date d;
ASSERT_FALSE(d.valid());
}
TEST(SccsdateTest, StringConstructor)
{
sccs_date d12("990519014208");
ASSERT_TRUE(d12.valid());
EXPECT_EQ("99/05/19 01:42:08", d12.as_string());
sccs_date d14("19990519014208");
ASSERT_TRUE(d14.valid());
EXPECT_EQ("99/05/19 01:42:08", d14.as_string());
}
TEST(SccsdateTest, StringDateTimeConstructor)
{
sccs_date d12("99/05/19", "01:42:08");
ASSERT_TRUE(d12.valid());
EXPECT_EQ("99/05/19 01:42:08", d12.as_string());
}
TEST(SccsdateTest, FourDigitYear)
{
// This test generates a warning on stderr.
// That's OK.
sccs_date d14("1999/05/19", "01:42:08");
ASSERT_TRUE(d14.valid());
EXPECT_EQ("99/05/19 01:42:08", d14.as_string());
}
#if GTEST_HAS_DEATH_TEST
TEST(SccsdateDeathTest, BuckRogers)
{
// As a sanity check we verify that the year is within the window
// described by the X/Open convention for handling 2-digit years.
//
// We could support such years quite easily, except for the fact that
// interoperation with other versions of SCCS would become harder.
EXPECT_EXIT(sccs_date("2429/05/19", "01:42:08"),
::testing::KilledBySignal(SIGABRT),
"year < 2069");
}
#endif
TEST(SccsdateTest, ColonYear)
{
// This test generates a warning on stderr.
// That's OK.
//
// Some versions of SCCS roll from 99 to :0 instead of 99 to 00.
// Yes, that's a bug in those versions of SCCS.
// Check that we correctly convert those dates.
sccs_date d12(":0/05/19", "01:42:08");
ASSERT_TRUE(d12.valid());
EXPECT_EQ("00/05/19 01:42:08", d12.as_string());
}
TEST(SccsdateTest, Now)
{
// Make sure the now method at least returns.
sccs_date::now();
}
TEST(SccsdateTest, Greater)
{
EXPECT_TRUE(sccs_date("99/01/01 00:00:00") >
sccs_date("98/01/01 00:00:00"));
EXPECT_FALSE(sccs_date("98/01/01 00:00:00") >
sccs_date("99/01/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/02/01 00:00:00") >
sccs_date("98/01/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/10/01 00:00:00") >
sccs_date("98/01/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/02 00:00:00") >
sccs_date("98/01/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/10 00:00:00") >
sccs_date("98/01/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 01:00:00") >
sccs_date("98/01/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 10:00:00") >
sccs_date("98/01/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:01:00") >
sccs_date("98/01/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:10:00") >
sccs_date("98/01/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:01") >
sccs_date("98/01/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:10") >
sccs_date("98/01/01 00:00:00"));
// Leap year.
EXPECT_TRUE(sccs_date("00/02/29 00:00:00") >
sccs_date("00/02/28 00:00:00"));
EXPECT_TRUE(sccs_date("00/03/01 00:00:00") >
sccs_date("00/02/29 00:00:00"));
}
TEST(SccsdateTest, Less)
{
EXPECT_FALSE(sccs_date("99/01/01 00:00:00") < sccs_date("98/01/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:00") < sccs_date("99/01/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:00") < sccs_date("98/02/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:00") < sccs_date("98/10/01 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:00") < sccs_date("98/01/02 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:00") < sccs_date("98/01/10 00:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:00") < sccs_date("98/01/01 01:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:00") < sccs_date("98/01/01 10:00:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:00") < sccs_date("98/01/01 00:01:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:00") < sccs_date("98/01/01 00:10:00"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:00") < sccs_date("98/01/01 00:00:01"));
EXPECT_TRUE(sccs_date("98/01/01 00:00:00") < sccs_date("98/01/01 00:00:10"));
// Leap year.
EXPECT_TRUE(sccs_date("00/02/28 00:00:00") < sccs_date("00/02/29 00:00:00"));
EXPECT_TRUE(sccs_date("00/02/29 00:00:00") < sccs_date("00/03/01 00:00:00"));
}
TEST(SccsdateTest, Equality)
{
const char *datestr = "99/01/01 00:00:00";
EXPECT_FALSE(sccs_date(datestr) < sccs_date(datestr));
EXPECT_FALSE(sccs_date(datestr) > sccs_date(datestr));
EXPECT_TRUE(sccs_date(datestr) <= sccs_date(datestr));
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
set_prg_name("test_sccsdate");
return RUN_ALL_TESTS();
}
|