Files
uLib/src/Core/testing/PropertyGroupingTest.cpp
2026-03-26 23:13:43 +00:00

79 lines
2.2 KiB
C++

#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include "Core/Object.h"
#include "Core/Property.h"
using namespace uLib;
struct Nested {
float x = 1.0f;
float y = 2.0f;
ULIB_SERIALIZE_ACCESS
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & HRP(x);
ar & HRP(y);
}
};
class GroupObject : public Object {
uLibTypeMacro(GroupObject, Object)
public:
Nested position;
Nested orientation;
float weight = 50.0f;
ULIB_SERIALIZE_ACCESS
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & boost::serialization::make_nvp("Position", position);
ar & boost::serialization::make_nvp("Orientation", orientation);
ar & HRP(weight);
}
};
int main() {
std::cout << "Testing Property Grouping..." << std::endl;
GroupObject obj;
ULIB_ACTIVATE_PROPERTIES(obj);
auto props = obj.GetProperties();
std::cout << "Registered " << props.size() << " properties." << std::endl;
for (auto* p : props) {
std::cout << "Prop: " << p->GetName()
<< " Group: " << p->GetGroup()
<< " Qualified: " << p->GetQualifiedName() << std::endl;
}
// Check if nested properties are registered
PropertyBase* p1 = obj.GetProperty("Position.x");
PropertyBase* p2 = obj.GetProperty("Position.y");
PropertyBase* p3 = obj.GetProperty("Orientation.x");
PropertyBase* p4 = obj.GetProperty("Orientation.y");
PropertyBase* p5 = obj.GetProperty("weight");
assert(p1 != nullptr && "Position.x not found");
assert(p2 != nullptr && "Position.y not found");
assert(p3 != nullptr && "Orientation.x not found");
assert(p4 != nullptr && "Orientation.y not found");
assert(p5 != nullptr && "weight not found");
assert(p1->GetGroup() == "Position");
assert(p2->GetGroup() == "Position");
assert(p3->GetGroup() == "Orientation");
assert(p4->GetGroup() == "Orientation");
assert(p5->GetGroup() == "");
assert(p1->GetQualifiedName() == "Position.x");
assert(p5->GetQualifiedName() == "weight");
std::cout << "Property Grouping Tests PASSED!" << std::endl;
return 0;
}