Skip to content

upgrade to use catch2 #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ add_subdirectory (src)

if(BUILD_TESTS)
enable_testing()
add_subdirectory(Catch2)
add_subdirectory (tests)
endif(BUILD_TESTS)

Expand Down
1 change: 1 addition & 0 deletions Catch2
Submodule Catch2 added at 914aee
1 change: 0 additions & 1 deletion catch
Submodule catch deleted from d75842
8 changes: 4 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/aggregate_view_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//

#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>

#include <sstream>
#include "mfast.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/arena_allocator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//
#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>

#include <mfast/arena_allocator.h>
#include <cstring>
Expand Down
3 changes: 1 addition & 2 deletions tests/coder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//

#include "catch.hpp"

#include <catch2/catch_test_macros.hpp>
#include <mfast.h>
#include <mfast/field_comparator.h>
#include <mfast/xml_parser/dynamic_templates_description.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/composite_type_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//

#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>

#include "test4.h"
#include <mfast/field_comparator.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/debug_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//
#pragma once

#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>
#include <mfast/malloc_allocator.h>
#include <set>
#include <cstring>
Expand Down
20 changes: 10 additions & 10 deletions tests/decoder_operator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//
#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>

#include <mfast/int_ref.h>
#include <mfast/coder/common/codec_helper.h>
Expand Down Expand Up @@ -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<uint64_mref, copy_operator_tag, mandatory_with_initial_value_tag >(result), CHANGE_PREVIOUS_VALUE), const mfast::fast_error& );
REQUIRE_THROWS_AS(decode_ext_mref("\x80\x80", HAS_PMAP_BIT, ext_mref<uint64_mref, copy_operator_tag, mandatory_with_initial_value_tag >(result), CHANGE_PREVIOUS_VALUE), mfast::fast_error );
}

{
Expand Down Expand Up @@ -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<uint64_mref, increment_operator_tag, mandatory_with_initial_value_tag >(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<uint64_mref, increment_operator_tag, mandatory_with_initial_value_tag >(result), CHANGE_PREVIOUS_VALUE), mfast::fast_error);
}

{
Expand Down Expand Up @@ -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<ascii_string_mref, delta_operator_tag, mandatory_without_initial_value_tag >(
result), CHANGE_PREVIOUS_VALUE), const mfast::fast_error&);
result), CHANGE_PREVIOUS_VALUE), mfast::fast_error);

inst.destruct_value(storage, &alloc);
}
Expand Down Expand Up @@ -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<unicode_string_mref, delta_operator_tag, mandatory_without_initial_value_tag >(result), CHANGE_PREVIOUS_VALUE),
const mfast::fast_error& );
mfast::fast_error );
inst.destruct_value(storage, &alloc);
}

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/dictionary_builder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//
#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>

#include <mfast.h>
#include <mfast/xml_parser/dynamic_templates_description.h>
Expand Down
11 changes: 5 additions & 6 deletions tests/encoder_operator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//

#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>
#include <mfast/int_ref.h>
#include <mfast/coder/common/codec_helper.h>
#include <mfast/coder/encoder/fast_ostream.h>
Expand Down Expand Up @@ -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<uint64_cref, copy_operator_tag, mandatory_with_initial_value_tag>(result),
CHANGE_PREVIOUS_VALUE, &allocator )
, const mfast::fast_error& );
, mfast::fast_error );
}

{
Expand Down Expand Up @@ -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<uint64_cref, increment_operator_tag, mandatory_with_initial_value_tag>(result),
CHANGE_PREVIOUS_VALUE, &allocator ),
const mfast::fast_error&);
mfast::fast_error);
}

{
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions tests/fast_istream_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//

#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>
#include <mfast/coder/decoder/fast_istream.h>
#include <mfast/coder/decoder/fast_istream_extractor.h>
#include <mfast/output.h>
Expand Down Expand Up @@ -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." );
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/fast_ostream_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//

#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>

#include <mfast/coder/encoder/fast_ostream.h>
#include <mfast/coder/encoder/fast_ostream_inserter.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/fast_type_gen_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// This file is part of mFAST.
// See the file license.txt for licensing information.

#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>
#include "debug_allocator.h"

#include "test1.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/field_comparator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//
#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>

#include <mfast.h>
#include <mfast/field_comparator.h>
Expand Down
11 changes: 6 additions & 5 deletions tests/field_ref_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
//


#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp>

#include <mfast/int_ref.h>
#include <mfast/string_ref.h>
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion tests/int_vector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//

#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>

#include <mfast.h>
#include <mfast/coder/fast_encoder.h>
Expand Down
4 changes: 2 additions & 2 deletions tests/json_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//
#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>

#include "test3.h"
#include <mfast/json/json.h>
Expand Down Expand Up @@ -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]")
Expand Down
2 changes: 1 addition & 1 deletion tests/scp_reset_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>
#include <mfast.h>
#include <mfast/field_comparator.h>
#include <mfast/coder/fast_encoder_v2.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/simple_coder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//

#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>
#include <mfast.h>
#include <mfast/field_comparator.h>
#include <mfast/coder/fast_encoder_v2.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@


#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>
2 changes: 1 addition & 1 deletion tests/value_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with mFast. If not, see <http://www.gnu.org/licenses/>.
//

#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>

#include <mfast/value_storage.h>
using namespace mfast;
Expand Down
Loading