Esempio n. 1
0
LOAD_TEST(btunittest, action_ut_waitforsignal_0_saveload_agent)
{
    AgentNodeTest* myTestAgent = initTestEnvNode("node_test/action_ut_waitforsignal_0", format);
    myTestAgent->resetProperties();
    behaviac::EBTStatus status = myTestAgent->btexec();
    BEHAVIAC_UNUSED_VAR(status);
    CHECK_EQUAL(-1, myTestAgent->testVar_1);
    CHECK_FLOAT_EQUAL(-1.0f, myTestAgent->testVar_2);

    behaviac::State_t state;
    myTestAgent->btsave(state);
    state.SaveToFile("btsave3.xml", myTestAgent);

    //modify the members
    myTestAgent->testVar_1 = 1;
    myTestAgent->testVar_2 = 1;

    behaviac::State_t stateTemp;
    stateTemp.LoadFromFile("btsave3.xml", myTestAgent);
    CHECK_EQUAL(-1, myTestAgent->testVar_1);
    CHECK_FLOAT_EQUAL(-1.0f, myTestAgent->testVar_2);

    myTestAgent->btload(stateTemp);

    finlTestEnvNode(myTestAgent);
}
Esempio n. 2
0
LOAD_TEST(btunittest, action_ut_3_save_load)
{
    AgentNodeTest* myTestAgent = initTestEnvNode("node_test/action_ut_3", format);
    myTestAgent->resetProperties();

#if BEHAVIAC_COMPILER_MSVC || BEHAVIAC_COMPILER_GCC_CYGWIN || BEHAVIAC_COMPILER_GCC_LINUX
    behaviac::State_t state;
    myTestAgent->btsave(state);
    state.SaveToFile("btsave.xml");
#endif

    behaviac::EBTStatus status = myTestAgent->btexec();
    BEHAVIAC_UNUSED_VAR(status);
    CHECK_FLOAT_EQUAL(2.4f, myTestAgent->testVar_2);
    CHECK_FLOAT_EQUAL(4.0f, myTestAgent->testVar_3);

#if BEHAVIAC_COMPILER_MSVC || BEHAVIAC_COMPILER_GCC_CYGWIN || BEHAVIAC_COMPILER_GCC_LINUX
    myTestAgent->resetProperties();

    behaviac::State_t stateTemp;
    stateTemp.LoadFromFile("btsave.xml");

    myTestAgent->btload(state);

    //myTestAgent->btexec();
    //CHECK_EQUAL(2.4f, myTestAgent->testVar_2);
    //CHECK_EQUAL(4.0f, myTestAgent->testVar_3);
#endif

    finlTestEnvNode(myTestAgent);
}
Esempio n. 3
0
LOAD_TEST(btunittest, action_ut_3)
{
    AgentNodeTest* myTestAgent = initTestEnvNode("node_test/action_ut_3", format);
    myTestAgent->resetProperties();
    behaviac::EBTStatus status = myTestAgent->btexec();
    BEHAVIAC_UNUSED_VAR(status);
    CHECK_FLOAT_EQUAL(2.4f, myTestAgent->testVar_2);
    CHECK_FLOAT_EQUAL(4.0f, myTestAgent->testVar_3);
    finlTestEnvNode(myTestAgent);
}
Esempio n. 4
0
LOAD_TEST(btunittest, action_ut_1)
{
    AgentNodeTest* myTestAgent = initTestEnvNode("node_test/action_ut_1", format);
    myTestAgent->resetProperties();
    behaviac::EBTStatus status = myTestAgent->btexec();
    BEHAVIAC_UNUSED_VAR(status);
    CHECK_FLOAT_EQUAL(1.8f, myTestAgent->testVar_2);
    CHECK_FLOAT_EQUAL(4.5f, myTestAgent->testVar_3);

	CHECK_EQUAL("HC", myTestAgent->testVar_str_0);
	CHECK_EQUAL("NODE", myTestAgent->testVar_str_1);
	const TestNS::Float2& float2 = myTestAgent->GetVariable<TestNS::Float2>("testFloat2");
	CHECK_FLOAT_EQUAL(1.0f, float2.x);
	CHECK_FLOAT_EQUAL(1.0f, float2.y);

	const TestNS::Float2& c_ReturnFloat2 = myTestAgent->GetVariable<TestNS::Float2>("c_ReturnFloat2");
	CHECK_FLOAT_EQUAL(2.0f, c_ReturnFloat2.x);
	CHECK_FLOAT_EQUAL(2.0f, c_ReturnFloat2.y);

	const TestNS::Float2& c_ReturnFloat2Const = myTestAgent->GetVariable<TestNS::Float2>("c_ReturnFloat2Const");
	CHECK_FLOAT_EQUAL(2.0f, c_ReturnFloat2Const.x);
	CHECK_FLOAT_EQUAL(2.0f, c_ReturnFloat2Const.y);

	finlTestEnvNode(myTestAgent);
}
Esempio n. 5
0
LOAD_TEST(btunittest, action_ut_waitforsignal_2)
{
    AgentNodeTest* myTestAgent = initTestEnvNode("node_test/action_ut_waitforsignal_2", format);
    myTestAgent->resetProperties();
    behaviac::EBTStatus status = myTestAgent->btexec();
    BEHAVIAC_UNUSED_VAR(status);
    CHECK_FLOAT_EQUAL(-1.0f, myTestAgent->testVar_2);
    CHECK_EQUAL(behaviac::BT_RUNNING, status);
    myTestAgent->resetProperties();
    myTestAgent->testVar_2 = 0.0f;
    status = myTestAgent->btexec();
    CHECK_FLOAT_EQUAL(2.3f, myTestAgent->testVar_2);
    CHECK_EQUAL(behaviac::BT_SUCCESS, status);
    finlTestEnvNode(myTestAgent);
}
Esempio n. 6
0
LOAD_TEST(btunittest, selector_probability_ut_4)
{
	const char* tree = "node_test/selector_probability_ut_4";

	behaviac::Profiler::CreateInstance();
	behaviac::Config::SetSocketing(false);
	behaviac::Config::SetLogging(false);

	//behaviac::Agent::Register<AgentNodeTest>();
	registerAllTypes();
	AgentNodeTest* myTestAgent = AgentNodeTest::DynamicCast(behaviac::Agent::Create<AgentNodeTest>());
	behaviac::Agent::SetIdMask(1);
	myTestAgent->SetIdFlag(1);
	myTestAgent->btload(tree);
	myTestAgent->btsetcurrent(tree);
	myTestAgent->resetProperties();

	behaviac::Workspace::GetInstance()->SetTimeSinceStartup(0.0);

	for (int i = 0; i < 10; ++i) {
		myTestAgent->btexec();
		if (myTestAgent->testVar_0 != -1) {
			CHECK_EQUAL(0, myTestAgent->testVar_0);
			CHECK_EQUAL(-1, myTestAgent->testVar_1);
			CHECK_FLOAT_EQUAL(0.0f, myTestAgent->testVar_2);
		}
		else {
			CHECK_EQUAL(-1, myTestAgent->testVar_0);
			CHECK_EQUAL(0, myTestAgent->testVar_1);
			CHECK_FLOAT_EQUAL(-1, myTestAgent->testVar_2);
		}

		behaviac::Workspace::GetInstance()->SetTimeSinceStartup(behaviac::Workspace::GetInstance()->GetTimeSinceStartup() + 0.1);
	}

	behaviac::Workspace::GetInstance()->SetTimeSinceStartup(behaviac::Workspace::GetInstance()->GetTimeSinceStartup() + 0.1);
	myTestAgent->btexec();

	CHECK_EQUAL(-1, myTestAgent->testVar_0);
	CHECK_EQUAL(-1, myTestAgent->testVar_1);


	unregisterAllTypes();
	BEHAVIAC_DELETE(myTestAgent);
	//behaviac::Agent::UnRegister<AgentNodeTest>();

	behaviac::Profiler::DestroyInstance();
}
Esempio n. 7
0
TEST(btunittest, agentInvoke)
{
    EmployeeParTestAgent::clearAllStaticMemberVariables();

    behaviac::Profiler::CreateInstance();
    behaviac::Config::SetSocketing(false);
    behaviac::Config::SetLogging(false);

    registerAllTypes();

    behaviac::Agent* testAgent = behaviac::Agent::Create<AgentNodeTest>();
    AgentNodeTest* nodeTestAgent = AgentNodeTest::DynamicCast(testAgent);

    CHECK_EQUAL(true, behaviac::Agent::Invoke(testAgent, "AgentNodeTest::setTestVar_0", 999));
    CHECK_EQUAL(999, nodeTestAgent->testVar_0);

    CHECK_EQUAL(true, behaviac::Agent::Invoke(testAgent, "AgentNodeTest::setTestVar_0_2", 8999, 1000.99f));
    CHECK_EQUAL(8999, nodeTestAgent->testVar_0);
    CHECK_FLOAT_EQUAL(1000.99f, nodeTestAgent->testVar_2);

    //float returnValue = 0.0f;
    //CHECK_EQUAL(true, behaviac::Agent::Invoke(testAgent, "AgentNodeTest::setTestVar_R"));
    //behaviac::Agent::GetInvokeReturn(testAgent, "AgentNodeTest::setTestVar_R", returnValue);
    //CHECK_EQUAL(9999.99f, returnValue);

    behaviac::Agent::Destroy(testAgent);

    unregisterAllTypes();

    behaviac::Profiler::DestroyInstance();
}
Esempio n. 8
0
LOAD_TEST(btunittest, reference_ut_2)
{
	AgentNodeTest* myTestAgent = initTestEnvNode("node_test/reference_ut_2", format);
	myTestAgent->resetProperties();

	myTestAgent->btexec();
	CHECK_EQUAL(0, myTestAgent->testVar_0);
	CHECK_FLOAT_EQUAL(0.0f, myTestAgent->testVar_2);
	finlTestEnvNode(myTestAgent);
}
Esempio n. 9
0
LOAD_TEST(btunittest, predicate_selector_ut_5)
{
    AgentNodeTest* myTestAgent = initTestEnvNode("node_test/predicate_selector_ut_5", format);
    myTestAgent->resetProperties();
    behaviac::EBTStatus status = myTestAgent->btexec();
    CHECK_EQUAL(behaviac::BT_FAILURE, status);
    CHECK_EQUAL(0, myTestAgent->testVar_0);
    CHECK_EQUAL(0, myTestAgent->testVar_1);
    CHECK_FLOAT_EQUAL(0.0f, myTestAgent->testVar_2);
    finlTestEnvNode(myTestAgent);
}
//< Decoration Log Tests
LOAD_TEST(btunittest, decoration_log_ut_0)
{
    AgentNodeTest* myTestAgent = initTestEnvNode("node_test/decoration_log_ut_0", format);
    myTestAgent->resetProperties();
    behaviac::EBTStatus status = myTestAgent->btexec();
    CHECK_EQUAL(0, myTestAgent->testVar_0);
    CHECK_EQUAL(1, myTestAgent->testVar_1);
    CHECK_FLOAT_EQUAL(0.0f, myTestAgent->testVar_2);
    CHECK_EQUAL(behaviac::BT_RUNNING, status);
    finlTestEnvNode(myTestAgent);
}
//< Decoration Always Success Tests
LOAD_TEST(btunittest, decoration_alwayssuccess_ut_0)
{
    AgentNodeTest* myTestAgent = initTestEnvNode("node_test/decoration_alwayssuccess_ut_0", format);
    myTestAgent->resetProperties();
    behaviac::EBTStatus status = myTestAgent->btexec();
    BEHAVIAC_UNUSED_VAR(status);
    CHECK_EQUAL(0, myTestAgent->testVar_0);
    CHECK_EQUAL(0, myTestAgent->testVar_1);
    CHECK_FLOAT_EQUAL(0.0f, myTestAgent->testVar_2);
    finlTestEnvNode(myTestAgent);
}
Esempio n. 12
0
LOAD_TEST(btunittest, vector_test)
{
    TestNS::AgentArrayAccessTest* testAgent = initTestEnvArray("par_test/vector_test", format);
    testAgent->resetProperties();
    testAgent->btexec();

    int Int1 = testAgent->GetVariable<int>("Int");
    CHECK_EQUAL(1, Int1);

    int Int2 = testAgent->Int;
    CHECK_EQUAL(1, Int2);

    int c_Int = testAgent->GetVariable<int>("c_Int");
    CHECK_EQUAL(10, c_Int);

    int Int0 = testAgent->ListInts[0];
    CHECK_EQUAL(110, Int0);

    int c_Count = testAgent->GetVariable<int>("c_Count");
    CHECK_EQUAL(5, c_Count);

	behaviac::vector<double> c_douleVec = testAgent->GetVariable<behaviac::vector<double> >("c_douleVec");
	CHECK_EQUAL(103, c_douleVec.size());
	for (int i = 0; i < 100; ++i)
	{
		CHECK_FLOAT_EQUAL(c_douleVec[3 + i], 0.03);
	}

	behaviac::vector<double> c_douleVec2 = testAgent->GetVariable<behaviac::vector<double> >("c_doubleVec2");
	CHECK_EQUAL(103, c_douleVec2.size());
	for (int i = 0; i < 100; ++i)
	{
		CHECK_FLOAT_EQUAL(c_douleVec2[3 + i], 0.05);
	}

    finlTestEnvArray(testAgent);
}
//< par_as_ref_param
LOAD_TEST(btunittest, readonly_default)
{
    PropertyReadonlyAgent* testAgent = initTestEnvProperty("par_test/readonly_default", format);
    testAgent->resetProperties();
    //testAgent->btexec();

    // base class 0 test
    int PropertyGetterOnly = testAgent->GetVariable<int>("PropertyGetterOnly");
    CHECK_EQUAL(1, PropertyGetterOnly);
    CHECK_EQUAL(2, testAgent->MemberReadonly);
    CHECK_EQUAL(3, testAgent->MemberReadonlyAs);

    testAgent->btexec();

    int c_IntReadonly = testAgent->GetVariable<int>("c_IntReadonly");
    CHECK_EQUAL(10, c_IntReadonly);

    int PropertyGetterSetter = testAgent->GetVariable<int>("PropertyGetterSetter");
    // PropertyGetterSetter = MemberReadonly, while MemberReadonly = 2
    CHECK_EQUAL(2, PropertyGetterSetter);

    PropertyGetterOnly = testAgent->GetVariable<int>("PropertyGetterOnly");
    // PropertyGetterOnly is passed in as the param of PassInProperty
    CHECK_EQUAL(1, PropertyGetterOnly);

    // MemberReadonly is readonly, not changed
    CHECK_EQUAL(2, testAgent->MemberReadonly);

    // MemberReadonlyAs is modified in PassInProperty and assigned to be PropertyGetterOnly
    CHECK_EQUAL(1, testAgent->MemberReadonlyAs);

    // m_Int is as the ref param of FnWithOutParam and set to 4
    int c_Int = testAgent->GetVariable<int>("c_Int");
    CHECK_EQUAL(4, c_Int);

    // c_ResultStatic = MemberReadonly + PropertyGetterOnly, 2 + 1 = 3
    int c_ResultStatic = testAgent->GetVariable<int>("c_ResultStatic");
    //BEHAVIAC_ASSERT(false);
    CHECK_EQUAL(3, c_ResultStatic);

    testAgent->SetVariable("StaticPropertyGetterSetter", 1.0f);
    float StaticPropertyGetterSetter = testAgent->GetVariable<float>("StaticPropertyGetterSetter");
    CHECK_FLOAT_EQUAL(1.0f, StaticPropertyGetterSetter);

    finlTestEnvProperty(testAgent);
}
Esempio n. 14
0
LOAD_TEST(btunittest, action_child_agent)
{
    AgentNodeTest* myTestAgent = initTestEnvNode("node_test/action_child_agent_0", format);

    myTestAgent->resetProperties();

    myTestAgent->initChildAgentTest();

    myTestAgent->btexec();

	const ChildNodeTest* ct = myTestAgent->GetVariable<ChildNodeTest*>("par_child_agent_1");
    CHECK_EQUAL(666, ct->testVar_0);
    CHECK_EQUAL(888, ct->testVar_1);
    CHECK_FLOAT_EQUAL(999, ct->testVar_2);

    finlTestEnvNode(myTestAgent);
}
//< Decoration Always Running Tests
LOAD_TEST(btunittest, decoration_alwaysrunning_ut_0)
{
    AgentNodeTest* myTestAgent = initTestEnvNode("node_test/decoration_alwaysrunning_ut_0", format);
    int loopCount = 0;

    while (loopCount < 1000)
    {
        myTestAgent->resetProperties();
        behaviac::EBTStatus status = myTestAgent->btexec();
        BEHAVIAC_UNUSED_VAR(status);
        CHECK_EQUAL(0, myTestAgent->testVar_0);
        CHECK_EQUAL(0, myTestAgent->testVar_1);
        CHECK_FLOAT_EQUAL(0.0f, myTestAgent->testVar_2);

        ++loopCount;
    }

    finlTestEnvNode(myTestAgent);
}
Esempio n. 16
0
LOAD_TEST(btunittest, event_ut_0)
{
	AgentNodeTest* myTestAgent = initTestEnvNode("node_test/event_ut_0", format);

	ChildNodeTest* childTestAgent = ChildNodeTest::DynamicCast(behaviac::Agent::Create<ChildNodeTest>(100, "ChildNodeTest", 0, 0));
	CHECK_EQUAL(100, childTestAgent->testVar_0);

	myTestAgent->resetProperties();

	behaviac::EBTStatus status = myTestAgent->btexec();
	CHECK_EQUAL(behaviac::BT_RUNNING, status);

	behaviac::Workspace::GetInstance()->SetTimeSinceStartup(0);
	myTestAgent->FireEvent("event_test_void");
	CHECK_EQUAL(true, myTestAgent->event_test_var_bool);

	status = myTestAgent->btexec();
	CHECK_EQUAL(behaviac::BT_RUNNING, status);

	behaviac::Workspace::GetInstance()->SetTimeSinceStartup(5.1);

	status = myTestAgent->btexec();
	CHECK_EQUAL(behaviac::BT_RUNNING, status);

	myTestAgent->resetProperties();
	myTestAgent->btsetcurrent("node_test/event_ut_0");
	myTestAgent->btexec();
	myTestAgent->FireEvent("event_test_int", 13);
	CHECK_EQUAL(13, myTestAgent->event_test_var_int);

	myTestAgent->FireEvent("event_test_float2", myTestAgent->TestFloat2);
	myTestAgent->FireEvent("event_test_float2_ref", myTestAgent->TestFloat2);
			
	status = myTestAgent->btexec();
	CHECK_EQUAL(behaviac::BT_RUNNING, status);

	myTestAgent->resetProperties();
	myTestAgent->btsetcurrent("node_test/event_ut_0");
	myTestAgent->btexec();
	myTestAgent->FireEvent("event_test_int_bool", 15, true);
	CHECK_EQUAL(true, myTestAgent->event_test_var_bool);
	CHECK_EQUAL(15, myTestAgent->event_test_var_int);

	status = myTestAgent->btexec();
	CHECK_EQUAL(behaviac::BT_RUNNING, status);

	myTestAgent->resetProperties();
	myTestAgent->btexec();
	myTestAgent->FireEvent("event_test_int_bool_float", 15, true, 27.3f);
	CHECK_EQUAL(true, myTestAgent->event_test_var_bool);
	CHECK_EQUAL(15, myTestAgent->event_test_var_int);
	CHECK_FLOAT_EQUAL(27.3f, myTestAgent->event_test_var_float);

	status = myTestAgent->btexec();
	CHECK_EQUAL(behaviac::BT_RUNNING, status);

	myTestAgent->resetProperties();
	myTestAgent->btsetcurrent("node_test/event_ut_0");
	myTestAgent->btexec();
	myTestAgent->testVar_0 = 0;
	status = myTestAgent->btexec();
	CHECK_EQUAL(behaviac::BT_SUCCESS, status);
	CHECK_EQUAL(0, myTestAgent->testVar_1);

	myTestAgent->FireEvent("event_test_int_bool_float", 19, true, 11.9f);
	CHECK_EQUAL(false, myTestAgent->event_test_var_bool);
	CHECK_EQUAL(-1, myTestAgent->event_test_var_int);
	CHECK_FLOAT_EQUAL(-1.0f, myTestAgent->event_test_var_float);

	myTestAgent->resetProperties();
	myTestAgent->btsetcurrent("node_test/event_ut_0");
	myTestAgent->btexec();

	CHECK_EQUAL(NULL, myTestAgent->event_test_var_agent);
	myTestAgent->FireEvent("event_test_agent", myTestAgent);
	CHECK_EQUAL(true, myTestAgent->event_test_var_agent != NULL);

	myTestAgent->resetProperties();
	myTestAgent->btsetcurrent("node_test/event_ut_0");
	myTestAgent->btexec();

	CHECK_EQUAL(NULL, myTestAgent->event_test_var_agent);
	myTestAgent->FireEvent("event_test_agent", childTestAgent);
	CHECK_EQUAL(true, myTestAgent->event_test_var_agent != NULL);

	BEHAVIAC_DELETE(childTestAgent);

	finlTestEnvNode(myTestAgent);
}