From 8dc155ba5c6a2dcfd170ff3984d5e24bfa53b12c Mon Sep 17 00:00:00 2001 From: Huang-Ming Huang Date: Tue, 25 Feb 2025 12:45:15 -0600 Subject: [PATCH 1/3] upgrade to use catch2 --- .gitmodules | 6 +++--- CMakeLists.txt | 1 + Catch2 | 1 + catch | 1 - tests/CMakeLists.txt | 8 ++++---- tests/aggregate_view_test.cpp | 2 +- tests/arena_allocator_test.cpp | 2 +- tests/coder_test.cpp | 3 +-- tests/composite_type_test.cpp | 2 +- tests/debug_allocator.h | 2 +- tests/decoder_operator_test.cpp | 20 ++++++++++---------- tests/dictionary_builder_test.cpp | 2 +- tests/encoder_operator_test.cpp | 11 +++++------ tests/fast_istream_test.cpp | 9 ++++----- tests/fast_ostream_test.cpp | 2 +- tests/fast_type_gen_test.cpp | 2 +- tests/field_comparator_test.cpp | 2 +- tests/field_ref_test.cpp | 11 ++++++----- tests/int_vector_test.cpp | 2 +- tests/json_test.cpp | 4 ++-- tests/scp_reset_test.cpp | 2 +- tests/simple_coder_test.cpp | 2 +- tests/test_main.cpp | 2 +- tests/value_storage_test.cpp | 2 +- 24 files changed, 50 insertions(+), 51 deletions(-) create mode 160000 Catch2 delete mode 160000 catch diff --git a/.gitmodules b/.gitmodules index 84ad92e4..90ae49a7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "tinyxml2"] path = tinyxml2 url = https://github.com/leethomason/tinyxml2.git -[submodule "catch"] - path = catch - url = https://github.com/philsquared/Catch.git +[submodule "Catch2"] + path = Catch2 + url = https://github.com/catchorg/Catch2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 10b4a17f..c41dea2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ add_subdirectory (src) if(BUILD_TESTS) enable_testing() + add_subdirectory(Catch2) add_subdirectory (tests) endif(BUILD_TESTS) diff --git a/Catch2 b/Catch2 new file mode 160000 index 00000000..914aeecf --- /dev/null +++ b/Catch2 @@ -0,0 +1 @@ +Subproject commit 914aeecfe23b1e16af6ea675a4fb5dbd5a5b8d0a diff --git a/catch b/catch deleted file mode 160000 index d758428f..00000000 --- a/catch +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d758428fe297655e558a86cc6a013fcb1bcc8c7d diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2859a552..3f7a4144 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,7 +6,7 @@ # endfunction(add_test_executable) # Includes Catch in the project: #add_subdirectory(${EXT_PROJECTS_DIR}/catch) -include_directories(${PROJECT_SOURCE_DIR}/catch/include) +# include_directories(${PROJECT_SOURCE_DIR}/Catch2/include) FASTTYPEGEN_TARGET(simple_types1 simple1.xml) @@ -28,7 +28,6 @@ FASTTYPEGEN_TARGET(test_types5 test5.xml) FASTTYPEGEN_TARGET(test_scp scp.xml) add_executable (mfast_test - test_main.cpp arena_allocator_test.cpp field_ref_test.cpp fast_istream_test.cpp @@ -63,11 +62,12 @@ add_executable (mfast_test scp_reset_test.cpp ) -target_link_libraries (mfast_test +target_link_libraries (mfast_test PRIVATE mfast_static mfast_coder_static mfast_json_static - mfast_xml_parser_static) + mfast_xml_parser_static + Catch2::Catch2WithMain) if(${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten") diff --git a/tests/aggregate_view_test.cpp b/tests/aggregate_view_test.cpp index 379ff24e..2b2309d6 100644 --- a/tests/aggregate_view_test.cpp +++ b/tests/aggregate_view_test.cpp @@ -17,7 +17,7 @@ // along with mFast. If not, see . // -#include "catch.hpp" +#include #include #include "mfast.h" diff --git a/tests/arena_allocator_test.cpp b/tests/arena_allocator_test.cpp index 73dba4c0..e2cf0709 100644 --- a/tests/arena_allocator_test.cpp +++ b/tests/arena_allocator_test.cpp @@ -16,7 +16,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with mFast. If not, see . // -#include "catch.hpp" +#include #include #include diff --git a/tests/coder_test.cpp b/tests/coder_test.cpp index 749ea3a1..c63e5737 100644 --- a/tests/coder_test.cpp +++ b/tests/coder_test.cpp @@ -17,8 +17,7 @@ // along with mFast. If not, see . // -#include "catch.hpp" - +#include #include #include #include diff --git a/tests/composite_type_test.cpp b/tests/composite_type_test.cpp index 95a4ea3b..da05423d 100644 --- a/tests/composite_type_test.cpp +++ b/tests/composite_type_test.cpp @@ -17,7 +17,7 @@ // along with mFast. If not, see . // -#include "catch.hpp" +#include #include "test4.h" #include diff --git a/tests/debug_allocator.h b/tests/debug_allocator.h index 19f6e7b2..7b167ee2 100644 --- a/tests/debug_allocator.h +++ b/tests/debug_allocator.h @@ -18,7 +18,7 @@ // #pragma once -#include "catch.hpp" +#include #include #include #include diff --git a/tests/decoder_operator_test.cpp b/tests/decoder_operator_test.cpp index f9599c4a..abaa3793 100644 --- a/tests/decoder_operator_test.cpp +++ b/tests/decoder_operator_test.cpp @@ -16,7 +16,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with mFast. If not, see . // -#include "catch.hpp" +#include #include #include @@ -497,9 +497,9 @@ TEST_CASE("test the decoding of fast operator copy","[operator_copy_decode_test] inst.prev_value().present(false); // // When the value is not present in the stream there are three cases depending on the state of the previous value: // // * empty – the value of the field is empty. If the field is optional the value is considered absent. It is a dynamic error [ERR D6] if the field is mandatory. - REQUIRE_THROWS_AS(decode_mref("\x80\x80", HAS_PMAP_BIT, result, CHANGE_PREVIOUS_VALUE), const mfast::fast_error& ); + REQUIRE_THROWS_AS(decode_mref("\x80\x80", HAS_PMAP_BIT, result, CHANGE_PREVIOUS_VALUE), mfast::fast_error ); inst.prev_value().present(false); - REQUIRE_THROWS_AS(decode_ext_mref("\x80\x80", HAS_PMAP_BIT, ext_mref(result), CHANGE_PREVIOUS_VALUE), const mfast::fast_error& ); + REQUIRE_THROWS_AS(decode_ext_mref("\x80\x80", HAS_PMAP_BIT, ext_mref(result), CHANGE_PREVIOUS_VALUE), mfast::fast_error ); } { @@ -644,8 +644,8 @@ TEST_CASE("test the decoding of fast operator increment","[operator_increment_de inst.prev_value().present(false); // When the value is not present in the stream there are three cases depending on the state of the previous value: // * empty – the value of the field is empty. If the field is optional the value is considered absent. It is a dynamic error [ERR D6] if the field is mandatory. - REQUIRE_THROWS_AS(decode_mref("\x80\x80", HAS_PMAP_BIT, result, CHANGE_PREVIOUS_VALUE), const mfast::fast_error&); - REQUIRE_THROWS_AS(decode_ext_mref("\x80\x80", HAS_PMAP_BIT, ext_mref(result), CHANGE_PREVIOUS_VALUE), const mfast::fast_error&); + REQUIRE_THROWS_AS(decode_mref("\x80\x80", HAS_PMAP_BIT, result, CHANGE_PREVIOUS_VALUE), mfast::fast_error); + REQUIRE_THROWS_AS(decode_ext_mref("\x80\x80", HAS_PMAP_BIT, ext_mref(result), CHANGE_PREVIOUS_VALUE), mfast::fast_error); } { @@ -980,10 +980,10 @@ TEST_CASE("test the decoding of fast operator delta for ascii string","[operator REQUIRE_THROWS_AS(decode_mref("\xC0\x86\x76\x61\x6C\x75\xE5", NO_PMAP_BIT, result, - CHANGE_PREVIOUS_VALUE), const mfast::fast_error&); + CHANGE_PREVIOUS_VALUE), mfast::fast_error); inst.prev_value().defined(false); // reset the previous value to undefined again REQUIRE_THROWS_AS(decode_ext_mref("\xC0\x86\x76\x61\x6C\x75\xE5", NO_PMAP_BIT, ext_mref( - result), CHANGE_PREVIOUS_VALUE), const mfast::fast_error&); + result), CHANGE_PREVIOUS_VALUE), mfast::fast_error); inst.destruct_value(storage, &alloc); } @@ -1117,10 +1117,10 @@ TEST_CASE("test the decoding of fast operator delta for unicode string","[operat // result.as("initial_value"); REQUIRE_THROWS_AS(decode_mref("\xC0\x86\x85\x76\x61\x6C\x75\x65", NO_PMAP_BIT, result, CHANGE_PREVIOUS_VALUE), - const mfast::fast_error& ); + mfast::fast_error ); REQUIRE_THROWS_AS(decode_ext_mref("\xC0\x86\x85\x76\x61\x6C\x75\x65", NO_PMAP_BIT, ext_mref(result), CHANGE_PREVIOUS_VALUE), - const mfast::fast_error& ); + mfast::fast_error ); inst.destruct_value(storage, &alloc); } @@ -1256,7 +1256,7 @@ TEST_CASE("test the decoding of fast operator tail for ascii string","[operator_ // undefined – the value of the field is the initial value that also becomes the new previous value. // It is a dynamic error [ERR D6] if the instruction context has no initial value. - REQUIRE_THROWS_AS(decode_mref("\x80\x80", HAS_PMAP_BIT, result, CHANGE_PREVIOUS_VALUE), const mfast::fast_error& ); + REQUIRE_THROWS_AS(decode_mref("\x80\x80", HAS_PMAP_BIT, result, CHANGE_PREVIOUS_VALUE), mfast::fast_error ); inst.destruct_value(storage, &alloc); } diff --git a/tests/dictionary_builder_test.cpp b/tests/dictionary_builder_test.cpp index 934f4a7b..9c4c328a 100644 --- a/tests/dictionary_builder_test.cpp +++ b/tests/dictionary_builder_test.cpp @@ -16,7 +16,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with mFast. If not, see . // -#include "catch.hpp" +#include #include #include diff --git a/tests/encoder_operator_test.cpp b/tests/encoder_operator_test.cpp index 288828ae..59aab368 100644 --- a/tests/encoder_operator_test.cpp +++ b/tests/encoder_operator_test.cpp @@ -17,7 +17,7 @@ // along with mFast. If not, see . // -#include "catch.hpp" +#include #include #include #include @@ -528,12 +528,12 @@ TEST_CASE("test the encoding of fast operator copy","[operator_copy_encode_test] inst.prev_value().present(false); // // When the value is not present in the stream there are three cases depending on the state of the previous value: // // * empty – the value of the field is empty. If the field is optional the value is considered absent. It is a dynamic error [ERR D6] if the field is mandatory. - REQUIRE_THROWS_AS( encode_mref("\x80", result, CHANGE_PREVIOUS_VALUE), const mfast::fast_error& ); + REQUIRE_THROWS_AS( encode_mref("\x80", result, CHANGE_PREVIOUS_VALUE), mfast::fast_error); inst.prev_value().present(false); // // When the value is not present in the stream there are three cases depending on the state of the previous value: REQUIRE_THROWS_AS( encode_ext_cref("\x80", ext_cref(result), CHANGE_PREVIOUS_VALUE, &allocator ) - , const mfast::fast_error& ); + , mfast::fast_error ); } { @@ -687,12 +687,12 @@ TEST_CASE("test the encoding of fast operator increment","[operator_increment_en inst.prev_value().present(false); // When the value is not present in the stream there are three cases depending on the state of the previous value: // * empty – the value of the field is empty. If the field is optional the value is considered absent. It is a dynamic error [ERR D6] if the field is mandatory. - REQUIRE_THROWS_AS( encode_mref("\x80\x80", result, CHANGE_PREVIOUS_VALUE), const mfast::fast_error&); + REQUIRE_THROWS_AS( encode_mref("\x80\x80", result, CHANGE_PREVIOUS_VALUE), mfast::fast_error); inst.prev_value().present(false); REQUIRE_THROWS_AS( encode_ext_cref("\x80\x80", ext_cref(result), CHANGE_PREVIOUS_VALUE, &allocator ), - const mfast::fast_error&); + mfast::fast_error); } { @@ -983,7 +983,6 @@ TEST_CASE("test the encoding of fast no operator for ascii string", "[operator_n value_storage storage; { // testing Option assci field with no operator - const char* default_value = "initial_string"; ascii_field_instruction inst(operator_none, presence_optional, 1, diff --git a/tests/fast_istream_test.cpp b/tests/fast_istream_test.cpp index e8bd36cf..ca961cdd 100644 --- a/tests/fast_istream_test.cpp +++ b/tests/fast_istream_test.cpp @@ -17,7 +17,7 @@ // along with mFast. If not, see . // -#include "catch.hpp" +#include #include #include #include @@ -104,7 +104,6 @@ decode_string(const byte_stream& bs, bool nullable, const char* result, std::siz if ((str == nullptr && not_null == false) || (str && len == result_len && memcmp(str, result, len) == 0) ) return true; - bool res( false ); if (not_null) { INFO( "Got \"" << byte_stream(str, len) << "\" instead." ); } @@ -126,9 +125,9 @@ TEST_CASE("test the fast decoding of ascii string","[ascii_string_test]") REQUIRE(decode_string( "\x40\x40\xC0", true, "\x40\x40\xC0", 3)); REQUIRE(decode_string( "\x40\x40\xC0", false, "\x40\x40\xC0", 3)); - REQUIRE_THROWS_AS(decode_string("\x00\xC0", false, nullptr, 0), const mfast::fast_error& ); - REQUIRE_THROWS_AS(decode_string("\x00\xC0", true, nullptr, 0), const mfast::fast_error& ); - REQUIRE_THROWS_AS(decode_string("\x00\x00\xC0", true, nullptr, 0), const mfast::fast_error& ); + REQUIRE_THROWS_AS(decode_string("\x00\xC0", false, nullptr, 0), mfast::fast_error); + REQUIRE_THROWS_AS(decode_string("\x00\xC0", true, nullptr, 0), mfast::fast_error); + REQUIRE_THROWS_AS(decode_string("\x00\x00\xC0", true, nullptr, 0), mfast::fast_error); } bool diff --git a/tests/fast_ostream_test.cpp b/tests/fast_ostream_test.cpp index 11a6b696..bd02417e 100644 --- a/tests/fast_ostream_test.cpp +++ b/tests/fast_ostream_test.cpp @@ -17,7 +17,7 @@ // along with mFast. If not, see . // -#include "catch.hpp" +#include #include #include diff --git a/tests/fast_type_gen_test.cpp b/tests/fast_type_gen_test.cpp index 4656cf97..945a9a8b 100644 --- a/tests/fast_type_gen_test.cpp +++ b/tests/fast_type_gen_test.cpp @@ -4,7 +4,7 @@ // This file is part of mFAST. // See the file license.txt for licensing information. -#include "catch.hpp" +#include #include "debug_allocator.h" #include "test1.h" diff --git a/tests/field_comparator_test.cpp b/tests/field_comparator_test.cpp index e7893f3f..06681e9f 100644 --- a/tests/field_comparator_test.cpp +++ b/tests/field_comparator_test.cpp @@ -16,7 +16,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with mFast. If not, see . // -#include "catch.hpp" +#include #include #include diff --git a/tests/field_ref_test.cpp b/tests/field_ref_test.cpp index d4e30430..c50a445b 100644 --- a/tests/field_ref_test.cpp +++ b/tests/field_ref_test.cpp @@ -18,7 +18,8 @@ // -#include "catch.hpp" +#include +#include #include #include @@ -108,7 +109,7 @@ TEST_CASE("test the operations of interger_field","[integer_field_test]") #ifndef EMSCRIPTEN { helper.save_previous_value(ref); - REQUIRE_THROWS_AS(helper.delta_base_value_of(ref), const mfast::fast_error&); + REQUIRE_THROWS_AS(helper.delta_base_value_of(ref), mfast::fast_error); } #endif { @@ -307,7 +308,7 @@ TEST_CASE("test the operations of decimal_field without mantissa instruction","[ { ref.omit(); helper.save_previous_value(ref); - REQUIRE_THROWS_AS(helper.delta_base_value_of(ref), const mfast::fast_error&); + REQUIRE_THROWS_AS(helper.delta_base_value_of(ref), mfast::fast_error); } #endif { @@ -450,7 +451,7 @@ TEST_CASE("test the operations of decimal_field with mantissa instruction","[dec x.mref ().as (9664.3); double y(x.cref()); - REQUIRE(y == Approx( 9664.3)); + REQUIRE(y == Catch::Approx( 9664.3)); x.mref ().as (0); REQUIRE(x.cref().mantissa() == 0LL); @@ -588,7 +589,7 @@ TEST_CASE("test the operations of string_field","[string_field_test]") #ifndef EMSCRIPTEN { helper.save_previous_value(ref); - REQUIRE_THROWS_AS(helper.delta_base_value_of(ref), const mfast::fast_error&); + REQUIRE_THROWS_AS(helper.delta_base_value_of(ref), mfast::fast_error); } #endif { diff --git a/tests/int_vector_test.cpp b/tests/int_vector_test.cpp index f069d903..ffb579e5 100644 --- a/tests/int_vector_test.cpp +++ b/tests/int_vector_test.cpp @@ -17,7 +17,7 @@ // along with mFast. If not, see . // -#include "catch.hpp" +#include #include #include diff --git a/tests/json_test.cpp b/tests/json_test.cpp index 834510c7..5663c82a 100644 --- a/tests/json_test.cpp +++ b/tests/json_test.cpp @@ -16,7 +16,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with mFast. If not, see . // -#include "catch.hpp" +#include #include "test3.h" #include @@ -128,7 +128,7 @@ TEST_CASE("test json_encode with product type","[json_encode_product_test]") product_ref.omit_stock(); REQUIRE(product_ref.get_stock().absent()); - REQUIRE_THROWS_AS(product_ref.try_get_stock(), const mfast::bad_optional_access&); + REQUIRE_THROWS_AS(product_ref.try_get_stock(), mfast::bad_optional_access); } TEST_CASE("test json_encode with person type","[json_encode_person_test]") diff --git a/tests/scp_reset_test.cpp b/tests/scp_reset_test.cpp index 27003f87..693e3f12 100644 --- a/tests/scp_reset_test.cpp +++ b/tests/scp_reset_test.cpp @@ -1,4 +1,4 @@ -#include "catch.hpp" +#include #include #include #include diff --git a/tests/simple_coder_test.cpp b/tests/simple_coder_test.cpp index 6aed49c1..9d0b3cf4 100644 --- a/tests/simple_coder_test.cpp +++ b/tests/simple_coder_test.cpp @@ -17,7 +17,7 @@ // along with mFast. If not, see . // -#include "catch.hpp" +#include #include #include #include diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 32c2645d..c646c2ac 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -21,4 +21,4 @@ #define CATCH_CONFIG_MAIN -#include "catch.hpp" +#include diff --git a/tests/value_storage_test.cpp b/tests/value_storage_test.cpp index 57f7ac8d..3129c953 100644 --- a/tests/value_storage_test.cpp +++ b/tests/value_storage_test.cpp @@ -17,7 +17,7 @@ // along with mFast. If not, see . // -#include "catch.hpp" +#include #include using namespace mfast; From 340fc2cb8a69fa432d209cfe56746028e8a45894 Mon Sep 17 00:00:00 2001 From: Huang-Ming Huang Date: Tue, 25 Feb 2025 12:58:59 -0600 Subject: [PATCH 2/3] fix ext_ref --- src/mfast/ext_ref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mfast/ext_ref.h b/src/mfast/ext_ref.h index c9a569fa..c7a41800 100644 --- a/src/mfast/ext_ref.h +++ b/src/mfast/ext_ref.h @@ -128,7 +128,7 @@ class ext_cref, Properties> { exponent_type get_exponent() const { return exponent_type(base_.get_exponent()); } - bool present() const { return !this->optional() || base_.present(); } + bool present() const { return !base_.optional() || base_.present(); } private: decimal_cref base_; From fedb11532ddfc1127b9c816fc8a5b687219072ec Mon Sep 17 00:00:00 2001 From: Huang-Ming Huang Date: Tue, 25 Feb 2025 16:08:30 -0600 Subject: [PATCH 3/3] revert ext_ref.h --- src/mfast/ext_ref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mfast/ext_ref.h b/src/mfast/ext_ref.h index c7a41800..c9a569fa 100644 --- a/src/mfast/ext_ref.h +++ b/src/mfast/ext_ref.h @@ -128,7 +128,7 @@ class ext_cref, Properties> { exponent_type get_exponent() const { return exponent_type(base_.get_exponent()); } - bool present() const { return !base_.optional() || base_.present(); } + bool present() const { return !this->optional() || base_.present(); } private: decimal_cref base_;