diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b757f8ad..9fbb83b8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,6 +9,7 @@ set(SOURCES main.cpp parser.cpp results.cpp + transaction_log_parsing.cpp util/test_file.cpp ) diff --git a/tests/transaction_log_parsing.cpp b/tests/transaction_log_parsing.cpp new file mode 100644 index 00000000..e85c6b8c --- /dev/null +++ b/tests/transaction_log_parsing.cpp @@ -0,0 +1,86 @@ +#include "catch.hpp" + +#include "util/test_file.hpp" + +#include "impl/realm_coordinator.hpp" +#include "impl/transact_log_handler.hpp" +#include "property.hpp" +#include "object_schema.hpp" +#include "schema.hpp" + +#include +#include + +using namespace realm; + +TEST_CASE("Transaction log parsing") { + InMemoryTestFile path; + Realm::Config config = path; + + SECTION("schema change validation") { + config.schema = std::make_unique(Schema{ + {"table", "", { + {"unindexed", PropertyTypeInt}, + {"indexed", PropertyTypeInt, "", false, true} + }}, + }); + auto r = Realm::get_shared_realm(std::move(config)); + r->read_group(); + + auto history = make_client_history(config.path); + SharedGroup sg(*history, SharedGroup::durability_MemOnly); + + SECTION("adding a table is allowed") { + WriteTransaction wt(sg); + TableRef table = wt.add_table("new table"); + table->add_column(type_String, "new col"); + wt.commit(); + + REQUIRE_NOTHROW(r->refresh()); + } + + SECTION("adding an index to an existing column is allowed") { + WriteTransaction wt(sg); + TableRef table = wt.get_table("class_table"); + table->add_search_index(0); + wt.commit(); + + REQUIRE_NOTHROW(r->refresh()); + } + + SECTION("removing an index from an existing column is allowed") { + WriteTransaction wt(sg); + TableRef table = wt.get_table("class_table"); + table->remove_search_index(1); + wt.commit(); + + REQUIRE_NOTHROW(r->refresh()); + } + + SECTION("adding a column to an existing table is not allowed (but eventually should be)") { + WriteTransaction wt(sg); + TableRef table = wt.get_table("class_table"); + table->add_column(type_String, "new col"); + wt.commit(); + + REQUIRE_THROWS(r->refresh()); + } + + SECTION("removing a column is not allowed") { + WriteTransaction wt(sg); + TableRef table = wt.get_table("class_table"); + table->remove_column(1); + wt.commit(); + + REQUIRE_THROWS(r->refresh()); + } + + SECTION("removing a table is not allowed") { + WriteTransaction wt(sg); + wt.get_group().remove_table("class_table"); + wt.commit(); + + REQUIRE_THROWS(r->refresh()); + } + } +}