Skip to content

Commit 423dceb

Browse files
committed
Conversion tests and fixes
1 parent 9df55ba commit 423dceb

5 files changed

Lines changed: 812 additions & 6 deletions

File tree

include/xnode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,9 @@ class basic_xnode {
669669
return result;
670670
}
671671

672-
if (!xnode_caster<T, typename value_policy::cast_policy>::cast_to_value(result, const_cast<void **>(&value_), vtable_->type_code_))
672+
if (!xnode_caster<T, typename value_policy::cast_policy>::cast_to_value(result, const_cast<void **>(&value_), vtable_->type_code_)) {
673673
throwWrongCastToValue<T>();
674+
}
674675
return result;
675676
}
676677

include/xnode_long_double.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ class xnode_caster<long double, xnode_ld_cast_policy> : xnode_caster_base {
8383

8484
switch (srcTypeCode) {
8585
case xnode_type_code<double>::value: {
86-
output = static_cast<ValueType>(*reinterpret_cast<double*>(*storage));
86+
output = xnode_get_scalar<double>(storage);
8787
break;
8888
}
8989
case xnode_type_code<float>::value: {
90-
output = static_cast<ValueType>(*reinterpret_cast<float*>(*storage));
90+
output = xnode_get_scalar<float>(storage);
9191
break;
9292
}
9393
case xnode_type_code<long double>::value: {
94-
output = *reinterpret_cast<long double*>(*storage);
94+
output = xnode_get_scalar<long double>(storage);
9595
break;
9696
}
9797
case xnode_type_code<int>::value: {
98-
output = static_cast<ValueType>(*reinterpret_cast<int*>(*storage));
98+
output = xnode_get_scalar<int>(storage);
9999
break;
100100
}
101101
default: {

test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
rm -f build/*
2+
rmdir -p build
3+
14
# Configure
25
cmake -B build
36

test/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ target_link_libraries(xnode_test PRIVATE xnode)
44
# Add test to CTest
55
add_test(NAME xnode_test COMMAND xnode_test)
66

7+
# Add conversion tests
8+
add_executable(xnode_convert_test xnode_convert_test.cpp)
9+
target_link_libraries(xnode_convert_test PRIVATE xnode)
10+
11+
# Add conversion test to CTest
12+
add_test(NAME xnode_convert_test COMMAND xnode_convert_test)
13+
714
# Install the test executable if needed (optional)
8-
install(TARGETS xnode_test
15+
install(TARGETS xnode_test xnode_convert_test
916
RUNTIME DESTINATION bin
1017
OPTIONAL
1118
)

0 commit comments

Comments
 (0)