Object lifetime specificity test added.
This commit is contained in:
@@ -155,6 +155,10 @@ IF(BUILD_TESTING)
|
|||||||
target_link_libraries(boxed_cast_test ${LIBS})
|
target_link_libraries(boxed_cast_test ${LIBS})
|
||||||
add_test(NAME Boxed_Cast_Test COMMAND boxed_cast_test)
|
add_test(NAME Boxed_Cast_Test COMMAND boxed_cast_test)
|
||||||
|
|
||||||
|
add_executable(object_lifetime_test unittests/object_lifetime_test.cpp)
|
||||||
|
target_link_libraries(object_lifetime_test ${LIBS})
|
||||||
|
add_test(NAME Object_Lifetime_Test COMMAND object_lifetime_test)
|
||||||
|
|
||||||
add_executable(multifile_test unittests/multifile_test_main.cpp unittests/multifile_test_chai.cpp
|
add_executable(multifile_test unittests/multifile_test_main.cpp unittests/multifile_test_chai.cpp
|
||||||
unittests/multifile_test_module.cpp)
|
unittests/multifile_test_module.cpp)
|
||||||
target_link_libraries(multifile_test ${LIBS})
|
target_link_libraries(multifile_test ${LIBS})
|
||||||
|
66
unittests/object_lifetime_test.cpp
Normal file
66
unittests/object_lifetime_test.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#include <chaiscript/utility/utility.hpp>
|
||||||
|
|
||||||
|
class Test
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Test()
|
||||||
|
{
|
||||||
|
++count();
|
||||||
|
}
|
||||||
|
|
||||||
|
Test(const Test &)
|
||||||
|
{
|
||||||
|
++count();
|
||||||
|
}
|
||||||
|
|
||||||
|
~Test()
|
||||||
|
{
|
||||||
|
--count();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int& count()
|
||||||
|
{
|
||||||
|
static int c = 0;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module());
|
||||||
|
|
||||||
|
CHAISCRIPT_CLASS( m,
|
||||||
|
Test,
|
||||||
|
(Test ())
|
||||||
|
(Test (const Test &)),
|
||||||
|
((count))
|
||||||
|
);
|
||||||
|
|
||||||
|
chaiscript::ChaiScript chai;
|
||||||
|
chai.add(m);
|
||||||
|
chai.add(chaiscript::fun(&Test::count), "count");
|
||||||
|
|
||||||
|
int count = chai.eval<int>("count()");
|
||||||
|
|
||||||
|
int count2 = chai.eval<int>("var i = 0; { var t = Test(); } return i;");
|
||||||
|
|
||||||
|
int count3 = chai.eval<int>("var i = 0; { var t = Test(); i = count(); } return i;");
|
||||||
|
|
||||||
|
int count4 = chai.eval<int>("var i = 0; { var t = Test(); { var t2 = Test(); i = count(); } } return i;");
|
||||||
|
|
||||||
|
int count5 = chai.eval<int>("var i = 0; { var t = Test(); { var t2 = Test(); } i = count(); } return i;");
|
||||||
|
|
||||||
|
int count6 = chai.eval<int>("var i = 0; { var t = Test(); { var t2 = Test(); } } i = count(); return i;");
|
||||||
|
|
||||||
|
if (count == 0
|
||||||
|
&& count2 == 0
|
||||||
|
&& count3 == 1
|
||||||
|
&& count4 == 2
|
||||||
|
&& count5 == 1
|
||||||
|
&& count6 == 0)
|
||||||
|
{
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
} else {
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user