Add failing test for non-const shared_ptr &
This commit is contained in:
@@ -114,6 +114,16 @@ std::shared_ptr<TestBaseType> null_factory()
|
|||||||
return std::shared_ptr<TestBaseType>();
|
return std::shared_ptr<TestBaseType>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void update_shared_ptr(std::shared_ptr<TestBaseType> &ptr)
|
||||||
|
{
|
||||||
|
ptr = std::make_shared<TestDerivedType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void nullify_shared_ptr(std::shared_ptr<TestBaseType> &ptr)
|
||||||
|
{
|
||||||
|
ptr = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
std::string hello_world()
|
std::string hello_world()
|
||||||
{
|
{
|
||||||
return "Hello World";
|
return "Hello World";
|
||||||
@@ -209,6 +219,10 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
|
|||||||
m->add(chaiscript::type_conversion<const char *, std::string>());
|
m->add(chaiscript::type_conversion<const char *, std::string>());
|
||||||
m->add(chaiscript::constructor<Type2 (const TestBaseType &)>(), "Type2");
|
m->add(chaiscript::constructor<Type2 (const TestBaseType &)>(), "Type2");
|
||||||
|
|
||||||
|
m->add(chaiscript::fun(&update_shared_ptr), "update_shared_ptr");
|
||||||
|
m->add(chaiscript::fun(&nullify_shared_ptr), "nullify_shared_ptr");
|
||||||
|
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
unittests/shared_ptr_update.chai
Normal file
24
unittests/shared_ptr_update.chai
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
load_module("test_module")
|
||||||
|
|
||||||
|
auto o := null_factory();
|
||||||
|
|
||||||
|
assert_true(o.is_var_null());
|
||||||
|
|
||||||
|
update_shared_ptr(o);
|
||||||
|
|
||||||
|
assert_false(o.is_var_null());
|
||||||
|
assert_true(o.base_only_func() == -9);
|
||||||
|
|
||||||
|
nullify_shared_ptr(o);
|
||||||
|
|
||||||
|
assert_true(o.is_var_null());
|
||||||
|
|
||||||
|
try {
|
||||||
|
o.func();
|
||||||
|
} catch (e) {
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_true(false);
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user