Skip to content

Commit e2f2200

Browse files
committed
Create test file in file-format 24
1 parent 43c2548 commit e2f2200

File tree

3 files changed

+106
-2
lines changed

3 files changed

+106
-2
lines changed

test/test_upgrade_database.cpp

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <realm/version.hpp>
3737
#include "test.hpp"
3838
#include "test_table_helper.hpp"
39+
#include "util/compare_groups.hpp"
3940

4041
#include <external/json/json.hpp>
4142

@@ -273,8 +274,8 @@ TEST(Upgrade_Database_11)
273274
TableRef foo = g.add_table_with_primary_key("foo", type_Int, "id", false);
274275
TableRef bar = g.add_table_with_primary_key("bar", type_String, "name", false);
275276
TableRef o = g.add_table("origin");
276-
auto col1 = o->add_column_link(type_Link, "link1", *foo);
277-
auto col2 = o->add_column_link(type_Link, "link2", *bar);
277+
auto col1 = o->add_column(*foo, "link1");
278+
auto col2 = o->add_column(*bar, "link2");
278279

279280
for (auto id : ids) {
280281
auto obj = foo->create_object_with_primary_key(id);
@@ -884,4 +885,107 @@ TEST_IF(Upgrade_Database_23, REALM_MAX_BPNODE_SIZE == 4 || REALM_MAX_BPNODE_SIZE
884885
g.write(path);
885886
#endif // TEST_READ_UPGRADE_MODE
886887
}
888+
889+
TEST_IF(Upgrade_Database_24, REALM_MAX_BPNODE_SIZE == 4 || REALM_MAX_BPNODE_SIZE == 1000)
890+
{
891+
std::string path = test_util::get_test_resource_path() + "test_upgrade_database_" +
892+
util::to_string(REALM_MAX_BPNODE_SIZE) + "_24.realm";
893+
894+
#if TEST_READ_UPGRADE_MODE
895+
CHECK_OR_RETURN(File::exists(path));
896+
897+
SHARED_GROUP_TEST_PATH(temp_copy);
898+
899+
900+
// Make a copy of the database so that we keep the original file intact and unmodified
901+
File::copy(path, temp_copy);
902+
auto hist = make_in_realm_history();
903+
DBOptions options;
904+
options.logger = test_context.logger;
905+
auto sg = DB::create(*hist, temp_copy, options);
906+
auto wt = sg->start_write();
907+
// rt->to_json(std::cout);
908+
wt->verify();
909+
910+
SHARED_GROUP_TEST_PATH(path2);
911+
wt->write(path2);
912+
auto db2 = DB::create(path2);
913+
auto wt2 = db2->start_write();
914+
CHECK(test_util::compare_groups(*wt, *wt2));
915+
#else
916+
// NOTE: This code must be executed from an old file-format-version 24
917+
// core in order to create a file-format-version 25 test file!
918+
919+
const size_t cnt = 10 * REALM_MAX_BPNODE_SIZE;
920+
921+
std::vector<StringData> string_values{
922+
"white", "yellow", "red", "orange", "green", "blue", "grey", "violet", "purple", "black",
923+
};
924+
925+
StringData long_string(R"(1. Jeg ved en lærkerede,
926+
jeg siger ikke mer;
927+
den findes på en hede,
928+
et sted som ingen ser.
929+
930+
2. I reden er der unger,
931+
og ungerne har dun.
932+
De pipper de har tunger,
933+
og reden er så lun.
934+
935+
3. Og de to gamle lærker,
936+
de flyver tæt omkring.
937+
Jeg tænker nok de mærker,
938+
jeg gør dem ingenting.
939+
940+
4. Jeg lurer bag en slåen.
941+
Der står jeg ganske nær.
942+
Jeg rækker mig på tåen
943+
og holder på mit vejr.
944+
945+
5. For ræven han vil bide
946+
og drengen samle bær.
947+
men ingen skal få vide,
948+
hvor lærkereden er.
949+
)");
950+
StringData dict_value(
951+
R"({"Seven":7, "Six":6, "Points": [1.25, 4.5, 6.75], "Attributes": {"Height": 202, "Weight": 92}})");
952+
953+
Timestamp now(std::chrono::system_clock::now());
954+
auto now_seconds = now.get_seconds();
955+
956+
Group g;
957+
958+
TableRef t = g.add_table_with_primary_key("table", type_ObjectId, "_id", false);
959+
auto col_int = t->add_column(type_Int, "int");
960+
auto col_optint = t->add_column(type_Int, "optint", true);
961+
/* auto col_bool = */ t->add_column(type_Bool, "bool");
962+
auto col_string = t->add_column(type_String, "string");
963+
/* auto col_binary = */ t->add_column(type_Binary, "binary");
964+
auto col_mixed = t->add_column(type_Mixed, "any");
965+
auto col_date = t->add_column(type_Timestamp, "date");
966+
/* auto col_float = */ t->add_column(type_Float, "float");
967+
/* auto col_double = */ t->add_column(type_Double, "double");
968+
/* auto col_decimal = */ t->add_column(type_Decimal, "decimal");
969+
/* auto col_uuid = */ t->add_column(type_UUID, "uuid");
970+
971+
TableRef target = g.add_table_with_primary_key("target", type_Int, "_id", false);
972+
auto col_link = t->add_column(*target, "link");
973+
974+
auto target_key = target->create_object_with_primary_key(1).get_key();
975+
for (size_t i = 0; i < cnt; i++) {
976+
977+
auto o = t->create_object_with_primary_key(ObjectId::gen());
978+
o.set(col_int, uint64_t(0xffff) + i);
979+
o.set(col_optint, uint64_t(0xffff) + (i % 10));
980+
o.set(col_string, string_values[i % string_values.size()]);
981+
o.set(col_date, Timestamp(now_seconds + i, 0));
982+
o.set(col_link, target_key);
983+
}
984+
auto obj = t->create_object_with_primary_key(ObjectId::gen());
985+
obj.set_json(col_mixed, dict_value);
986+
obj.set(col_string, long_string);
987+
g.write(path);
988+
#endif // TEST_READ_UPGRADE_MODE
989+
}
990+
887991
#endif // TEST_GROUP
702 KB
Binary file not shown.
8.14 KB
Binary file not shown.

0 commit comments

Comments
 (0)