Files
uLib/src/Vtk/testing/PuppetPropertyTest.cpp
2026-03-23 15:09:35 +00:00

69 lines
2.4 KiB
C++

/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
//////////////////////////////////////////////////////////////////////////////*/
#include "Vtk/uLibVtkInterface.h"
#include "Core/Property.h"
#include <iostream>
#include <cassert>
#include "testing-prototype.h"
using namespace uLib;
using namespace Vtk;
int main() {
BEGIN_TESTING(Puppet Property Registration Test);
std::cout << "Creating Puppet object..." << std::endl;
Puppet p;
// At this point, the Puppet constructor has called ULIB_ACTIVATE_PROPERTIES.
// This should have discovered the members used in Puppet::serialize()
// and registered them as uLib properties.
const auto& props = p.GetProperties();
std::cout << "Total registered properties: " << props.size() << std::endl;
// Verify specific properties exist
Property<double>* opacityProp = nullptr;
Property<double>* colorRProp = nullptr;
for (auto* prop : props) {
std::cout << " - [" << prop->GetTypeName() << "] " << prop->GetName()
<< " = " << prop->GetValueAsString() << std::endl;
if (prop->GetName() == "Opacity") {
opacityProp = dynamic_cast<Property<double>*>(prop);
}
if (prop->GetName() == "ColorR") {
colorRProp = dynamic_cast<Property<double>*>(prop);
}
}
assert(opacityProp != nullptr && "Opacity property not registered!");
assert(colorRProp != nullptr && "ColorR property not registered!");
// Test modification via uLib Property interface
std::cout << "Modifying Opacity via property proxy (0.25)..." << std::endl;
*opacityProp = 0.25;
// Verify the proxy correctly updated the underlying data
assert(opacityProp->Get() == 0.25);
assert(opacityProp->GetValueAsString().find("0.25") != std::string::npos);
std::cout << "Modifying ColorR via property proxy (0.9)..." << std::endl;
*colorRProp = 0.9;
assert(colorRProp->Get() == 0.9);
std::cout << "All Puppet Property Registration Tests PASSED!" << std::endl;
END_TESTING;
}