mirror of
https://gitlab.com/splashmapper/splash.git
synced 2026-02-11 22:40:47 +01:00
Fixed RootObject serializing test
This commit is contained in:
@@ -25,8 +25,11 @@ bool BufferObject::deserialize()
|
||||
}
|
||||
|
||||
/*************/
|
||||
void BufferObject::setSerializedObject(SerializedObject&& obj)
|
||||
bool BufferObject::setSerializedObject(SerializedObject&& obj)
|
||||
{
|
||||
if (obj.size() == 0)
|
||||
return false;
|
||||
|
||||
if (_serializedObjectWaitingMutex.try_lock())
|
||||
{
|
||||
_serializedObject = std::move(obj);
|
||||
@@ -38,7 +41,11 @@ void BufferObject::setSerializedObject(SerializedObject&& obj)
|
||||
deserialize();
|
||||
_serializedObjectWaitingMutex.unlock();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*************/
|
||||
|
||||
@@ -151,10 +151,15 @@ class BufferObject : public GraphObject
|
||||
virtual SerializedObject serialize() const = 0;
|
||||
|
||||
/**
|
||||
* Set the next serialized object to deserialize to buffer
|
||||
* Set the next serialized object to deserialize to buffer. Deserialization is
|
||||
* done asynchronously, in a separate thread if the system allows for it. Use
|
||||
* hasSerializedObjectWaiting to check whether a deserialization is waiting
|
||||
* If another object is currently being set for deserialization, the call
|
||||
* to this method will do nothing and return false.
|
||||
* \param obj Serialized object
|
||||
* \return Return true if the object has been set for deserialization, false otherwise
|
||||
*/
|
||||
void setSerializedObject(SerializedObject&& obj);
|
||||
bool setSerializedObject(SerializedObject&& obj);
|
||||
|
||||
/**
|
||||
* Check whether a serialized object is waiting for deserialization
|
||||
|
||||
@@ -192,8 +192,7 @@ bool RootObject::setFromSerializedObject(const std::string& name, SerializedObje
|
||||
auto objectAsBuffer = std::dynamic_pointer_cast<BufferObject>(object);
|
||||
if (objectAsBuffer)
|
||||
{
|
||||
objectAsBuffer->setSerializedObject(std::move(obj));
|
||||
return true;
|
||||
return objectAsBuffer->setSerializedObject(std::move(obj));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -199,7 +199,12 @@ class RootObject : public BaseObject
|
||||
bool set(const std::string& name, const std::string& attrib, const Values& args, bool async = true);
|
||||
|
||||
/**
|
||||
* Set an object from its serialized form. If non existant, it is handled by the handleSerializedObject method.
|
||||
* Set an object from its serialized form. If non existant, it is handled
|
||||
* by the handleSerializedObject method.
|
||||
* Note that if the object exists, this method calls itself
|
||||
* BufferObject::setFromSerializedObject, and that the deserialization is
|
||||
* handled asynchronously. Use BufferObject::hasSerializedObjectWaiting to
|
||||
* check whether a deserialization is waiting.
|
||||
* \param name Object name
|
||||
* \param obj Serialized object
|
||||
* \return Return true if the object has been set
|
||||
|
||||
@@ -67,9 +67,7 @@ TEST_CASE("Testing serialization")
|
||||
auto buffer = BufferObjectMock();
|
||||
auto timestamp = buffer.getTimestamp();
|
||||
|
||||
buffer.setSerializedObject({});
|
||||
while (buffer.hasSerializedObjectWaiting())
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
|
||||
CHECK_NE(timestamp, buffer.getTimestamp());
|
||||
auto result = buffer.setSerializedObject({});
|
||||
CHECK_EQ(result, false);
|
||||
CHECK_EQ(timestamp, buffer.getTimestamp());
|
||||
}
|
||||
|
||||
@@ -136,16 +136,20 @@ TEST_CASE("Testing RootObject serialized object set")
|
||||
auto timestamp = image->getTimestamp();
|
||||
auto result = root.setFromSerializedObject(imageName, SerializedObject());
|
||||
image->update();
|
||||
CHECK_EQ(result, true);
|
||||
CHECK_EQ(result, false);
|
||||
CHECK_EQ(timestamp, image->getTimestamp());
|
||||
|
||||
auto otherName = "otherImage";
|
||||
auto otherImage = std::dynamic_pointer_cast<Image>(root.createObject("image", otherName).lock());
|
||||
otherImage->set(512, 512, 3, ImageBufferSpec::Type::UINT8);
|
||||
otherImage->update();
|
||||
while (otherImage->hasSerializedObjectWaiting())
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
|
||||
result = root.setFromSerializedObject(imageName, otherImage->serialize());
|
||||
while (image->hasSerializedObjectWaiting())
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
|
||||
image->update();
|
||||
CHECK_EQ(result, true);
|
||||
CHECK_NE(timestamp, image->getTimestamp());
|
||||
|
||||
Reference in New Issue
Block a user