parent
3c7b0ea069
commit
f3090c3857
@ -317,6 +317,11 @@ if(BUILD_TESTING)
|
||||
target_link_libraries(object_lifetime_test2 ${LIBS})
|
||||
add_test(NAME Object_Lifetime_Test2 COMMAND object_lifetime_test2)
|
||||
|
||||
add_executable(object_copy_count_test unittests/object_copy_count_test.cpp)
|
||||
target_link_libraries(object_copy_count_test ${LIBS})
|
||||
add_test(NAME Object_Copy_Test COMMAND object_copy_count_test)
|
||||
|
||||
|
||||
add_executable(function_ordering_test unittests/function_ordering_test.cpp)
|
||||
target_link_libraries(function_ordering_test ${LIBS})
|
||||
add_test(NAME Function_Ordering_Test COMMAND function_ordering_test)
|
||||
|
@ -7,8 +7,8 @@ var func = fun(){
|
||||
}
|
||||
|
||||
|
||||
var fut1 := async(func);
|
||||
var fut2 := async(func);
|
||||
var fut1 = async(func);
|
||||
var fut2 = async(func);
|
||||
|
||||
// simply executing without crashing is good enough for this test
|
||||
|
||||
|
80
unittests/object_copy_count_test.cpp
Normal file
80
unittests/object_copy_count_test.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include <chaiscript/utility/utility.hpp>
|
||||
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
Test()
|
||||
{
|
||||
std::cout << "Test()\n";
|
||||
++constructcount();
|
||||
}
|
||||
|
||||
Test(const Test &)
|
||||
{
|
||||
std::cout << "Test(const Test &)\n";
|
||||
++copycount();
|
||||
}
|
||||
|
||||
Test(Test &&)
|
||||
{
|
||||
std::cout << "Test(Test &&)\n";
|
||||
++movecount();
|
||||
}
|
||||
|
||||
~Test()
|
||||
{
|
||||
std::cout << "~Test()\n";
|
||||
++destructcount();
|
||||
}
|
||||
|
||||
static int& constructcount()
|
||||
{
|
||||
static int c = 0;
|
||||
return c;
|
||||
}
|
||||
|
||||
static int& copycount()
|
||||
{
|
||||
static int c = 0;
|
||||
return c;
|
||||
}
|
||||
|
||||
static int& movecount()
|
||||
{
|
||||
static int c = 0;
|
||||
return c;
|
||||
}
|
||||
|
||||
static int& destructcount()
|
||||
{
|
||||
static int c = 0;
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
Test create()
|
||||
{
|
||||
return Test();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module());
|
||||
|
||||
m->add(chaiscript::user_type<Test>(), "Test");
|
||||
m->add(chaiscript::constructor<Test()>(), "Test");
|
||||
m->add(chaiscript::constructor<Test(const Test &)>(), "Test");
|
||||
m->add(chaiscript::fun(&create), "create");
|
||||
|
||||
chaiscript::ChaiScript chai;
|
||||
chai.add(m);
|
||||
|
||||
chai.eval(" { auto i = create(); } ");
|
||||
|
||||
if (Test::destructcount() == 2 && Test::copycount() == 0 && Test::movecount() == 1 && Test::constructcount() == 1)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user