mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-09 15:49:53 +01:00
73 lines
2.3 KiB
C++
73 lines
2.3 KiB
C++
|
|
// Copyright Catch2 Authors
|
|
// Distributed under the Boost Software License, Version 1.0.
|
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
// https://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <catch2/catch_test_case_info.hpp>
|
|
#include <catch2/internal/catch_test_case_info_hasher.hpp>
|
|
|
|
static constexpr Catch::SourceLineInfo dummySourceLineInfo = CATCH_INTERNAL_LINEINFO;
|
|
|
|
using Catch::TestCaseInfo;
|
|
using Catch::TestCaseInfoHasher;
|
|
|
|
TEST_CASE("Hashers with same seed produce same hash", "[test-case-hash]") {
|
|
TestCaseInfo dummy( "", { "name", "[a-tag]" }, dummySourceLineInfo );
|
|
|
|
TestCaseInfoHasher h1( 0x12345678 );
|
|
TestCaseInfoHasher h2( 0x12345678 );
|
|
|
|
REQUIRE( h1( dummy ) == h2( dummy ) );
|
|
}
|
|
|
|
TEST_CASE(
|
|
"Hashers with different seed produce different hash with same test case",
|
|
"[test-case-hash]") {
|
|
TestCaseInfo dummy( "", { "name", "[a-tag]" }, dummySourceLineInfo );
|
|
|
|
TestCaseInfoHasher h1( 0x12345678 );
|
|
TestCaseInfoHasher h2( 0x87654321 );
|
|
|
|
REQUIRE( h1( dummy ) != h2( dummy ) );
|
|
}
|
|
|
|
TEST_CASE("Hashing test case produces same hash across multiple calls",
|
|
"[test-case-hash]") {
|
|
TestCaseInfo dummy( "", { "name", "[a-tag]" }, dummySourceLineInfo );
|
|
|
|
TestCaseInfoHasher h( 0x12345678 );
|
|
|
|
REQUIRE( h( dummy ) == h( dummy ) );
|
|
}
|
|
|
|
TEST_CASE("Hashing different test cases produces different result", "[test-case-hash]") {
|
|
TestCaseInfoHasher h( 0x12345678 );
|
|
SECTION("Different test name") {
|
|
TestCaseInfo dummy1( "class", { "name-1", "[a-tag]" }, dummySourceLineInfo );
|
|
TestCaseInfo dummy2(
|
|
"class", { "name-2", "[a-tag]" }, dummySourceLineInfo );
|
|
|
|
REQUIRE( h( dummy1 ) != h( dummy2 ) );
|
|
}
|
|
SECTION("Different classname") {
|
|
TestCaseInfo dummy1(
|
|
"class-1", { "name", "[a-tag]" }, dummySourceLineInfo );
|
|
TestCaseInfo dummy2(
|
|
"class-2", { "name", "[a-tag]" }, dummySourceLineInfo );
|
|
|
|
REQUIRE( h( dummy1 ) != h( dummy2 ) );
|
|
}
|
|
SECTION("Different tags") {
|
|
TestCaseInfo dummy1(
|
|
"class", { "name", "[a-tag]" }, dummySourceLineInfo );
|
|
TestCaseInfo dummy2(
|
|
"class", { "name", "[b-tag]" }, dummySourceLineInfo );
|
|
|
|
REQUIRE( h( dummy1 ) != h( dummy2 ) );
|
|
}
|
|
}
|