-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91b70a2
commit c92a24c
Showing
2 changed files
with
105 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,85 +109,85 @@ TEST_CASE("flexible_sync_beta", "[sync]") { | |
// } | ||
} | ||
|
||
//template<typename T, typename Func> | ||
//void test_set(realm::experimental::managed<T>* property, Func f, | ||
// std::vector<typename T::value_type>&& values, size_t&& expected_count = 3) { | ||
// f(property, values, expected_count); | ||
//} | ||
// | ||
//TEST_CASE("set collection sync", "[set]") { | ||
// Admin::Session test_session = Admin::Session::make_default_session(); | ||
// auto app = realm::App(realm::App::configuration({test_session.cached_app_id(), test_session.base_url()})); | ||
// | ||
// SECTION("insert") { | ||
// std::cout << "start insert" << "\n"; | ||
// auto user = app.login(realm::App::credentials::anonymous()).get(); | ||
// auto flx_sync_config = user.flexible_sync_configuration(); | ||
// auto realm = realm::experimental::db(std::move(flx_sync_config)); | ||
// auto update_success = realm.subscriptions().update([](realm::mutable_sync_subscription_set &subs) { | ||
// subs.clear(); | ||
// }).get(); | ||
// CHECK(update_success == true); | ||
// CHECK(realm.subscriptions().size() == 0); | ||
// | ||
// update_success = realm.subscriptions().update([](realm::mutable_sync_subscription_set &subs) { | ||
// subs.add<experimental::AllTypesObject>("foo-strings"); | ||
// subs.add<experimental::AllTypesObjectLink>("foo-link"); | ||
// }).get(); | ||
// CHECK(update_success == true); | ||
// CHECK(realm.subscriptions().size() == 2); | ||
// | ||
// auto obj = realm::experimental::AllTypesObject(); | ||
// | ||
// auto managed_obj = realm.write([&]() { | ||
// return realm.add(std::move(obj)); | ||
// }); | ||
// | ||
// auto scenario = [&](auto &p, auto &values, size_t expected_count) { | ||
// realm.write([&]() { | ||
// for (auto v: values) { | ||
// p->insert(v); | ||
// } | ||
// }); | ||
// CHECK(p->size() == expected_count); | ||
// }; | ||
// | ||
// test_set(&managed_obj.set_int_col, scenario, {42, 42, 24, -1}); | ||
// test_set(&managed_obj.set_double_col, scenario, {42.001, 42.001, 24.001, -1.001}); | ||
// test_set(&managed_obj.set_bool_col, scenario, {true, false, true}, 2); | ||
// test_set(&managed_obj.set_str_col, scenario, {"42", "42", "24", "-1"}); | ||
// test_set(&managed_obj.set_uuid_col, scenario, {realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120000"), realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120000"), realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120001"), realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120002")}); | ||
// auto obj_id = realm::object_id::generate(); | ||
// test_set(&managed_obj.set_object_id_col, scenario, {obj_id, obj_id, realm::object_id::generate(), realm::object_id::generate()}); | ||
// | ||
// auto bin_data = std::vector<uint8_t>({1, 2, 3, 4}); | ||
// test_set(&managed_obj.set_binary_col, scenario, {bin_data, bin_data, std::vector<uint8_t>({1, 3, 4}), std::vector<uint8_t>({1})}); | ||
// | ||
// auto time = std::chrono::system_clock::now(); | ||
// auto time2 = time + time.time_since_epoch(); | ||
// test_set(&managed_obj.set_date_col, scenario, {time, time, time2, std::chrono::time_point<std::chrono::system_clock>()}); | ||
// test_set(&managed_obj.set_mixed_col, scenario, {realm::mixed((int64_t)42), realm::mixed((int64_t)42), realm::mixed("24"), realm::mixed(realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120002"))}); | ||
// | ||
// test::wait_for_sync_uploads(user).get(); | ||
// test::wait_for_sync_downloads(user).get(); | ||
// | ||
// app.register_user("[email protected]", "foobar").get(); | ||
// auto user2 = app.login(realm::App::credentials::username_password("[email protected]", "foobar")).get(); | ||
// | ||
// auto realm2 = realm::experimental::db(user2.flexible_sync_configuration()); | ||
// auto update_success2 = realm2.subscriptions().update([](realm::mutable_sync_subscription_set &subs) { | ||
// subs.add<experimental::AllTypesObject>("foo-strings", [](auto &obj) { | ||
// return obj.str_col == "foo"; | ||
// }); | ||
// subs.add<experimental::AllTypesObjectLink>("foo-link"); | ||
// }).get(); | ||
// CHECK(update_success2 == true); | ||
// CHECK(realm2.subscriptions().size() == 2); | ||
// test::wait_for_sync_downloads(user2).get(); | ||
// realm2.refresh(); | ||
// auto objs = realm2.objects<experimental::AllTypesObject>(); | ||
// CHECK(objs.size() == 1); | ||
// std::cout << "end insert" << "\n"; | ||
// | ||
// } | ||
//} | ||
template<typename T, typename Func> | ||
void test_set(realm::experimental::managed<T>* property, Func f, | ||
std::vector<typename T::value_type>&& values, size_t&& expected_count = 3) { | ||
f(property, values, expected_count); | ||
} | ||
|
||
TEST_CASE("set collection sync", "[set]") { | ||
Admin::Session test_session = Admin::Session::make_default_session(); | ||
auto app = realm::App(realm::App::configuration({test_session.cached_app_id(), test_session.base_url()})); | ||
|
||
SECTION("insert") { | ||
std::cout << "start insert" << "\n"; | ||
auto user = app.login(realm::App::credentials::anonymous()).get(); | ||
auto flx_sync_config = user.flexible_sync_configuration(); | ||
auto realm = realm::experimental::db(std::move(flx_sync_config)); | ||
auto update_success = realm.subscriptions().update([](realm::mutable_sync_subscription_set &subs) { | ||
subs.clear(); | ||
}).get(); | ||
CHECK(update_success == true); | ||
CHECK(realm.subscriptions().size() == 0); | ||
|
||
update_success = realm.subscriptions().update([](realm::mutable_sync_subscription_set &subs) { | ||
subs.add<experimental::AllTypesObject>("foo-strings"); | ||
subs.add<experimental::AllTypesObjectLink>("foo-link"); | ||
}).get(); | ||
CHECK(update_success == true); | ||
CHECK(realm.subscriptions().size() == 2); | ||
|
||
auto obj = realm::experimental::AllTypesObject(); | ||
|
||
auto managed_obj = realm.write([&]() { | ||
return realm.add(std::move(obj)); | ||
}); | ||
|
||
auto scenario = [&](auto &p, auto &values, size_t expected_count) { | ||
realm.write([&]() { | ||
for (auto v: values) { | ||
p->insert(v); | ||
} | ||
}); | ||
CHECK(p->size() == expected_count); | ||
}; | ||
|
||
test_set(&managed_obj.set_int_col, scenario, {42, 42, 24, -1}); | ||
test_set(&managed_obj.set_double_col, scenario, {42.001, 42.001, 24.001, -1.001}); | ||
test_set(&managed_obj.set_bool_col, scenario, {true, false, true}, 2); | ||
test_set(&managed_obj.set_str_col, scenario, {"42", "42", "24", "-1"}); | ||
test_set(&managed_obj.set_uuid_col, scenario, {realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120000"), realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120000"), realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120001"), realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120002")}); | ||
auto obj_id = realm::object_id::generate(); | ||
test_set(&managed_obj.set_object_id_col, scenario, {obj_id, obj_id, realm::object_id::generate(), realm::object_id::generate()}); | ||
|
||
auto bin_data = std::vector<uint8_t>({1, 2, 3, 4}); | ||
test_set(&managed_obj.set_binary_col, scenario, {bin_data, bin_data, std::vector<uint8_t>({1, 3, 4}), std::vector<uint8_t>({1})}); | ||
|
||
auto time = std::chrono::system_clock::now(); | ||
auto time2 = time + time.time_since_epoch(); | ||
test_set(&managed_obj.set_date_col, scenario, {time, time, time2, std::chrono::time_point<std::chrono::system_clock>()}); | ||
test_set(&managed_obj.set_mixed_col, scenario, {realm::mixed((int64_t)42), realm::mixed((int64_t)42), realm::mixed("24"), realm::mixed(realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120002"))}); | ||
|
||
test::wait_for_sync_uploads(user).get(); | ||
test::wait_for_sync_downloads(user).get(); | ||
|
||
app.register_user("[email protected]", "foobar").get(); | ||
auto user2 = app.login(realm::App::credentials::username_password("[email protected]", "foobar")).get(); | ||
|
||
auto realm2 = realm::experimental::db(user2.flexible_sync_configuration()); | ||
auto update_success2 = realm2.subscriptions().update([](realm::mutable_sync_subscription_set &subs) { | ||
subs.add<experimental::AllTypesObject>("foo-strings", [](auto &obj) { | ||
return obj.str_col == "foo"; | ||
}); | ||
subs.add<experimental::AllTypesObjectLink>("foo-link"); | ||
}).get(); | ||
CHECK(update_success2 == true); | ||
CHECK(realm2.subscriptions().size() == 2); | ||
test::wait_for_sync_downloads(user2).get(); | ||
realm2.refresh(); | ||
auto objs = realm2.objects<experimental::AllTypesObject>(); | ||
CHECK(objs.size() == 1); | ||
std::cout << "end insert" << "\n"; | ||
|
||
} | ||
} |