8 #include <framework/datastore/StoreArray.h>
9 #include <framework/dataobjects/EventMetaData.h>
10 #include <framework/dataobjects/ProfileInfo.h>
11 #include <framework/datastore/RelationsObject.h>
12 #include <framework/utilities/TestHelpers.h>
14 #include <gtest/gtest.h>
21 class RelationsObjectTest :
public ::testing::Test {
26 evtData.registerInDataStore();
27 profileData.registerInDataStore();
28 relObjData.registerInDataStore();
30 for (
int i = 0; i < 10; ++i) {
32 profileData.appendNew();
33 relObjData.appendNew();
38 void TearDown()
override
40 DataStore::Instance().reset();
51 relObjData.registerRelationTo(profileData);
52 DataStore::Instance().setInitializeActive(
false);
54 (relObjData)[0]->addRelationTo((profileData)[0], -42.0);
58 EXPECT_TRUE(rels.
size() == 1);
59 EXPECT_TRUE(rels.
object(0) == (profileData)[0]);
60 EXPECT_DOUBLE_EQ(rels.
weight(0), -42.0);
61 EXPECT_EQ(0u, relObjData[1]->getRelationsTo<ProfileInfo>().size());
62 EXPECT_EQ(0u, relObjData[0]->getRelationsFrom<ProfileInfo>().size());
63 EXPECT_EQ(1u, relObjData[0]->getRelationsWith<ProfileInfo>().size());
66 EXPECT_TRUE(profileData[0] == relObjData[0]->getRelatedTo<ProfileInfo>());
67 EXPECT_TRUE(
nullptr == relObjData[1]->getRelatedTo<ProfileInfo>());
68 EXPECT_TRUE(
nullptr == relObjData[0]->getRelatedFrom<ProfileInfo>());
69 EXPECT_TRUE(profileData[0] == relObjData[0]->getRelated<ProfileInfo>());
72 EXPECT_TRUE(std::make_pair(profileData[0], -42.0f) == relObjData[0]->getRelatedToWithWeight<ProfileInfo>());
74 EXPECT_TRUE(std::make_pair(profileNullPtr, 1.0f) == relObjData[1]->getRelatedToWithWeight<ProfileInfo>());
75 EXPECT_TRUE(std::make_pair(profileNullPtr, 1.0f) == relObjData[0]->getRelatedFromWithWeight<ProfileInfo>());
76 EXPECT_TRUE(std::make_pair(profileData[0], -42.0f) == relObjData[0]->getRelatedWithWeight<ProfileInfo>());
80 (relObjData)[0]->addRelationTo(
static_cast<TObject*
>(
nullptr));
81 (relObjData)[0]->addRelationTo(
static_cast<ProfileInfo*
>(
nullptr));
85 EXPECT_B2FATAL((relObjData)[0]->addRelationTo(¬InArray));
89 TEST_F(RelationsObjectTest, IndexUpdating)
91 relObjData.registerRelationTo(profileData);
92 DataStore::Instance().setInitializeActive(
false);
95 EXPECT_FALSE((relObjData)[0]->getRelated<ProfileInfo>() !=
nullptr);
97 (relObjData)[0]->addRelationTo((profileData)[0], -42.0);
100 EXPECT_TRUE((relObjData)[0]->getRelated<ProfileInfo>() !=
nullptr);
103 EXPECT_FALSE((relObjData)[1]->getRelated<ProfileInfo>() !=
nullptr);
105 (relObjData)[1]->addRelationTo((profileData)[0], -42.0);
108 EXPECT_TRUE((relObjData)[1]->getRelated<ProfileInfo>() !=
nullptr);
112 TEST_F(RelationsObjectTest, RelationsObjectArrayIndex)
114 for (
int i = 0; i < relObjData.getEntries(); i++) {
115 EXPECT_TRUE((relObjData)[i]->getArrayName() == relObjData.getName());
116 EXPECT_TRUE((relObjData)[i]->getArrayIndex() == i);
125 TEST_F(RelationsObjectTest, DuplicateRelations)
127 evtData.registerRelationTo(relObjData);
128 relObjData.registerRelationTo(evtData);
129 DataStore::Instance().setInitializeActive(
false);
132 DataStore::Instance().addRelationFromTo((evtData)[0], (relObjData)[1], 1.0);
133 DataStore::Instance().addRelationFromTo((evtData)[0], (relObjData)[1], 2.0);
138 EXPECT_EQ(2u, rels1.
size());
142 EXPECT_FLOAT_EQ(1.0, rels1.
weight(0));
143 EXPECT_FLOAT_EQ(2.0, rels1.
weight(1));
144 EXPECT_FLOAT_EQ(1.0, relObjData[1]->getRelatedFromWithWeight<EventMetaData>().second);
148 DataStore::Instance().addRelationFromTo((relObjData)[1], (evtData)[0], 1.0);
151 EXPECT_EQ(2u, rels2.
size());
154 EXPECT_EQ(3u, rels3.
size());
156 for (
int i = 0; i < (int)rels3.
size(); i++) {
159 EXPECT_DOUBLE_EQ(sum, 1.0 + 1.0 + 2.0);
162 TEST_F(RelationsObjectTest, RelationsToSameArray)
164 relObjData.registerRelationTo(relObjData);
165 DataStore::Instance().setInitializeActive(
false);
167 relObjData[0]->addRelationTo(relObjData[1]);
168 EXPECT_TRUE(relObjData[0] == relObjData[1]->getRelated<RelationsObject>());
169 EXPECT_TRUE(relObjData[0] == relObjData[1]->getRelatedFrom<RelationsObject>());
170 EXPECT_TRUE(relObjData[1] == relObjData[0]->getRelated<RelationsObject>());
171 EXPECT_TRUE(relObjData[1] == relObjData[0]->getRelatedTo<RelationsObject>());
172 EXPECT_TRUE(
nullptr == relObjData[2]->getRelated<RelationsObject>());
173 EXPECT_TRUE(
nullptr == relObjData[2]->getRelatedFrom<RelationsObject>());
174 EXPECT_TRUE(
nullptr == relObjData[2]->getRelatedTo<RelationsObject>());
176 EXPECT_TRUE(
nullptr == relObjData[1]->getRelatedTo<RelationsObject>());
177 EXPECT_TRUE(
nullptr == relObjData[0]->getRelatedFrom<RelationsObject>());
180 relObjData[3]->addRelationTo(relObjData[3]);
181 EXPECT_TRUE(relObjData[3] == relObjData[3]->getRelated<RelationsObject>());
182 EXPECT_TRUE(relObjData[3] == relObjData[3]->getRelatedFrom<RelationsObject>());
183 EXPECT_TRUE(relObjData[3] == relObjData[3]->getRelatedTo<RelationsObject>());
186 TEST_F(RelationsObjectTest, ModifyRelations)
188 relObjData.registerRelationTo(profileData);
189 DataStore::Instance().setInitializeActive(
false);
191 (relObjData)[0]->addRelationTo((profileData)[0], -42.0);
195 EXPECT_DOUBLE_EQ(rels.
weight(0), -42.0);
197 EXPECT_DOUBLE_EQ(rels.
weight(0), -3.0);
199 EXPECT_DOUBLE_EQ(rels2.
weight(0), -3.0);
202 EXPECT_EQ(1u, relObjData[0]->getRelationsTo<ProfileInfo>().size());
203 EXPECT_EQ(1u, relObjData[0]->getRelationsWith<ProfileInfo>().size());
205 EXPECT_EQ(0u, rels2.
size());
206 EXPECT_EQ(0u, relObjData[0]->getRelationsTo<ProfileInfo>().size());
207 EXPECT_EQ(0u, relObjData[0]->getRelationsWith<ProfileInfo>().size());
211 TEST_F(RelationsObjectTest, NamedRelationsWithInvalidName)
213 const std::string relationName =
"ExtraRelation WithSpaceInName";
214 EXPECT_B2FATAL(relObjData.registerRelationTo(profileData, DataStore::c_Event, DataStore::c_WriteOut, relationName));
218 TEST_F(RelationsObjectTest, NamedRelations)
220 const std::string relationName =
"ExtraRelation";
221 relObjData.registerRelationTo(profileData, DataStore::c_Event, DataStore::c_WriteOut, relationName);
222 DataStore::Instance().setInitializeActive(
false);
225 EXPECT_TRUE(relObjData.hasRelationTo(profileData, DataStore::c_Event, relationName));
226 EXPECT_FALSE(profileData.hasRelationTo(relObjData, DataStore::c_Event, relationName));
227 EXPECT_FALSE(profileData.hasRelationTo(evtData, DataStore::c_Event, relationName));
228 EXPECT_FALSE(relObjData.hasRelationTo(profileData));
229 EXPECT_FALSE(profileData.hasRelationTo(relObjData));
231 (relObjData)[0]->addRelationTo((profileData)[0], -42.0, relationName);
235 EXPECT_TRUE(rels.
size() == 1);
236 EXPECT_TRUE(rels.
object(0) == (profileData)[0]);
237 EXPECT_DOUBLE_EQ(rels.
weight(0), -42.0);
238 EXPECT_EQ(0u, relObjData[1]->getRelationsTo<ProfileInfo>(
"", relationName).size());
239 EXPECT_EQ(0u, relObjData[0]->getRelationsFrom<ProfileInfo>(
"", relationName).size());
240 EXPECT_EQ(1u, relObjData[0]->getRelationsWith<ProfileInfo>(
"", relationName).size());
243 EXPECT_TRUE(profileData[0] == relObjData[0]->getRelatedTo<ProfileInfo>(
"", relationName));
244 EXPECT_TRUE(
nullptr == relObjData[1]->getRelatedTo<ProfileInfo>(
"", relationName));
245 EXPECT_TRUE(
nullptr == relObjData[0]->getRelatedFrom<ProfileInfo>(
"", relationName));
246 EXPECT_TRUE(profileData[0] == relObjData[0]->getRelated<ProfileInfo>(
"", relationName));
249 EXPECT_TRUE(std::make_pair(profileData[0], -42.0f) == relObjData[0]->getRelatedToWithWeight<ProfileInfo>(
"", relationName));
251 EXPECT_TRUE(std::make_pair(profileNullPtr, 1.0f) == relObjData[1]->getRelatedToWithWeight<ProfileInfo>(
"", relationName));
252 EXPECT_TRUE(std::make_pair(profileNullPtr, 1.0f) == relObjData[0]->getRelatedFromWithWeight<ProfileInfo>(
"", relationName));
253 EXPECT_TRUE(std::make_pair(profileData[0], -42.0f) == relObjData[0]->getRelatedWithWeight<ProfileInfo>(
"", relationName));
258 DataStore::Instance().getRelationsWith(DataStore::c_FromSide, (relObjData)[0], storeEntry, index,
259 TObject::Class(),
"ALL",
"");
262 (relObjData)[0]->addRelationTo(
static_cast<TObject*
>(
nullptr), 1.0, relationName);
263 (relObjData)[0]->addRelationTo(
static_cast<ProfileInfo*
>(
nullptr), 1.0, relationName);
267 EXPECT_B2FATAL((relObjData)[0]->addRelationTo(¬InArray, 1.0, relationName));
Store execution time and memory usage.
Class for type safe access to objects that are referred to in relations.
void setWeight(int index, float weight)
Set a new weight for the given relation.
size_t size() const
Get number of relations.
void remove(int index)
Remove relation at given index.
T * object(int index) const
Get object with index.
float weight(int index) const
Get weight with index.
Defines interface for accessing relations of objects in StoreArray.
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
Accessor to arrays stored in the data store.
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
Abstract base class for different kinds of events.
Wraps a stored array/object, stored under unique (name, durability) key.