补全边角
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <semaphore>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <typeinfo>
|
||||
@@ -24,6 +25,15 @@ struct structive::Type_Descriptor<Runtime_Device> {
|
||||
);
|
||||
}
|
||||
};
|
||||
struct Move_Only_Runtime_Device : Property_Object<Move_Only_Runtime_Device> {
|
||||
std::unique_ptr<int> value{std::make_unique<int>(1)};
|
||||
};
|
||||
template <>
|
||||
struct structive::Type_Descriptor<Move_Only_Runtime_Device> {
|
||||
static auto get() {
|
||||
return object<Move_Only_Runtime_Device>(field<&Move_Only_Runtime_Device::value>(key<"value">));
|
||||
}
|
||||
};
|
||||
struct Runtime_Read_Capture {
|
||||
std::size_t calls{};
|
||||
std::size_t index{};
|
||||
@@ -82,6 +92,20 @@ static void test_runtime_metadata_and_results() {
|
||||
REQUIRE(erased.runtime_write("value", typeid(double), &wrong_type) == Runtime_Access_Result::type_mismatch);
|
||||
REQUIRE(erased.runtime_write("missing", typeid(int), &value) == Runtime_Access_Result::unknown_property);
|
||||
}
|
||||
static void test_runtime_copy_write_boundary() {
|
||||
using Schema = type_descriptor_schema_t<Move_Only_Runtime_Device>;
|
||||
using Property = typename Schema::template property_type<0>;
|
||||
static_assert(Property::writable);
|
||||
static_assert(!Property::runtime_copy_writable);
|
||||
Move_Only_Runtime_Device device;
|
||||
device.write<&Move_Only_Runtime_Device::value>(std::make_unique<int>(9));
|
||||
REQUIRE(*device.value == 9);
|
||||
Property_Object_Base& erased = device;
|
||||
std::unique_ptr<int> replacement = std::make_unique<int>(11);
|
||||
REQUIRE(erased.runtime_write("value", typeid(std::unique_ptr<int>), &replacement) == Runtime_Access_Result::unsupported_runtime_write);
|
||||
REQUIRE(*device.value == 9);
|
||||
REQUIRE(*replacement == 11);
|
||||
}
|
||||
static void test_runtime_access_uses_managed_synchronization() {
|
||||
Runtime_Device device;
|
||||
Property_Object_Base& erased = device;
|
||||
@@ -134,6 +158,7 @@ static void test_runtime_read_only_fast_path() {
|
||||
}
|
||||
int main() {
|
||||
test_runtime_metadata_and_results();
|
||||
test_runtime_copy_write_boundary();
|
||||
test_runtime_access_uses_managed_synchronization();
|
||||
test_runtime_read_only_fast_path();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user