Skip to content

Commit

Permalink
better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltabacaru committed Feb 1, 2022
1 parent 3409477 commit 093ec7a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
29 changes: 18 additions & 11 deletions test/test_changeset_encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ Changeset encode_then_parse(const Changeset& changeset)
}
} // namespace

TEST(ChangesetEncoding_InternStringsNotDuplicated)
{
sync::ChangesetEncoder encoder;

encoder.intern_string("Prógram");
encoder.intern_string("Program");
// Bug #5193 caused "Program" not to be found through the interned strings
// although it was just created before.
encoder.intern_string("Program");
}

TEST(ChangesetEncoding_AddTable)
{
Changeset changeset;
Expand Down Expand Up @@ -270,3 +259,21 @@ TEST(ChangesetEncoding_Clear)
CHECK_EQUAL(changeset, parsed);
CHECK(**changeset.begin() == instr);
}

TEST(ChangesetEncoding_AccentWords)
{
sync::ChangesetEncoder encoder;

encoder.intern_string("Prógram");
encoder.intern_string("Program");
// Bug #5193 caused "Program" to not be found as an intern string
// although it was just created before.
encoder.intern_string("Program");
auto& buffer = encoder.buffer();

using realm::_impl::SimpleNoCopyInputStream;
SimpleNoCopyInputStream stream{buffer.data(), buffer.size()};
Changeset parsed;
// This will throw if a string is interned twice.
CHECK_NOTHROW(parse_changeset(stream, parsed));
}
50 changes: 50 additions & 0 deletions test/test_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5733,6 +5733,56 @@ TEST(Sync_BadChangeset)
}


TEST(Sync_GoodChangeset_AccentCharacterInFieldName)
{
TEST_DIR(dir);
TEST_CLIENT_DB(db);

bool did_fail = false;
{
ClientServerFixture::Config config;
config.disable_upload_compaction = true;
ClientServerFixture fixture(dir, test_context, std::move(config));
fixture.start();

{
Session session = fixture.make_bound_session(db);
session.wait_for_download_complete_or_client_stopped();
}

{
WriteTransaction wt(db);
TableRef table = wt.add_table("class_table");
table->add_column(type_Int, "prógram");
table->add_column(type_Int, "program");
auto obj = table->create_object();
obj.add_int("program", 42);
wt.commit();
}

auto listener = [&](ConnectionState state, const Session::ErrorInfo* error_info) {
if (state != ConnectionState::disconnected)
return;
REALM_ASSERT(error_info);
std::error_code ec = error_info->error_code;
bool is_fatal = error_info->is_fatal;
CHECK_EQUAL(sync::ProtocolError::bad_changeset, ec);
CHECK(is_fatal);
fixture.stop();
did_fail = true;
};

Session session = fixture.make_session(db);
session.set_connection_state_change_listener(listener);
fixture.bind_session(session, "/test");

session.wait_for_upload_complete_or_client_stopped();
session.wait_for_download_complete_or_client_stopped();
}
CHECK_NOT(did_fail);
}


namespace issue2104 {

class IntegrationReporter : public _impl::ServerHistory::IntegrationReporter {
Expand Down

0 comments on commit 093ec7a

Please sign in to comment.