Blender  V3.3
lib_id_remapper_test.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2022 Blender Foundation. */
3 
4 #include "testing/testing.h"
5 
6 #include "BKE_lib_remap.h"
7 
8 #include "BLI_string.h"
9 
10 #include "DNA_ID.h"
11 
13 
14 TEST(lib_id_remapper, unavailable)
15 {
16  ID id1;
17  ID *idp = &id1;
18 
19  IDRemapper *remapper = BKE_id_remapper_create();
22 
23  BKE_id_remapper_free(remapper);
24 }
25 
26 TEST(lib_id_remapper, not_mappable)
27 {
28  ID *idp = nullptr;
29 
30  IDRemapper *remapper = BKE_id_remapper_create();
33 
34  BKE_id_remapper_free(remapper);
35 }
36 
37 TEST(lib_id_remapper, mapped)
38 {
39  ID id1;
40  ID id2;
41  ID *idp = &id1;
42  BLI_strncpy(id1.name, "OB1", sizeof(id1.name));
43  BLI_strncpy(id2.name, "OB2", sizeof(id2.name));
44 
45  IDRemapper *remapper = BKE_id_remapper_create();
46  BKE_id_remapper_add(remapper, &id1, &id2);
49  EXPECT_EQ(idp, &id2);
50 
51  BKE_id_remapper_free(remapper);
52 }
53 
54 TEST(lib_id_remapper, unassigned)
55 {
56  ID id1;
57  ID *idp = &id1;
58  BLI_strncpy(id1.name, "OB2", sizeof(id1.name));
59 
60  IDRemapper *remapper = BKE_id_remapper_create();
61  BKE_id_remapper_add(remapper, &id1, nullptr);
64  EXPECT_EQ(idp, nullptr);
65 
66  BKE_id_remapper_free(remapper);
67 }
68 
69 TEST(lib_id_remapper, unassign_when_mapped_to_self)
70 {
71  ID id_self;
72  ID id1;
73  ID id2;
74  ID *idp;
75 
76  BLI_strncpy(id_self.name, "OBSelf", sizeof(id1.name));
77  BLI_strncpy(id1.name, "OB1", sizeof(id1.name));
78  BLI_strncpy(id2.name, "OB2", sizeof(id2.name));
79 
80  /* Default mapping behavior. Should just remap to id2. */
81  idp = &id1;
82  IDRemapper *remapper = BKE_id_remapper_create();
83  BKE_id_remapper_add(remapper, &id1, &id2);
85  remapper, &idp, ID_REMAP_APPLY_UNMAP_WHEN_REMAPPING_TO_SELF, &id_self);
87  EXPECT_EQ(idp, &id2);
88 
89  /* Default mapping behavior. Should unassign. */
90  idp = &id1;
91  BKE_id_remapper_clear(remapper);
92  BKE_id_remapper_add(remapper, &id1, nullptr);
94  remapper, &idp, ID_REMAP_APPLY_UNMAP_WHEN_REMAPPING_TO_SELF, &id_self);
96  EXPECT_EQ(idp, nullptr);
97 
98  /* Unmap when remapping to self behavior. Should unassign. */
99  idp = &id1;
100  BKE_id_remapper_clear(remapper);
101  BKE_id_remapper_add(remapper, &id1, &id_self);
103  remapper, &idp, ID_REMAP_APPLY_UNMAP_WHEN_REMAPPING_TO_SELF, &id_self);
105  EXPECT_EQ(idp, nullptr);
106  BKE_id_remapper_free(remapper);
107 }
108 
109 } // namespace blender::bke::id::remapper::tests
IDRemapperApplyResult BKE_id_remapper_apply_ex(const struct IDRemapper *id_remapper, struct ID **r_id_ptr, IDRemapperApplyOptions options, struct ID *id_self)
IDRemapperApplyResult
@ ID_REMAP_RESULT_SOURCE_REMAPPED
@ ID_REMAP_RESULT_SOURCE_UNASSIGNED
@ ID_REMAP_RESULT_SOURCE_NOT_MAPPABLE
@ ID_REMAP_RESULT_SOURCE_UNAVAILABLE
void BKE_id_remapper_add(struct IDRemapper *id_remapper, struct ID *old_id, struct ID *new_id)
void BKE_id_remapper_clear(struct IDRemapper *id_remapper)
@ ID_REMAP_APPLY_UNMAP_WHEN_REMAPPING_TO_SELF
@ ID_REMAP_APPLY_DEFAULT
IDRemapperApplyResult BKE_id_remapper_apply(const struct IDRemapper *id_remapper, struct ID **r_id_ptr, IDRemapperApplyOptions options)
struct IDRemapper * BKE_id_remapper_create(void)
void BKE_id_remapper_free(struct IDRemapper *id_remapper)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
ID and Library types, which are fundamental for sdna.
TEST(lib_id_remapper, unavailable)
Definition: DNA_ID.h:368
char name[66]
Definition: DNA_ID.h:378