mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-07 01:06:54 +08:00
Add unit tests for inheritance with multiple layers
This commit is contained in:
parent
6b0e0dc7ae
commit
caf4495cff
@ -11,6 +11,8 @@ class TestBaseType
|
|||||||
virtual ~TestBaseType() {}
|
virtual ~TestBaseType() {}
|
||||||
virtual int func() { return 0; }
|
virtual int func() { return 0; }
|
||||||
|
|
||||||
|
int base_only_func() { return -9; }
|
||||||
|
|
||||||
const TestBaseType &constMe() const { return *this; }
|
const TestBaseType &constMe() const { return *this; }
|
||||||
|
|
||||||
int val;
|
int val;
|
||||||
@ -41,11 +43,22 @@ class TestDerivedType : public TestBaseType
|
|||||||
TestDerivedType &operator=(const TestDerivedType &);
|
TestDerivedType &operator=(const TestDerivedType &);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TestMoreDerivedType : public TestDerivedType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~TestMoreDerivedType() {}
|
||||||
|
};
|
||||||
|
|
||||||
boost::shared_ptr<TestBaseType> derived_type_factory()
|
boost::shared_ptr<TestBaseType> derived_type_factory()
|
||||||
{
|
{
|
||||||
return boost::shared_ptr<TestBaseType>(new TestDerivedType());
|
return boost::shared_ptr<TestBaseType>(new TestDerivedType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<TestBaseType> more_derived_type_factory()
|
||||||
|
{
|
||||||
|
return boost::shared_ptr<TestBaseType>(new TestMoreDerivedType());
|
||||||
|
}
|
||||||
|
|
||||||
std::string hello_world()
|
std::string hello_world()
|
||||||
{
|
{
|
||||||
return "Hello World";
|
return "Hello World";
|
||||||
@ -76,6 +89,7 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
|
|||||||
|
|
||||||
m->add(chaiscript::user_type<TestBaseType>(), "TestBaseType");
|
m->add(chaiscript::user_type<TestBaseType>(), "TestBaseType");
|
||||||
m->add(chaiscript::user_type<TestDerivedType>(), "TestDerivedType");
|
m->add(chaiscript::user_type<TestDerivedType>(), "TestDerivedType");
|
||||||
|
m->add(chaiscript::user_type<TestMoreDerivedType>(), "TestMoreDerivedType");
|
||||||
|
|
||||||
m->add(chaiscript::constructor<TestBaseType ()>(), "TestBaseType");
|
m->add(chaiscript::constructor<TestBaseType ()>(), "TestBaseType");
|
||||||
// m->add(chaiscript::constructor<TestBaseType (int)>(), "TestBaseType");
|
// m->add(chaiscript::constructor<TestBaseType (int)>(), "TestBaseType");
|
||||||
@ -85,15 +99,23 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
|
|||||||
m->add(chaiscript::constructor<TestDerivedType ()>(), "TestDerivedType");
|
m->add(chaiscript::constructor<TestDerivedType ()>(), "TestDerivedType");
|
||||||
m->add(chaiscript::constructor<TestDerivedType (const TestDerivedType &)>(), "TestDerivedType");
|
m->add(chaiscript::constructor<TestDerivedType (const TestDerivedType &)>(), "TestDerivedType");
|
||||||
|
|
||||||
|
m->add(chaiscript::constructor<TestMoreDerivedType ()>(), "TestMoreDerivedType");
|
||||||
|
m->add(chaiscript::constructor<TestMoreDerivedType (const TestMoreDerivedType &)>(), "TestMoreDerivedType");
|
||||||
|
|
||||||
|
/// \todo automatic chaining of base classes?
|
||||||
m->add(chaiscript::base_class<TestBaseType, TestDerivedType>());
|
m->add(chaiscript::base_class<TestBaseType, TestDerivedType>());
|
||||||
|
m->add(chaiscript::base_class<TestBaseType, TestMoreDerivedType>());
|
||||||
|
m->add(chaiscript::base_class<TestDerivedType, TestMoreDerivedType>());
|
||||||
|
|
||||||
m->add(chaiscript::fun(&TestDerivedType::derived_only_func), "derived_only_func");
|
m->add(chaiscript::fun(&TestDerivedType::derived_only_func), "derived_only_func");
|
||||||
|
|
||||||
m->add(chaiscript::fun(&derived_type_factory), "derived_type_factory");
|
m->add(chaiscript::fun(&derived_type_factory), "derived_type_factory");
|
||||||
|
m->add(chaiscript::fun(&more_derived_type_factory), "more_derived_type_factory");
|
||||||
|
|
||||||
m->add(chaiscript::fun(&TestBaseType::func), "func");
|
m->add(chaiscript::fun(&TestBaseType::func), "func");
|
||||||
m->add(chaiscript::fun(&TestBaseType::val), "val");
|
m->add(chaiscript::fun(&TestBaseType::val), "val");
|
||||||
m->add(chaiscript::fun(&TestBaseType::const_val), "const_val");
|
m->add(chaiscript::fun(&TestBaseType::const_val), "const_val");
|
||||||
|
m->add(chaiscript::fun(&TestBaseType::base_only_func), "base_only_func");
|
||||||
|
|
||||||
m->add(chaiscript::fun(&get_new_int), "get_new_int");
|
m->add(chaiscript::fun(&get_new_int), "get_new_int");
|
||||||
|
|
||||||
|
|||||||
@ -25,3 +25,11 @@ assert_equal(t.derived_only_func(), 19);
|
|||||||
var d := derived_type_factory();
|
var d := derived_type_factory();
|
||||||
assert_equal(d.derived_only_func(), 19);
|
assert_equal(d.derived_only_func(), 19);
|
||||||
|
|
||||||
|
var t2 = TestMoreDerivedType();
|
||||||
|
assert_equal(t2.derived_only_func(), 19);
|
||||||
|
assert_equal(t2.base_only_func(), -9);
|
||||||
|
|
||||||
|
var md := more_derived_type_factory();
|
||||||
|
assert_equal(md.derived_only_func(), 19);
|
||||||
|
assert_equal(md.base_only_func(), -9);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user