diff --git a/UnitTests/SoarUnitTests.cxx b/UnitTests/SoarUnitTests.cxx index e6b378e124..b0790be10f 100644 --- a/UnitTests/SoarUnitTests.cxx +++ b/UnitTests/SoarUnitTests.cxx @@ -9,6 +9,7 @@ #include "MultiAgentTest.cpp" #include "SimpleListener.cpp" #include "SMemFunctionalTests.cpp" +#include "SvsTests.cpp" #include "TokenizerTest.cpp" #include "wma/WmaFunctionalTests.cpp" #include "ExampleTests.cpp" diff --git a/UnitTests/SoarUnitTests/SvsTests.cpp b/UnitTests/SoarUnitTests/SvsTests.cpp new file mode 100644 index 0000000000..2a746b7e57 --- /dev/null +++ b/UnitTests/SoarUnitTests/SvsTests.cpp @@ -0,0 +1,162 @@ +#include "SvsTests.hpp" +#include "soar_instance.h" + +void SvsTests::setUp() +{ + kernel = sml::Kernel::CreateKernelInCurrentThread(true, sml::Kernel::kUseAnyPort); + configure_for_unit_tests(); + agent = kernel->CreateAgent("soar1"); + configure_agent_for_unit_tests(NULL); +} + +void SvsTests::tearDown(bool caught) +{ + kernel->DestroyAgent(agent); + kernel->Shutdown(); + delete kernel; + kernel = nullptr; +} + +void SvsTests::testEnableFromTopState() +{ + // enable, step, check that ^svs exists everywhere + + agent->ExecuteCommandLine("svs --enable"); + assertTrue_msg("Failed to enable SVS.", + agent->GetLastCommandLineResult()); + + agent->ExecuteCommandLine("svs --enable-in-substates"); + assertTrue_msg("Failed to enable SVS in substates.", + agent->GetLastCommandLineResult()); + + std::string result = agent->ExecuteCommandLine("print S1"); + assertFalse_msg("Expected to find ^svs in S1; return was " + result, + result.find("^svs") == std::string::npos); + + // no productions, so agent will subgoal each step + agent->ExecuteCommandLine("step 2"); + + result = agent->ExecuteCommandLine("print S2"); + assertFalse_msg("Expected to find ^svs in S2; return was: " + result, + result.find("^svs") == std::string::npos); + result = agent->ExecuteCommandLine("print S3"); + assertFalse_msg("Expected to find ^svs in S3", + result.find("^svs") == std::string::npos); +} + +void SvsTests::testEnableAndDisableInSubstatesFromTopState() { + // disable-in-substates, step, ^svs should not exist in substates + + agent->ExecuteCommandLine("svs --enable"); + assertTrue_msg("Failed to enable SVS.", + agent->GetLastCommandLineResult()); + + agent->ExecuteCommandLine("svs --disable-in-substates"); + assertTrue_msg("Failed to enable SVS in substates.", + agent->GetLastCommandLineResult()); + + std::string result = agent->ExecuteCommandLine("print S1"); + assertFalse_msg("Expected to find ^svs in S1", + result.find("^svs") == std::string::npos); + + // no productions, so agent will subgoal each step + agent->ExecuteCommandLine("step 2"); + + result = agent->ExecuteCommandLine("print S2"); + assertTrue_msg("Expected to not find ^svs in S2; return was: " + result, + result.find("^svs") == std::string::npos); + result = agent->ExecuteCommandLine("print S3"); + assertTrue_msg("Expected to not find ^svs in S3", + result.find("^svs") == std::string::npos); +} + +void SvsTests::testCannotDisableInSubstate() +{ + // enable, step, try to disable, should fail + + agent->ExecuteCommandLine("svs --enable"); + assertTrue_msg("Failed to enable SVS.", + agent->GetLastCommandLineResult()); + + // no productions, so agent will subgoal each step + agent->ExecuteCommandLine("step 1"); + + std::string result = agent->ExecuteCommandLine("svs --disable"); + assertFalse_msg("Expected not to be able to disable SVS from a substate; return was: " + result + " (" + (agent->GetLastCommandLineResult() ? "true" : "false") + ")", + agent->GetLastCommandLineResult()); + + result = agent->ExecuteCommandLine("svs --disable-in-substates"); + assertFalse_msg("Expected not to be able to disable SVS in substates from a substate; return was: " + result, + agent->GetLastCommandLineResult()); +} + +void SvsTests::testEnableFromSubstate() +{ + // disable, step, enable, check that ^svs exists in all states + + + + agent->ExecuteCommandLine("svs --disable"); + assertTrue_msg("Failed to disable SVS.", + agent->GetLastCommandLineResult()); + + // no productions, so agent will subgoal each step + agent->ExecuteCommandLine("step 2"); + agent->ExecuteCommandLine("svs --enable"); + assertTrue_msg("Failed to enable SVS.", + agent->GetLastCommandLineResult()); + + std::string result = agent->ExecuteCommandLine("print S1"); + assertFalse_msg("Expected to find ^svs in S1", + result.find("^svs") == std::string::npos); + result = agent->ExecuteCommandLine("print S2"); + assertFalse_msg("Expected to find ^svs in S2", + result.find("^svs") == std::string::npos); + result = agent->ExecuteCommandLine("print S3"); + assertFalse_msg("Expected to find ^svs in S3", + result.find("^svs") == std::string::npos); + +} + +void SvsTests::testEnableInSubstatesFromSubstate() +{ + // disable-in-substates, step and then enable, check that ^svs exists only on top state + + agent->ExecuteCommandLine("svs --disable"); + assertTrue_msg("Failed to disable SVS.", + agent->GetLastCommandLineResult()); + agent->ExecuteCommandLine("svs --disable-in-substates"); + assertTrue_msg("Failed to disable SVS in substates.", + agent->GetLastCommandLineResult()); + + // no productions, so agent will subgoal each step + agent->ExecuteCommandLine("step 2"); + + std::string result = agent->ExecuteCommandLine("print S1"); + assertTrue_msg("Expected to not find ^svs in S1; return was " + result, + result.find("^svs") == std::string::npos); + result = agent->ExecuteCommandLine("print S3"); + assertTrue_msg("Expected to not find ^svs in S3", + result.find("^svs") == std::string::npos); + + agent->ExecuteCommandLine("svs --enable"); + assertTrue_msg("Failed to enable SVS.", + agent->GetLastCommandLineResult()); + result = agent->ExecuteCommandLine("print S3"); + assertTrue_msg("Expected to not find ^svs in S3", + result.find("^svs") == std::string::npos); + + // then enable-in-substates and check that ^svs exists on all states + + agent->ExecuteCommandLine("svs --enable-in-substates"); + assertTrue_msg("Failed to enable SVS in substates.", + agent->GetLastCommandLineResult()); + result = agent->ExecuteCommandLine("print S3"); + assertFalse_msg("Expected to find ^svs in S3", + result.find("^svs") == std::string::npos); +} + +void SvsTests::testSubstateWhenDisabledInSubstates() +{ + // TODO +} diff --git a/UnitTests/SoarUnitTests/SvsTests.hpp b/UnitTests/SoarUnitTests/SvsTests.hpp new file mode 100644 index 0000000000..071c0138d3 --- /dev/null +++ b/UnitTests/SoarUnitTests/SvsTests.hpp @@ -0,0 +1,59 @@ +// +// SvsTests.hpp +// Soar-xcode +// +// Created by Alex Turner on 6/27/15. +// Copyright © 2015 University of Michigan – Soar Group. All rights reserved. +// + +#ifndef SvsTests_cpp +#define SvsTests_cpp + +#include "portability.h" + +#include +#include +#include + +#include "sml_Connection.h" +#include "sml_Client.h" +#include "sml_Utils.h" +#include "thread_Event.h" +#include "sml_Names.h" + +#include "FunctionalTestHarness.hpp" + +class SvsTests : public FunctionalTestHarness +{ +private: + sml::Agent* agent; + sml::Kernel* kernel; + +public: + TEST_CATEGORY(SvsTests); + void before() { setUp(); } + void setUp(); + + void after(bool caught) { tearDown(caught); } + void tearDown(bool caught); + + TEST(testEnableFromTopState, -1); + void testEnableFromTopState(); + + TEST(testEnableAndDisableInSubstatesFromTopState, -1); + void testEnableAndDisableInSubstatesFromTopState(); + + TEST(testCannotDisableInSubstate, -1); + void testCannotDisableInSubstate(); + + TEST(testEnableFromSubstate, -1); + void testEnableFromSubstate(); + + TEST(testEnableInSubstatesFromSubstate, -1); + void testEnableInSubstatesFromSubstate(); + + TEST(testSubstateWhenDisabledInSubstates, -1); + void testSubstateWhenDisabledInSubstates(); +}; + +#endif /* SvsTests_cpp */ diff --git a/UnitTests/TestHarness/testMain.cpp b/UnitTests/TestHarness/testMain.cpp index f44fb62e51..0976bbd972 100644 --- a/UnitTests/TestHarness/testMain.cpp +++ b/UnitTests/TestHarness/testMain.cpp @@ -38,6 +38,7 @@ #include "MultiAgentTest.hpp" #include "SimpleListener.hpp" #include "SMemFunctionalTests.hpp" +#include "SvsTests.hpp" #include "TokenizerTest.hpp" #include "wma/WmaFunctionalTests.hpp" #include "TestCategory.hpp" @@ -202,6 +203,7 @@ int main(int argc, char** argv) TEST_DECLARATION(MiscTests); TEST_DECLARATION(MultiAgentTest); TEST_DECLARATION(SMemFunctionalTests); + TEST_DECLARATION(SvsTests); TEST_DECLARATION(TokenizerTest); TEST_DECLARATION(WmaFunctionalTests);