test: minor changes, code coverage

This commit is contained in:
Michele Caini
2020-06-19 10:04:38 +02:00
parent 0043e3d623
commit 4e66fb4589
4 changed files with 33 additions and 10 deletions

3
TODO
View File

@@ -28,7 +28,6 @@ Next:
- meta: update doc
- static constexpr -> inline constexpr
- remove internal::find_if
- add meta_handle::operator-> that returns a meta_any * (easier to use directly)
- use a dedicate class template to specialize meta views for a better support to customizations
- remove operator* from meta_any, meta_handle
- add const meta container support to meta any
- meta_any deref fails if operator* returns a temporary

View File

@@ -164,6 +164,8 @@ public:
}
friend void swap(meta_storage &lhs, meta_storage &rhs) {
using std::swap;
if(lhs.steal_fn && rhs.steal_fn) {
meta_storage buffer{};
lhs.steal_fn(buffer, lhs);
@@ -174,12 +176,12 @@ public:
} else if(rhs.steal_fn) {
rhs.steal_fn(lhs, rhs);
} else {
std::swap(lhs.instance, rhs.instance);
swap(lhs.instance, rhs.instance);
}
std::swap(lhs.destroy_fn, rhs.destroy_fn);
std::swap(lhs.copy_fn, rhs.copy_fn);
std::swap(lhs.steal_fn, rhs.steal_fn);
swap(lhs.destroy_fn, rhs.destroy_fn);
swap(lhs.copy_fn, rhs.copy_fn);
swap(lhs.steal_fn, rhs.steal_fn);
}
private:

View File

@@ -504,10 +504,11 @@ public:
* @param rhs A valid meta any object.
*/
friend void swap(meta_any &lhs, meta_any &rhs) {
std::swap(lhs.node, rhs.node);
std::swap(lhs.storage, rhs.storage);
std::swap(lhs.deref, rhs.deref);
std::swap(lhs.cview, rhs.cview);
using std::swap;
swap(lhs.node, rhs.node);
swap(lhs.storage, rhs.storage);
swap(lhs.deref, rhs.deref);
swap(lhs.cview, rhs.cview);
}
private:

View File

@@ -636,6 +636,27 @@ TEST_F(MetaAny, DereferenceOperatorInvalidType) {
ASSERT_FALSE(deref);
}
TEST_F(MetaAny, DereferenceOperatorConstType) {
const int value = 0;
entt::meta_any any{&value};
ASSERT_TRUE(any.type().is_pointer());
ASSERT_TRUE(any.type().is_dereferenceable());
ASSERT_EQ(any.type(), entt::resolve<const int *>());
auto deref = *any;
ASSERT_TRUE(deref);
ASSERT_FALSE(deref.type().is_pointer());
ASSERT_FALSE(deref.type().is_dereferenceable());
ASSERT_EQ(deref.type(), entt::resolve<int>());
deref.cast<int>() = 42;
ASSERT_EQ(*any.cast<const int *>(), 0);
ASSERT_EQ(value, 0);
}
TEST_F(MetaAny, DereferenceOperatorRawPointer) {
int value = 0;
entt::meta_any any{&value};