/* * Copyright (c) 2010 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include #include #include #include using namespace Swift; class CommandParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(CommandParserTest); CPPUNIT_TEST(testParse); CPPUNIT_TEST(testParse_Result); CPPUNIT_TEST(testParse_Form); CPPUNIT_TEST_SUITE_END(); public: void testParse() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "" )); Command::ref payload = parser.getPayload(); CPPUNIT_ASSERT_EQUAL(Command::Prev, payload->getAction()); CPPUNIT_ASSERT_EQUAL(std::string("list"), payload->getNode()); CPPUNIT_ASSERT_EQUAL(std::string("myid"), payload->getSessionID()); } void testParse_Result() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "" "Service 'httpd' has been configured." "I lied." "" "" "" "" "" )); Command::ref payload = parser.getPayload(); CPPUNIT_ASSERT_EQUAL(Command::Completed, payload->getStatus()); std::vector notes = payload->getNotes(); CPPUNIT_ASSERT_EQUAL(2, static_cast(notes.size())); CPPUNIT_ASSERT_EQUAL(Command::Note::Warn, notes[0].type); CPPUNIT_ASSERT_EQUAL(std::string("Service 'httpd' has been configured."), notes[0].note); CPPUNIT_ASSERT_EQUAL(Command::Note::Error, notes[1].type); CPPUNIT_ASSERT_EQUAL(std::string("I lied."), notes[1].note); std::vector actions = payload->getAvailableActions(); CPPUNIT_ASSERT_EQUAL(2, static_cast(actions.size())); CPPUNIT_ASSERT_EQUAL(Command::Prev, actions[0]); CPPUNIT_ASSERT_EQUAL(Command::Next, actions[1]); CPPUNIT_ASSERT_EQUAL(Command::Next, payload->getExecuteAction()); } void testParse_Form() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "" "" "Bot Configuration" "Hello!" "Fill out this form to configure your new bot!" "" "" )); Command::ref payload = parser.getPayload(); Form::ref form = payload->getForm(); CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), form->getTitle()); CPPUNIT_ASSERT_EQUAL(std::string("Hello!\nFill out this form to configure your new bot!"), form->getInstructions()); CPPUNIT_ASSERT_EQUAL(Form::ResultType, form->getType()); } }; CPPUNIT_TEST_SUITE_REGISTRATION(CommandParserTest);