Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed Jun 2, 2023
1 parent ff421c2 commit a5eb04e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/realm/obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,9 @@ CollectionPtr Obj::get_collection_ptr(const Path& path) const
else if (ref.is_type(type_Dictionary)) {
collection = collection->get_dictionary(path_elem);
}
else {
throw InvalidArgument("Wrong path");
}
level++;
}

Expand Down
29 changes: 21 additions & 8 deletions test/object-store/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1290,24 +1290,23 @@ TEST_CASE("nested List") {
{"any", PropertyType::Mixed | PropertyType::Nullable}}},
});

auto& coordinator = *_impl::RealmCoordinator::get_coordinator(config.path);

auto table = r->read_group().get_table("class_table");
ColKey col_any = table->get_column_key("any");

r->begin_transaction();

Obj obj = table->create_object_with_primary_key(47);
obj.set_collection(col_any, CollectionType::List);
obj.get_collection_ptr(col_any)->insert_collection(0, CollectionType::List);
obj.get_collection_ptr(col_any)->insert_collection(1, CollectionType::List);
auto l0 = obj.get_list_ptr<Mixed>(Path{"any", 0});
auto l1 = obj.get_list_ptr<Mixed>(Path{"any", 1});
auto top_list = obj.get_list<Mixed>(col_any);
top_list.insert(0, "Hello");
top_list.insert_collection(1, CollectionType::List);
top_list.insert(2, "Godbye");
top_list.insert_collection(3, CollectionType::List);
auto l0 = obj.get_list_ptr<Mixed>(Path{"any", 1});
auto l1 = obj.get_list_ptr<Mixed>(Path{"any", 3});

r->commit_transaction();

auto r2 = coordinator.get_realm();

auto write = [&](auto&& f) {
r->begin_transaction();
f();
Expand Down Expand Up @@ -1363,6 +1362,20 @@ TEST_CASE("nested List") {
REQUIRE_INDICES(change.insertions, 0);
REQUIRE(!change.collection_was_cleared);
}

SECTION("a notifier can be attached in a different transaction") {
r->begin_transaction();
auto l = obj.get_list<Mixed>(col_any);
l.remove(0);
r->commit_transaction();

auto token = require_change();
write([&] {
lst0.add(Mixed(8));
});
REQUIRE_INDICES(change.insertions, 0);
REQUIRE(!change.collection_was_cleared);
}
}
}

Expand Down

0 comments on commit a5eb04e

Please sign in to comment.