Skip to content

Instantly share code, notes, and snippets.

@beeender
Created May 3, 2017 14:19
Show Gist options
  • Save beeender/3759da9032ae9a199b3d6b9f2560d38e to your computer and use it in GitHub Desktop.
Save beeender/3759da9032ae9a199b3d6b9f2560d38e to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <time.h>
TEST_CASE("438") {
srand(time(nullptr));
InMemoryTestFile config;
config.automatic_change_notifications = false;
auto r = Realm::get_shared_realm(config);
r->update_schema({
{"filter", {
{"int", PropertyType::Int},
{"apps", PropertyType::Array, "app"}
}},
{"app", {
{"feeds", PropertyType::Array, "feed"}
}},
{"feed", {
{"items", PropertyType::Array, "item"}
}},
{"item", {
{"app", PropertyType::Object, "app", "", false, false, true}
}},
});
auto filter_table = r->read_group().get_table("class_filter");
auto app_table = r->read_group().get_table("class_app");
auto feed_table = r->read_group().get_table("class_feed");
auto item_table = r->read_group().get_table("class_item");
const size_t app_count = 300;
const size_t feed_count = 10;
const size_t filter_count = 2;
const size_t item_count_per_feed = 2;
r->begin_transaction();
filter_table->add_empty_row(filter_count);
app_table->add_empty_row(app_count);
for (size_t i = 0; i < app_count; ++i) {
for (size_t j = 0; j < feed_count; ++j) {
size_t row_ndx = feed_table->add_empty_row(feed_count);
app_table->get_linklist(0, i)->add(row_ndx);
for (size_t k = 0; k < item_count_per_feed; ++k) {
size_t row_ndx = item_table->add_empty_row();
//item_table->set_link(0, row_ndx, app_count - i - 1);
//item_table->set_link(0, row_ndx, i);
item_table->set_link(0, row_ndx, rand() % app_count);
feed_table->get_linklist(0, j)->add(row_ndx);
}
}
for (size_t k = 0; k < filter_count; ++k)
filter_table->get_linklist(1, k)->add(rand() % app_count);
}
r->commit_transaction();
auto track_changes = [&](auto&& f) {
auto history = make_in_realm_history(config.path);
SharedGroup sg(*history, config.options());
Group const& g = sg.begin_read();
r->begin_transaction();
f();
r->commit_transaction();
_impl::TransactionChangeInfo info{};
info.table_modifications_needed.resize(g.size(), true);
info.table_moves_needed.resize(g.size(), true);
_impl::transaction::advance(sg, info);
return info;
};
std::vector<_impl::DeepChangeChecker::RelatedTable> tables;
_impl::DeepChangeChecker::find_related_tables(tables, *filter_table);
SECTION("test") {
auto info = track_changes([&] {
filter_table->set_int(0, 1, 10);
});
_impl::DeepChangeChecker checker(info, *filter_table, tables);
REQUIRE_FALSE(checker(0));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment