Skip to content

Commit

Permalink
Also fix Lst<Mixed>::clear()
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed Jun 18, 2024
1 parent b62ce85 commit 87c12c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/realm/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,11 @@ void Lst<Mixed>::remove(size_t from, size_t to)

void Lst<Mixed>::clear()
{
if (size() > 0) {
if (Replication* repl = Base::get_replication()) {
repl->list_clear(*this);
}
auto sz = size();
if (Replication* repl = Base::get_replication()) {
repl->list_clear(*this);
}
if (sz > 0) {
CascadeState state;
bool recurse = remove_backlinks(state);

Expand Down
10 changes: 10 additions & 0 deletions test/test_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6222,12 +6222,16 @@ TEST(Sync_CollectionClear)
auto& g = tr.get_group();
auto table = g.add_table_with_primary_key("class_Table", type_Int, "id");
auto col_list = table->add_column_list(type_Int, "ints");
auto col_list_mixed = table->add_column_list(type_Mixed, "any");
auto col_dict = table->add_column_dictionary(type_String, "features");

auto foo = table->create_object_with_primary_key(123);
auto list = foo.get_list<Int>(col_list);
list.clear();
list.add(1);
auto list_mixed = foo.get_list<Mixed>(col_list_mixed);
list_mixed.clear();
list_mixed.add("Hello");
auto dict = foo.get_dictionary(col_dict);
dict.clear();
dict.insert("address", "Any Road 3");
Expand All @@ -6237,12 +6241,16 @@ TEST(Sync_CollectionClear)
auto& g = tr.get_group();
auto table = g.add_table_with_primary_key("class_Table", type_Int, "id");
auto col_list = table->add_column_list(type_Int, "ints");
auto col_list_mixed = table->add_column_list(type_Mixed, "any");
auto col_dict = table->add_column_dictionary(type_String, "features");

auto foo = table->create_object_with_primary_key(123);
auto list = foo.get_list<Int>(col_list);
list.clear();
list.add(2);
auto list_mixed = foo.get_list<Mixed>(col_list_mixed);
list_mixed.clear();
list_mixed.add("Godbye");
auto dict = foo.get_dictionary(col_dict);
dict.clear();
dict.insert("city", "Andeby");
Expand All @@ -6258,8 +6266,10 @@ TEST(Sync_CollectionClear)
auto table = read_1.get_table("class_Table");
auto obj = table->get_object_with_primary_key(123);
auto list = obj.get_list<Int>("ints");
auto list_mixed = obj.get_list<Mixed>("any");
auto dict = obj.get_dictionary("features");
CHECK_EQUAL(list.size(), 1);
CHECK_EQUAL(list_mixed.size(), 1);
CHECK_EQUAL(dict.size(), 1);

ReadTransaction read_2{db_2};
Expand Down

0 comments on commit 87c12c4

Please sign in to comment.