|
| 1 | +/* |
| 2 | + ------------------------------------------------------------------------------- |
| 3 | + This file is part of the Private Message Database test suite. |
| 4 | + Copyright (C) 2025 Dirk Stolle |
| 5 | +
|
| 6 | + This program is free software: you can redistribute it and/or modify |
| 7 | + it under the terms of the GNU General Public License as published by |
| 8 | + the Free Software Foundation, either version 3 of the License, or |
| 9 | + (at your option) any later version. |
| 10 | +
|
| 11 | + This program is distributed in the hope that it will be useful, |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + GNU General Public License for more details. |
| 15 | +
|
| 16 | + You should have received a copy of the GNU General Public License |
| 17 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + ------------------------------------------------------------------------------- |
| 19 | +*/ |
| 20 | + |
| 21 | +#include "../locate_catch.hpp" |
| 22 | +#include "../../code/SortType.hpp" |
| 23 | + |
| 24 | +TEST_CASE("SortType") |
| 25 | +{ |
| 26 | + SECTION("constructor") |
| 27 | + { |
| 28 | + SHA256::MessageDigest digest; |
| 29 | + REQUIRE( digest.fromHexString("affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 30 | + SortType instance("2018-07-01 16:13", digest); |
| 31 | + |
| 32 | + REQUIRE( instance.datestamp == "2018-07-01 16:13" ); |
| 33 | + REQUIRE( instance.md.toHexString() == "affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe" ); |
| 34 | + } |
| 35 | + |
| 36 | + SECTION("constructor with changed parameter order") |
| 37 | + { |
| 38 | + SHA256::MessageDigest digest; |
| 39 | + REQUIRE( digest.fromHexString("affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 40 | + SortType instance(digest, "2018-07-01 16:13"); |
| 41 | + |
| 42 | + REQUIRE( instance.datestamp == "2018-07-01 16:13" ); |
| 43 | + REQUIRE( instance.md.toHexString() == "affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe" ); |
| 44 | + } |
| 45 | + |
| 46 | + SECTION("operator <") |
| 47 | + { |
| 48 | + SECTION("less than - different date stamp, different hash") |
| 49 | + { |
| 50 | + SHA256::MessageDigest digest_one; |
| 51 | + REQUIRE( digest_one.fromHexString("affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 52 | + const SortType a("2018-07-01 16:13", digest_one); |
| 53 | + |
| 54 | + SHA256::MessageDigest digest_two; |
| 55 | + REQUIRE( digest_two.fromHexString("ffff00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 56 | + const SortType b("2018-12-31 23:59", digest_two); |
| 57 | + |
| 58 | + REQUIRE( a < b ); |
| 59 | + REQUIRE_FALSE( b < a ); |
| 60 | + } |
| 61 | + |
| 62 | + SECTION("less than - same date stamp, different hash") |
| 63 | + { |
| 64 | + SHA256::MessageDigest digest_one; |
| 65 | + REQUIRE( digest_one.fromHexString("affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 66 | + const SortType a("2018-07-01 16:13", digest_one); |
| 67 | + |
| 68 | + SHA256::MessageDigest digest_two; |
| 69 | + REQUIRE( digest_two.fromHexString("ffff00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 70 | + const SortType b("2018-07-01 16:13", digest_two); |
| 71 | + |
| 72 | + REQUIRE( a < b ); |
| 73 | + REQUIRE_FALSE( b < a ); |
| 74 | + } |
| 75 | + |
| 76 | + SECTION("equal - same date stamp, same hash") |
| 77 | + { |
| 78 | + SHA256::MessageDigest digest; |
| 79 | + REQUIRE( digest.fromHexString("affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 80 | + const SortType a("2018-07-01 16:13", digest); |
| 81 | + const SortType b("2018-07-01 16:13", digest); |
| 82 | + |
| 83 | + REQUIRE_FALSE( a < b ); |
| 84 | + REQUIRE_FALSE( b < a ); |
| 85 | + } |
| 86 | + |
| 87 | + SECTION("greater than - different date stamp, different hash") |
| 88 | + { |
| 89 | + SHA256::MessageDigest digest_one; |
| 90 | + REQUIRE( digest_one.fromHexString("affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 91 | + const SortType a("2018-12-31 23:59", digest_one); |
| 92 | + |
| 93 | + SHA256::MessageDigest digest_two; |
| 94 | + REQUIRE( digest_two.fromHexString("ffff00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 95 | + const SortType b("2018-07-01 16:13", digest_two); |
| 96 | + |
| 97 | + REQUIRE_FALSE( a < b ); |
| 98 | + REQUIRE( b < a ); |
| 99 | + } |
| 100 | + |
| 101 | + SECTION("greater than - same date stamp, different hash") |
| 102 | + { |
| 103 | + SHA256::MessageDigest digest_one; |
| 104 | + REQUIRE( digest_one.fromHexString("ffff00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 105 | + const SortType a("2025-01-01 01:01", digest_one); |
| 106 | + |
| 107 | + SHA256::MessageDigest digest_two; |
| 108 | + REQUIRE( digest_two.fromHexString("affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 109 | + const SortType b("2025-01-01 01:01", digest_two); |
| 110 | + |
| 111 | + REQUIRE_FALSE( a < b ); |
| 112 | + REQUIRE( b < a ); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + SECTION("ST_greater") |
| 117 | + { |
| 118 | + SECTION("less than - different date stamp, different hash") |
| 119 | + { |
| 120 | + SHA256::MessageDigest digest_one; |
| 121 | + REQUIRE( digest_one.fromHexString("affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 122 | + const SortType a("2018-07-01 16:13", digest_one); |
| 123 | + |
| 124 | + SHA256::MessageDigest digest_two; |
| 125 | + REQUIRE( digest_two.fromHexString("ffff00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 126 | + const SortType b("2018-12-31 23:59", digest_two); |
| 127 | + |
| 128 | + REQUIRE_FALSE( ST_greater(a, b) ); |
| 129 | + REQUIRE( ST_greater(b, a) ); |
| 130 | + } |
| 131 | + |
| 132 | + SECTION("less than - same date stamp, different hash") |
| 133 | + { |
| 134 | + SHA256::MessageDigest digest_one; |
| 135 | + REQUIRE( digest_one.fromHexString("affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 136 | + const SortType a("2018-07-01 16:13", digest_one); |
| 137 | + |
| 138 | + SHA256::MessageDigest digest_two; |
| 139 | + REQUIRE( digest_two.fromHexString("ffff00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 140 | + const SortType b("2018-07-01 16:13", digest_two); |
| 141 | + |
| 142 | + REQUIRE_FALSE( ST_greater(a, b) ); |
| 143 | + REQUIRE( ST_greater(b, a) ); |
| 144 | + } |
| 145 | + |
| 146 | + SECTION("equal - same date stamp, same hash") |
| 147 | + { |
| 148 | + SHA256::MessageDigest digest; |
| 149 | + REQUIRE( digest.fromHexString("affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 150 | + const SortType a("2018-07-01 16:13", digest); |
| 151 | + const SortType b("2018-07-01 16:13", digest); |
| 152 | + |
| 153 | + REQUIRE_FALSE( ST_greater(a, b) ); |
| 154 | + REQUIRE_FALSE( ST_greater(b, a) ); |
| 155 | + } |
| 156 | + |
| 157 | + SECTION("greater than - different date stamp, different hash") |
| 158 | + { |
| 159 | + SHA256::MessageDigest digest_one; |
| 160 | + REQUIRE( digest_one.fromHexString("affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 161 | + const SortType a("2018-12-31 23:59", digest_one); |
| 162 | + |
| 163 | + SHA256::MessageDigest digest_two; |
| 164 | + REQUIRE( digest_two.fromHexString("ffff00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 165 | + const SortType b("2018-07-01 16:13", digest_two); |
| 166 | + |
| 167 | + REQUIRE( ST_greater(a, b) ); |
| 168 | + REQUIRE_FALSE( ST_greater(b, a) ); |
| 169 | + } |
| 170 | + |
| 171 | + SECTION("greater than - same date stamp, different hash") |
| 172 | + { |
| 173 | + SHA256::MessageDigest digest_one; |
| 174 | + REQUIRE( digest_one.fromHexString("ffff00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 175 | + const SortType a("2025-01-01 01:01", digest_one); |
| 176 | + |
| 177 | + SHA256::MessageDigest digest_two; |
| 178 | + REQUIRE( digest_two.fromHexString("affe00affe01affe02affe03affe04affe05affe06affe07affe08affe09affe") ); |
| 179 | + const SortType b("2025-01-01 01:01", digest_two); |
| 180 | + |
| 181 | + REQUIRE( ST_greater(a, b) ); |
| 182 | + REQUIRE_FALSE( ST_greater(b, a) ); |
| 183 | + } |
| 184 | + } |
| 185 | +} |
0 commit comments