diff options
author | Bastien Montagne <bastien@blender.org> | 2022-07-27 12:21:18 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2022-07-27 12:22:48 +0300 |
commit | 7324f32a946fe8899973a559186266cab9a9cfdf (patch) | |
tree | 4278aafea9aef7d5a07c82a5979dc38ac23c82ea /source/blender | |
parent | 18dc611b401690c477a97b7d74f4c666c9b41e42 (diff) |
ID namemap tests: Use consistency check, fix an issue.
Massively use the new consistency check in namemap regression tests, and
fix an issue with library data tests revealed by those checks.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/lib_id_test.cc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/lib_id_test.cc b/source/blender/blenkernel/intern/lib_id_test.cc index ea3f5395f1f..62066204227 100644 --- a/source/blender/blenkernel/intern/lib_id_test.cc +++ b/source/blender/blenkernel/intern/lib_id_test.cc @@ -116,6 +116,8 @@ TEST(lib_id_main_unique_name, local_ids_1) ID *id_b = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "OB_B")); test_lib_id_main_sort_check_order({id_a, id_b, id_c}); + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); + change_name(ctx.bmain, id_c, "OB_A"); EXPECT_STREQ(id_c->name + 2, "OB_A.001"); @@ -123,6 +125,8 @@ TEST(lib_id_main_unique_name, local_ids_1) EXPECT_TRUE(ctx.bmain->objects.first == id_a); EXPECT_TRUE(ctx.bmain->objects.last == id_b); test_lib_id_main_sort_check_order({id_a, id_c, id_b}); + + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); } TEST(lib_id_main_unique_name, linked_ids_1) @@ -136,6 +140,8 @@ TEST(lib_id_main_unique_name, linked_ids_1) ID *id_a = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "OB_A")); ID *id_b = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "OB_B")); + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); + change_lib(ctx.bmain, id_a, lib_a); id_sort_by_name(&ctx.bmain->objects, id_a, nullptr); change_lib(ctx.bmain, id_b, lib_a); @@ -148,6 +154,8 @@ TEST(lib_id_main_unique_name, linked_ids_1) EXPECT_TRUE(ctx.bmain->objects.last == id_b); test_lib_id_main_sort_check_order({id_c, id_a, id_b}); + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); + change_lib(ctx.bmain, id_b, lib_b); id_sort_by_name(&ctx.bmain->objects, id_b, nullptr); change_name(ctx.bmain, id_b, "OB_A"); @@ -156,6 +164,8 @@ TEST(lib_id_main_unique_name, linked_ids_1) EXPECT_TRUE(ctx.bmain->objects.first == id_c); EXPECT_TRUE(ctx.bmain->objects.last == id_b); test_lib_id_main_sort_check_order({id_c, id_a, id_b}); + + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); } TEST(lib_id_main_unique_name, ids_sorted_by_default) @@ -167,12 +177,16 @@ TEST(lib_id_main_unique_name, ids_sorted_by_default) ID *id_baz = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "Baz")); ID *id_yes = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "Yes")); test_lib_id_main_sort_check_order({id_bar, id_baz, id_foo, id_yes}); + + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); } static ID *add_id_in_library(Main *bmain, const char *name, Library *lib) { ID *id = static_cast<ID *>(BKE_id_new(bmain, ID_OB, name)); + BKE_main_namemap_remove_name(bmain, id, id->name + 2); id->lib = lib; + BKE_main_namemap_get_name(bmain, id, id->name + 2); id_sort_by_name(&bmain->objects, id, nullptr); return id; } @@ -195,6 +209,8 @@ TEST(lib_id_main_unique_name, ids_sorted_by_default_with_libraries) ID *id_yes = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "Yes")); test_lib_id_main_sort_check_order({id_bar, id_baz, id_foo, id_yes, id_l1a, id_l1c, id_l2b}); + + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); } TEST(lib_id_main_unique_name, name_too_long_handling) @@ -211,6 +227,8 @@ TEST(lib_id_main_unique_name, name_too_long_handling) EXPECT_STREQ(id_a->name + 2, "Long_Name_That_Does_Not_Fit_Into_Max_Name_Limit_And_Should_Get_"); EXPECT_STREQ(id_b->name + 2, "Another_Long_Name_That_Does_Not_Fit_And_Has_A_Number_Suffix.123"); EXPECT_STREQ(id_c->name + 2, "Name_That_Has_Too_Long_Number_Suffix.1234567890"); /* Unchanged */ + + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); } TEST(lib_id_main_unique_name, create_equivalent_numeric_suffixes) @@ -244,6 +262,8 @@ TEST(lib_id_main_unique_name, create_equivalent_numeric_suffixes) EXPECT_STREQ(id_j->name + 2, "Foo..001"); EXPECT_STREQ(id_k->name + 2, "Foo..000"); + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); + /* Now create their exact duplicates again, and check what happens. */ id_a = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "Foo.123")); id_b = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "Foo.000")); @@ -268,6 +288,8 @@ TEST(lib_id_main_unique_name, create_equivalent_numeric_suffixes) EXPECT_STREQ(id_i->name + 2, "Foo...001"); EXPECT_STREQ(id_j->name + 2, "Foo..003"); EXPECT_STREQ(id_k->name + 2, "Foo..004"); + + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); } TEST(lib_id_main_unique_name, zero_suffix_is_never_assigned) @@ -283,6 +305,8 @@ TEST(lib_id_main_unique_name, zero_suffix_is_never_assigned) EXPECT_STREQ(id_002->name + 2, "Foo.002"); EXPECT_STREQ(id_001->name + 2, "Foo.001"); EXPECT_STREQ(id_003->name + 2, "Foo.003"); + + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); } TEST(lib_id_main_unique_name, remove_after_dup_get_original_name) @@ -296,8 +320,12 @@ TEST(lib_id_main_unique_name, remove_after_dup_get_original_name) EXPECT_STREQ(id_b->name + 2, "Foo.001"); BKE_id_free(ctx.bmain, id_a); + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); + id_a = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "Foo")); EXPECT_STREQ(id_a->name + 2, "Foo"); + + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); } TEST(lib_id_main_unique_name, name_number_suffix_assignment) @@ -316,11 +344,15 @@ TEST(lib_id_main_unique_name, name_number_suffix_assignment) EXPECT_STREQ(ids[1]->name + 2, "Foo.001"); EXPECT_STREQ(ids[total_object_count / 2 - 1]->name + 2, "Foo.599"); + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); + /* Free some of the objects. */ BKE_id_free(ctx.bmain, ids[10]); BKE_id_free(ctx.bmain, ids[20]); BKE_id_free(ctx.bmain, ids[30]); + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); + /* Create objects again; they should get suffixes that were just free'd up. */ ID *id_010 = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "Foo")); EXPECT_STREQ(id_010->name + 2, "Foo.010"); @@ -335,6 +367,8 @@ TEST(lib_id_main_unique_name, name_number_suffix_assignment) ID *id_600 = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "Foo")); EXPECT_STREQ(id_600->name + 2, "Foo.600"); + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); + /* Max possible numeric suffix. */ ID *id_max = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "Foo.999999999")); EXPECT_STREQ(id_max->name + 2, "Foo.999999999"); @@ -342,6 +376,8 @@ TEST(lib_id_main_unique_name, name_number_suffix_assignment) ID *id_max1 = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "Foo.999999999")); EXPECT_STREQ(id_max1->name + 2, "Foo.601"); + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); + /* Now create the rest of objects, to use all the suffixes up to 1k. * Once all the ones up to 1k are used, the logic will fall back to * "use largest number seen + 1", but the largest one is already the max @@ -358,6 +394,8 @@ TEST(lib_id_main_unique_name, name_number_suffix_assignment) EXPECT_STREQ(id_fo179->name + 2, "Fo.179"); ID *id_fo180 = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "Foo.999999999")); EXPECT_STREQ(id_fo180->name + 2, "Fo.180"); + + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); } TEST(lib_id_main_unique_name, renames_with_duplicates) @@ -372,6 +410,8 @@ TEST(lib_id_main_unique_name, renames_with_duplicates) EXPECT_STREQ(id_b->name + 2, "Foo.001"); EXPECT_STREQ(id_c->name + 2, "Bar"); + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); + BKE_libblock_rename(ctx.bmain, id_a, "Foo.002"); EXPECT_STREQ(id_a->name + 2, "Foo.002"); BKE_libblock_rename(ctx.bmain, id_b, "Bar"); @@ -380,6 +420,8 @@ TEST(lib_id_main_unique_name, renames_with_duplicates) EXPECT_STREQ(id_c->name + 2, "Foo"); BKE_libblock_rename(ctx.bmain, id_b, "Bar"); EXPECT_STREQ(id_b->name + 2, "Bar"); + + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); } TEST(lib_id_main_unique_name, names_are_unique_per_id_type) @@ -393,6 +435,8 @@ TEST(lib_id_main_unique_name, names_are_unique_per_id_type) EXPECT_STREQ(id_a->name + 2, "Foo"); EXPECT_STREQ(id_b->name + 2, "Foo"); /* Different types (OB & CA) can have the same name. */ EXPECT_STREQ(id_c->name + 2, "Foo.001"); + + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); } TEST(lib_id_main_unique_name, name_huge_number_suffix) @@ -406,6 +450,8 @@ TEST(lib_id_main_unique_name, name_huge_number_suffix) /* Now create with the same name again: should get 001 suffix. */ ID *id_b = static_cast<ID *>(BKE_id_new(ctx.bmain, ID_OB, "SuperLong.1234567890")); EXPECT_STREQ(id_b->name + 2, "SuperLong.001"); + + EXPECT_TRUE(BKE_main_namemap_validate(ctx.bmain)); } } // namespace blender::bke::tests |