mirror of
https://github.com/nasa/trick.git
synced 2024-12-20 13:43:10 +00:00
Extended unit test to include allocatin gin the input processor
This commit is contained in:
parent
43253a2741
commit
91caad9ce8
@ -36,7 +36,7 @@ In the case that a TrickTypeToString<T> for some type T exist, then this functio
|
|||||||
*/
|
*/
|
||||||
template<typename T, typename ...Args>
|
template<typename T, typename ...Args>
|
||||||
typename std::enable_if<Trick::has_getname<T>::value, T*>::type
|
typename std::enable_if<Trick::has_getname<T>::value, T*>::type
|
||||||
tmm_alloc_args(Args&&... args, T* address)
|
tmm_alloc_args(T* address, Args&&... args)
|
||||||
{
|
{
|
||||||
return new (address) T(std::forward<Args>(args)...);
|
return new (address) T(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,7 @@ trick.exec_set_freeze_command(True)
|
|||||||
|
|
||||||
import trick
|
import trick
|
||||||
|
|
||||||
# Test
|
|
||||||
EXPECT_EQ(atwargs_1.some_int, 5)
|
|
||||||
EXPECT_EQ(atwargs_1.some_double, 10.0)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import math
|
import math
|
||||||
from trick.unit_test import *
|
from trick.unit_test import *
|
||||||
|
|
||||||
def test():
|
def test_single_alloc():
|
||||||
test_suite = "AllocatingUserDefinedTypes"
|
test_suite = "AllocatingUserDefinedTypes"
|
||||||
|
|
||||||
test_case = "type_AllocTestWithArguments"
|
test_case = "type_AllocTestWithArguments"
|
||||||
@ -20,13 +20,53 @@ def test():
|
|||||||
TRICK_EXPECT_EQ(alloc_test.atwargs_4.some_int, 4, test_case, test_suite)
|
TRICK_EXPECT_EQ(alloc_test.atwargs_4.some_int, 4, test_case, test_suite)
|
||||||
TRICK_EXPECT_NEAR(alloc_test.atwargs_4.some_double, 8.0, 1e-6, test_case, test_suite)
|
TRICK_EXPECT_NEAR(alloc_test.atwargs_4.some_double, 8.0, 1e-6, test_case, test_suite)
|
||||||
|
|
||||||
|
def test_placement_new():
|
||||||
|
test_suite = "AllocatingUserDefinedTypes"
|
||||||
|
test_case = "placement_new"
|
||||||
|
#
|
||||||
|
TRICK_EXPECT_EQ(alloc_test.atwargs_5.some_int, 4, test_case, test_suite)
|
||||||
|
TRICK_EXPECT_NEAR(alloc_test.atwargs_5.some_double, 8.0, 1e-6, test_case, test_suite)
|
||||||
|
|
||||||
|
|
||||||
|
def test_python_alloc():
|
||||||
|
test_suite = "AllocatingUserDefinedTypes"
|
||||||
|
test_case = "IP_allocs"
|
||||||
|
|
||||||
|
some_str = "test_str"
|
||||||
|
|
||||||
|
#Default constructor
|
||||||
|
alloc_1 = trick.AllocTestWithArguments()
|
||||||
|
#alloc_1.thisown = 0
|
||||||
|
TRICK_EXPECT_EQ(alloc_1.some_int, 0, test_case, test_suite)
|
||||||
|
TRICK_EXPECT_NEAR(alloc_1.some_double, 0, 1e-6, test_case, test_suite)
|
||||||
|
|
||||||
|
alloc_2 = trick.AllocTestWithArguments(5, 10.0, TMMName="Alloc2")
|
||||||
|
|
||||||
|
TRICK_EXPECT_EQ(alloc_2.some_int, 5, test_case, test_suite)
|
||||||
|
TRICK_EXPECT_NEAR(alloc_2.some_double, 10.0, 1e-6, test_case, test_suite)
|
||||||
|
|
||||||
|
#Constructor: AllocTestWithArguments::AllocTestWithArguments(int in_int, double in_double, const char* a_name)
|
||||||
|
alloc_3 = trick.AllocTestWithArguments(5, 10.0, some_str)
|
||||||
|
#alloc_3.thisown = 0
|
||||||
|
TRICK_EXPECT_EQ(alloc_3.some_int, 5, test_case, test_suite)
|
||||||
|
TRICK_EXPECT_NEAR(alloc_3.some_double, 10.0, 1e-6, test_case, test_suite)
|
||||||
|
|
||||||
|
#AllocTestWithArguments::AllocTestWithArguments(int in_int, double in_double, const char* a_name)
|
||||||
|
alloc_4 = trick.AllocTestWithArguments(5, 10.0, some_str)
|
||||||
|
#alloc_4.thisown = 0
|
||||||
|
TRICK_EXPECT_EQ(alloc_4.some_int, 5, test_case, test_suite)
|
||||||
|
TRICK_EXPECT_NEAR(alloc_4.some_double, 10.0, 1e-6, test_case, test_suite)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
trick_utest.unit_tests.enable()
|
trick_utest.unit_tests.enable()
|
||||||
trick_utest.unit_tests.set_file_name( os.getenv("TRICK_HOME") + "/trick_test/SIM_tmm_alloc_args.xml" )
|
trick_utest.unit_tests.set_file_name( os.getenv("TRICK_HOME") + "/trick_test/SIM_tmm_alloc_args.xml" )
|
||||||
trick_utest.unit_tests.set_test_name( "TMMAllocWithArgsTest" )
|
trick_utest.unit_tests.set_test_name( "TMMAllocWithArgsTest" )
|
||||||
|
|
||||||
trick.add_read(2.0, """test()""")
|
trick.add_read(2.0, """test_single_alloc()""")
|
||||||
|
trick.add_read(2.0, """test_placement_new()""")
|
||||||
|
trick.add_read(2.0, """test_python_alloc()""")
|
||||||
|
|
||||||
|
|
||||||
trick.stop(5.0)
|
trick.stop(5.0)
|
||||||
|
|
||||||
|
@ -53,15 +53,13 @@ class AllocTestSimObject : public Trick::SimObject {
|
|||||||
|
|
||||||
atwargs_4 = tmm_alloc_args<AllocTestWithArguments>(&test_int, test_double, "test_string");
|
atwargs_4 = tmm_alloc_args<AllocTestWithArguments>(&test_int, test_double, "test_string");
|
||||||
|
|
||||||
|
atwargs_5 = new AllocTestWithArguments();
|
||||||
|
|
||||||
|
atwargs_5 = tmm_alloc_args<AllocTestWithArguments>( atwargs_5, &test_int, test_double, "test_string");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AllocTestSimObject alloc_test ;
|
AllocTestSimObject alloc_test ;
|
@ -4,7 +4,8 @@
|
|||||||
AllocTestWithArguments::AllocTestWithArguments()
|
AllocTestWithArguments::AllocTestWithArguments()
|
||||||
:
|
:
|
||||||
some_int(0),
|
some_int(0),
|
||||||
some_double(0.0)
|
some_double(0.0),
|
||||||
|
some_string("")
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -13,36 +14,60 @@ some_double(0.0)
|
|||||||
AllocTestWithArguments::AllocTestWithArguments(int* in_int, double& in_double, std::string in_string)
|
AllocTestWithArguments::AllocTestWithArguments(int* in_int, double& in_double, std::string in_string)
|
||||||
:
|
:
|
||||||
some_int(*in_int),
|
some_int(*in_int),
|
||||||
some_double(in_double)
|
some_double(in_double),
|
||||||
|
some_string(in_string)
|
||||||
{
|
{
|
||||||
std::cout << in_string << "\nn";
|
//std::cout << in_string << "\nn";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AllocTestWithArguments::AllocTestWithArguments(int* in_int, double *in_double, std::string &a_name)
|
AllocTestWithArguments::AllocTestWithArguments(int* in_int, double *in_double, std::string &a_name)
|
||||||
:
|
:
|
||||||
some_int(*in_int),
|
some_int(*in_int),
|
||||||
some_double(*in_double)
|
some_double(*in_double),
|
||||||
|
some_string(a_name)
|
||||||
{
|
{
|
||||||
std::cout << "AllocTestWithArguments constructor with: \n";
|
//std::cout << "AllocTestWithArguments constructor with: \n";
|
||||||
std::cout << a_name << std::endl;
|
//std::cout << a_name << std::endl;
|
||||||
std::cout << "in_int: " << in_int << "\n";
|
//std::cout << "in_int: " << in_int << "\n";
|
||||||
std::cout << "in_double: " << in_double << "\n";
|
//std::cout << "in_double: " << in_double << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
AllocTestWithArguments::AllocTestWithArguments(int in_int, double in_double, const char* a_name)
|
||||||
|
:
|
||||||
|
some_int(in_int),
|
||||||
|
some_double(in_double),
|
||||||
|
some_string(a_name)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
AllocTestWithArguments::AllocTestWithArguments(int* in_int, double *in_double, const char* a_name)
|
||||||
|
:
|
||||||
|
some_int(*in_int),
|
||||||
|
some_double(*in_double),
|
||||||
|
some_string(a_name)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AllocTestWithArguments::AllocTestWithArguments(int in_int, double in_double)
|
AllocTestWithArguments::AllocTestWithArguments(int in_int, double in_double)
|
||||||
:
|
:
|
||||||
some_int(in_int),
|
some_int(in_int),
|
||||||
some_double(in_double)
|
some_double(in_double),
|
||||||
|
some_string("")
|
||||||
{
|
{
|
||||||
std::cout << "AllocTestWithArguments constructor with: \n";
|
//std::cout << "AllocTestWithArguments constructor with: \n";
|
||||||
std::cout << "in_int: " << in_int << "\n";
|
//std::cout << "in_int: " << in_int << "\n";
|
||||||
std::cout << "in_double: "
|
//std::cout << "in_double: "
|
||||||
<< in_double << "\n";
|
// << in_double << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AllocTestWithArguments::AllocTestWithArguments(Test::SomeStruct in_struct)
|
AllocTestWithArguments::AllocTestWithArguments(Test::SomeStruct in_struct)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}:
|
||||||
|
some_int(*in_int),
|
||||||
|
some_double(*in_double),
|
||||||
|
some_string(a_name)
|
@ -31,6 +31,10 @@ class AllocTestWithArguments {
|
|||||||
|
|
||||||
AllocTestWithArguments(int* in_int, double *in_double, std::string &a_name);
|
AllocTestWithArguments(int* in_int, double *in_double, std::string &a_name);
|
||||||
|
|
||||||
|
AllocTestWithArguments(int* in_int, double *in_double, const char* a_name);
|
||||||
|
|
||||||
|
AllocTestWithArguments(int in_int, double in_double, const char* a_name);
|
||||||
|
|
||||||
AllocTestWithArguments(int*, double&, std::string);
|
AllocTestWithArguments(int*, double&, std::string);
|
||||||
|
|
||||||
AllocTestWithArguments(Test::SomeStruct in_struct);
|
AllocTestWithArguments(Test::SomeStruct in_struct);
|
||||||
@ -41,5 +45,7 @@ class AllocTestWithArguments {
|
|||||||
|
|
||||||
int some_int;
|
int some_int;
|
||||||
double some_double;
|
double some_double;
|
||||||
|
std::string some_string;
|
||||||
|
|
||||||
Test::SomeStruct* my_struct;
|
Test::SomeStruct* my_struct;
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user