aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorSimon Warta <[email protected]>2015-08-11 10:13:50 +0200
committerSimon Warta <[email protected]>2015-08-11 10:21:43 +0200
commit0bcab9b1234c97062f0209c5ba2ec149d5442aad (patch)
treefdec833afe18263ba2ca298e93d55915975eb149 /src/tests
parentd61a49d1435d30c5345741ba6a86bd22fc2e0584 (diff)
Refector tests style (use matchers)
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/catchy/test_utils.cpp146
1 files changed, 64 insertions, 82 deletions
diff --git a/src/tests/catchy/test_utils.cpp b/src/tests/catchy/test_utils.cpp
index c2b22c34a..a01cffa2b 100644
--- a/src/tests/catchy/test_utils.cpp
+++ b/src/tests/catchy/test_utils.cpp
@@ -11,91 +11,73 @@ using namespace Botan;
TEST_CASE("round_up strictly positive", "[utils]")
{
- CHECK(( round_up( 1, 10) == 10 ));
- CHECK(( round_up( 3, 10) == 10 ));
- CHECK(( round_up( 9, 10) == 10 ));
- CHECK(( round_up(10, 10) == 10 ));
-
- CHECK(( round_up( 1, 4) == 4 ));
- CHECK(( round_up( 3, 4) == 4 ));
- CHECK(( round_up( 4, 4) == 4 ));
- CHECK(( round_up( 9, 4) == 12 ));
- CHECK(( round_up(10, 4) == 12 ));
+ CHECK_THAT(round_up( 1, 10), Equals(10));
+ CHECK_THAT(round_up( 3, 10), Equals(10));
+ CHECK_THAT(round_up( 9, 10), Equals(10));
+ CHECK_THAT(round_up(10, 10), Equals(10));
+
+ CHECK_THAT(round_up( 1, 4), Equals( 4));
+ CHECK_THAT(round_up( 3, 4), Equals( 4));
+ CHECK_THAT(round_up( 4, 4), Equals( 4));
+ CHECK_THAT(round_up( 9, 4), Equals(12));
+ CHECK_THAT(round_up(10, 4), Equals(12));
}
-/*
-This was broken
-
-TEST_CASE("round_up strictly negative", "[utils]")
- {
- CHECK(( round_up( -1, 10) == 0 ));
- CHECK(( round_up( -3, 10) == 0 ));
- CHECK(( round_up( -9, 10) == 0 ));
- CHECK(( round_up(-10, 10) == -10 ));
-
- CHECK(( round_up( -1, 3) == 0 ));
- CHECK(( round_up( -3, 3) == -3 ));
- CHECK(( round_up( -8, 3) == -3 ));
- CHECK(( round_up( -9, 3) == -9 ));
- CHECK(( round_up(-10, 3) == -9 ));
- }
-*/
-
TEST_CASE("round_up zero", "[utils]")
{
- CHECK(( round_up(0, 2) == 0 ));
- CHECK(( round_up(0, 10) == 0 ));
- CHECK(( round_up(0, 1000) == 0 ));
- CHECK(( round_up(0, 99999) == 0 ));
- CHECK(( round_up(0, 2222222) == 0 ));
+ CHECK_THAT(round_up(0, 2), Equals(0));
+ CHECK_THAT(round_up(0, 10), Equals(0));
+ CHECK_THAT(round_up(0, 1000), Equals(0));
+ CHECK_THAT(round_up(0, 99999), Equals(0));
+ CHECK_THAT(round_up(0, 2222222), Equals(0));
}
TEST_CASE("round_up invalid input", "[utils]")
{
- CHECK_THROWS( round_up(3, 0) );
- CHECK_THROWS( round_up(5, 0) );
+ CHECK_THROWS(round_up(3, 0));
+ CHECK_THROWS(round_up(5, 0));
}
TEST_CASE("calendar_point constructor works", "[utils]")
{
{
auto point1 = calendar_point(1988, 04, 23, 14, 37, 28);
- CHECK(( point1.year == 1988 ));
- CHECK(( point1.month == 4 ));
- CHECK(( point1.day == 23 ));
- CHECK(( point1.hour == 14 ));
- CHECK(( point1.minutes == 37 ));
- CHECK(( point1.seconds == 28 ));
+ CHECK_THAT(point1.year, Equals(1988));
+ CHECK_THAT(point1.month, Equals(4));
+ CHECK_THAT(point1.day, Equals(23));
+ CHECK_THAT(point1.hour, Equals(14));
+ CHECK_THAT(point1.minutes, Equals(37));
+ CHECK_THAT(point1.seconds, Equals(28));
}
{
auto point2 = calendar_point(1800, 01, 01, 0, 0, 0);
- CHECK(( point2.year == 1800 ));
- CHECK(( point2.month == 1 ));
- CHECK(( point2.day == 1 ));
- CHECK(( point2.hour == 0 ));
- CHECK(( point2.minutes == 0 ));
- CHECK(( point2.seconds == 0 ));
+ CHECK_THAT(point2.year, Equals(1800));
+ CHECK_THAT(point2.month, Equals(1));
+ CHECK_THAT(point2.day, Equals(1));
+ CHECK_THAT(point2.hour, Equals(0));
+ CHECK_THAT(point2.minutes, Equals(0));
+ CHECK_THAT(point2.seconds, Equals(0));
}
{
auto point = calendar_point(2037, 12, 31, 24, 59, 59);
- CHECK(( point.year == 2037 ));
- CHECK(( point.month == 12 ));
- CHECK(( point.day == 31 ));
- CHECK(( point.hour == 24 ));
- CHECK(( point.minutes == 59 ));
- CHECK(( point.seconds == 59 ));
+ CHECK_THAT(point.year, Equals(2037));
+ CHECK_THAT(point.month, Equals(12));
+ CHECK_THAT(point.day, Equals(31));
+ CHECK_THAT(point.hour, Equals(24));
+ CHECK_THAT(point.minutes, Equals(59));
+ CHECK_THAT(point.seconds, Equals(59));
}
{
auto point = calendar_point(2100, 5, 1, 0, 0, 0);
- CHECK(( point.year == 2100 ));
- CHECK(( point.month == 5 ));
- CHECK(( point.day == 1 ));
- CHECK(( point.hour == 0 ));
- CHECK(( point.minutes == 0 ));
- CHECK(( point.seconds == 0 ));
+ CHECK_THAT(point.year, Equals(2100));
+ CHECK_THAT(point.month, Equals(5));
+ CHECK_THAT(point.day, Equals(1));
+ CHECK_THAT(point.hour, Equals(0));
+ CHECK_THAT(point.minutes, Equals(0));
+ CHECK_THAT(point.seconds, Equals(0));
}
}
@@ -105,12 +87,12 @@ TEST_CASE("calendar_point to stl timepoint and back", "[utils]")
{
auto in = calendar_point(1988, 04, 23, 14, 37, 28);
auto out = calendar_value(in.to_std_timepoint());
- CHECK(( out.year == 1988 ));
- CHECK(( out.month == 4 ));
- CHECK(( out.day == 23 ));
- CHECK(( out.hour == 14 ));
- CHECK(( out.minutes == 37 ));
- CHECK(( out.seconds == 28 ));
+ CHECK_THAT(out.year, Equals(1988));
+ CHECK_THAT(out.month, Equals(4));
+ CHECK_THAT(out.day, Equals(23));
+ CHECK_THAT(out.hour, Equals(14));
+ CHECK_THAT(out.minutes, Equals(37));
+ CHECK_THAT(out.seconds, Equals(28));
}
// _mkgmtime on Windows does not work for dates before 1970
@@ -118,53 +100,53 @@ TEST_CASE("calendar_point to stl timepoint and back", "[utils]")
{
auto in = calendar_point(1970, 01, 01, 00, 00, 00);
auto out = calendar_value(in.to_std_timepoint());
- CHECK(( out.year == 1970 ));
- CHECK(( out.month == 01 ));
- CHECK(( out.day == 01 ));
- CHECK(( out.hour == 00 ));
- CHECK(( out.minutes == 00 ));
- CHECK(( out.seconds == 00 ));
+ CHECK_THAT(out.year, Equals(1970));
+ CHECK_THAT(out.month, Equals(01));
+ CHECK_THAT(out.day, Equals(01));
+ CHECK_THAT(out.hour, Equals(00));
+ CHECK_THAT(out.minutes, Equals(00));
+ CHECK_THAT(out.seconds, Equals(00));
}
SECTION("latest possible time point")
{
auto in = calendar_point(2037, 12, 31, 23, 59, 59);
auto out = calendar_value(in.to_std_timepoint());
- CHECK(( out.year == 2037 ));
- CHECK(( out.month == 12 ));
- CHECK(( out.day == 31 ));
- CHECK(( out.hour == 23 ));
- CHECK(( out.minutes == 59 ));
- CHECK(( out.seconds == 59 ));
+ CHECK_THAT(out.year, Equals(2037));
+ CHECK_THAT(out.month, Equals(12));
+ CHECK_THAT(out.day, Equals(31));
+ CHECK_THAT(out.hour, Equals(23));
+ CHECK_THAT(out.minutes, Equals(59));
+ CHECK_THAT(out.seconds, Equals(59));
}
SECTION("year too early")
{
{
auto in = calendar_point(1800, 01, 01, 0, 0, 0);
- CHECK_THROWS( in.to_std_timepoint() );
+ CHECK_THROWS(in.to_std_timepoint());
}
{
auto in = calendar_point(1899, 12, 31, 23, 59, 59);
- CHECK_THROWS( in.to_std_timepoint() );
+ CHECK_THROWS(in.to_std_timepoint());
}
{
auto in = calendar_point(1969, 12, 31, 23, 59, 58); // time_t = -2
- CHECK_THROWS( in.to_std_timepoint() );
+ CHECK_THROWS(in.to_std_timepoint());
}
{
auto in = calendar_point(1969, 12, 31, 23, 59, 59); // time_t = -1
- CHECK_THROWS( in.to_std_timepoint() );
+ CHECK_THROWS(in.to_std_timepoint());
}
}
SECTION("year too late")
{
auto in = calendar_point(2038, 01, 01, 0, 0, 0);
- CHECK_THROWS( in.to_std_timepoint() );
+ CHECK_THROWS(in.to_std_timepoint());
}
}