[Ktutorial-commits] SF.net SVN: ktutorial:[194] trunk/ktutorial/ktutorial-editor/tests/unit/ serial
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-03-26 01:10:30
|
Revision: 194
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=194&view=rev
Author: danxuliu
Date: 2010-03-26 01:10:24 +0000 (Fri, 26 Mar 2010)
Log Message:
-----------
Files missed in commit 192
Modified Paths:
--------------
trunk/ktutorial/ktutorial-editor/tests/unit/serialization/CMakeLists.txt
Added Paths:
-----------
trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialWriterTest.cpp
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/serialization/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/serialization/CMakeLists.txt 2010-03-26 01:09:26 UTC (rev 193)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/serialization/CMakeLists.txt 2010-03-26 01:10:24 UTC (rev 194)
@@ -14,6 +14,8 @@
unit_tests(
JavascriptExporter
Serialization
+ TutorialReader
+ TutorialWriter
)
MACRO(MEM_TESTS)
@@ -25,4 +27,6 @@
mem_tests(
JavascriptExporter
Serialization
+ TutorialReader
+ TutorialWriter
)
Added: trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialWriterTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialWriterTest.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialWriterTest.cpp 2010-03-26 01:10:24 UTC (rev 194)
@@ -0,0 +1,590 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Daniel Calviño Sánchez *
+ * dan...@gm... *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+
+#include <QtTest>
+
+#include "TutorialWriter.h"
+
+#include "../Reaction.h"
+#include "../Step.h"
+#include "../Tutorial.h"
+#include "../WaitForComposed.h"
+#include "../WaitForEvent.h"
+#include "../WaitForNot.h"
+#include "../WaitForSignal.h"
+
+#define HEADER_XML \
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+
+#define TUTORIAL_ELEMENTS \
+" <description>The description,\nwith < and >\n</description>\n" \
+" <license>The license text,\nwith < and >\n</license>\n" \
+" <setup>The setup code,\nwith < and >\n</setup>\n" \
+" <tearDown>The tear down code,\nwith < and >\n</tearDown>\n"
+
+#define STEP_PARENT_START \
+HEADER_XML \
+"<tutorial>\n"
+
+#define STEP_PARENT_END \
+"</tutorial>\n"
+
+#define STEP_ELEMENTS \
+" <text>The text,\nwith < and >\n</text>\n" \
+" <setup>The setup code,\nwith < and >\n</setup>\n" \
+" <tearDown>The tear down code,\nwith < and >\n</tearDown>\n"
+
+#define REACTION_PARENT_START \
+STEP_PARENT_START \
+" <step>\n"
+
+#define REACTION_PARENT_END \
+" </step>\n" \
+STEP_PARENT_END
+
+#define WAITFOR_PARENT_START \
+REACTION_PARENT_START \
+" <reaction triggerType=\"ConditionMet\" responseType=\"NextStep\">\n"
+
+#define WAITFOR_PARENT_END \
+" </reaction>\n" \
+REACTION_PARENT_END
+
+class TutorialWriterTest: public QObject {
+Q_OBJECT
+
+private slots:
+
+ void testTutorial();
+ void testTutorialEmpty();
+ void testTutorialWithSeveralSteps();
+
+ void testStep();
+ void testStepEmpty();
+ void testStepWithSeveralReactions();
+
+ void testReactionConditionCustomCode();
+ void testReactionOptionNextStep();
+ void testReactionEmpty();
+
+ void testWaitForEvent();
+ void testWaitForEventEmpty();
+ void testWaitForSignal();
+ void testWaitForSignalEmpty();
+ void testWaitForComposed();
+ void testWaitForComposedEmpty();
+ void testWaitForNot();
+ void testWaitForNotWithoutNegatedWaitFor();
+
+};
+
+void TutorialWriterTest::testTutorial() {
+ Tutorial tutorial;
+ tutorial.setName("The \"name\"");
+ tutorial.setDescription("The description,\nwith < and >\n");
+ tutorial.setLicenseText("The license text,\nwith < and >\n");
+ tutorial.setCustomSetupCode("The setup code,\nwith < and >\n");
+ tutorial.setCustomTearDownCode("The tear down code,\nwith < and >\n");
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+HEADER_XML
+"<tutorial name=\"The "name"\">\n"
+" <description>The description,\nwith < and >\n</description>\n"
+" <license>The license text,\nwith < and >\n</license>\n"
+" <setup>The setup code,\nwith < and >\n</setup>\n"
+" <tearDown>The tear down code,\nwith < and >\n</tearDown>\n"
+"</tutorial>\n";
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testTutorialEmpty() {
+ Tutorial tutorial;
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+HEADER_XML
+"<tutorial/>\n";
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testTutorialWithSeveralSteps() {
+ Tutorial tutorial;
+ tutorial.setName("The \"name\"");
+ tutorial.setDescription("The description,\nwith < and >\n");
+ tutorial.setLicenseText("The license text,\nwith < and >\n");
+ tutorial.setCustomSetupCode("The setup code,\nwith < and >\n");
+ tutorial.setCustomTearDownCode("The tear down code,\nwith < and >\n");
+
+ Step* step1 = new Step();
+ step1->setId("The id1");
+ step1->setText("The text1");
+ tutorial.addStep(step1);
+
+ Step* step2 = new Step();
+ step2->setId("The id2");
+ step2->setText("The text2");
+ tutorial.addStep(step2);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+HEADER_XML
+"<tutorial name=\"The "name"\">\n"
+TUTORIAL_ELEMENTS
+" <step id=\"The id1\">\n"
+" <text>The text1</text>\n"
+" </step>\n"
+" <step id=\"The id2\">\n"
+" <text>The text2</text>\n"
+" </step>\n"
+"</tutorial>\n";
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testStep() {
+ Tutorial tutorial;
+
+ Step* step = new Step();
+ step->setId("The \"id\"");
+ step->setText("The text,\nwith < and >\n");
+ step->setCustomSetupCode("The setup code,\nwith < and >\n");
+ step->setCustomTearDownCode("The tear down code,\nwith < and >\n");
+ tutorial.addStep(step);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+STEP_PARENT_START
+" <step id=\"The "id"\">\n"
+" <text>The text,\nwith < and >\n</text>\n"
+" <setup>The setup code,\nwith < and >\n</setup>\n"
+" <tearDown>The tear down code,\nwith < and >\n</tearDown>\n"
+" </step>\n"
+STEP_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testStepEmpty() {
+ Tutorial tutorial;
+
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+STEP_PARENT_START
+" <step/>\n"
+STEP_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testStepWithSeveralReactions() {
+ Tutorial tutorial;
+
+ Step* step = new Step();
+ step->setId("The \"id\"");
+ step->setText("The text,\nwith < and >\n");
+ step->setCustomSetupCode("The setup code,\nwith < and >\n");
+ step->setCustomTearDownCode("The tear down code,\nwith < and >\n");
+ tutorial.addStep(step);
+
+ Reaction* reaction1 = new Reaction();
+ reaction1->setTriggerType(Reaction::ConditionMet);
+ reaction1->setResponseType(Reaction::CustomCode);
+ step->addReaction(reaction1);
+
+ Reaction* reaction2 = new Reaction();
+ reaction2->setTriggerType(Reaction::OptionSelected);
+ reaction2->setOptionName("The option name");
+ reaction2->setResponseType(Reaction::NextStep);
+ reaction2->setNextStepId("Another id");
+ step->addReaction(reaction2);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+STEP_PARENT_START
+" <step id=\"The "id"\">\n"
+STEP_ELEMENTS
+" <reaction triggerType=\"ConditionMet\" responseType=\"CustomCode\"/>\n"
+" <reaction triggerType=\"OptionSelected\" responseType=\"NextStep\">\n"
+" <option name=\"The option name\"/>\n"
+" <nextStep id=\"Another id\"/>\n"
+" </reaction>\n"
+" </step>\n"
+STEP_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testReactionConditionCustomCode() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ WaitForSignal* waitForSignal = new WaitForSignal();
+ waitForSignal->setEmitterName("The emitter name");
+ waitForSignal->setSignalName("theSignalName(Argument1Type, Argument2Type)");
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForSignal);
+ reaction->setOptionName("The \"option\" name");
+ reaction->setResponseType(Reaction::CustomCode);
+ reaction->setCustomCode("The custom code,\nwith < and >\n");
+ reaction->setNextStepId("Another \"id\"");
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+REACTION_PARENT_START
+" <reaction triggerType=\"ConditionMet\" responseType=\"CustomCode\">\n"
+" <option name=\"The "option" name\"/>\n"
+" <waitForSignal emitterName=\"The emitter name\" \
+signalName=\"theSignalName(Argument1Type, Argument2Type)\"/>\n"
+" <customCode>The custom code,\nwith < and >\n</customCode>\n"
+" <nextStep id=\"Another "id"\"/>\n"
+" </reaction>\n"
+REACTION_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testReactionOptionNextStep() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ WaitForSignal* waitForSignal = new WaitForSignal();
+ waitForSignal->setEmitterName("The emitter name");
+ waitForSignal->setSignalName("theSignalName(Argument1Type, Argument2Type)");
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::OptionSelected);
+ reaction->setOptionName("The \"option\" name");
+ reaction->setWaitFor(waitForSignal);
+ reaction->setResponseType(Reaction::NextStep);
+ reaction->setNextStepId("Another \"id\"");
+ reaction->setCustomCode("The custom code,\nwith < and >\n");
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+REACTION_PARENT_START
+" <reaction triggerType=\"OptionSelected\" responseType=\"NextStep\">\n"
+" <option name=\"The "option" name\"/>\n"
+" <waitForSignal emitterName=\"The emitter name\" \
+signalName=\"theSignalName(Argument1Type, Argument2Type)\"/>\n"
+" <customCode>The custom code,\nwith < and >\n</customCode>\n"
+" <nextStep id=\"Another "id"\"/>\n"
+" </reaction>\n"
+REACTION_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testReactionEmpty() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setResponseType(Reaction::CustomCode);
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+REACTION_PARENT_START
+" <reaction triggerType=\"ConditionMet\" responseType=\"CustomCode\"/>\n"
+REACTION_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testWaitForEvent() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ WaitForEvent* waitForEvent = new WaitForEvent();
+ waitForEvent->setReceiverName("The \"receiver\" name");
+ waitForEvent->setEventName("The\"Event\"Name");
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForEvent);
+ reaction->setResponseType(Reaction::NextStep);
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+WAITFOR_PARENT_START
+" <waitForEvent receiverName=\"The "receiver" name\" \
+eventName=\"The"Event"Name\"/>\n"
+WAITFOR_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testWaitForEventEmpty() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ WaitForEvent* waitForEvent = new WaitForEvent();
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForEvent);
+ reaction->setResponseType(Reaction::NextStep);
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+WAITFOR_PARENT_START
+" <waitForEvent/>\n"
+WAITFOR_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testWaitForSignal() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ WaitForSignal* waitForSignal = new WaitForSignal();
+ waitForSignal->setEmitterName("The \"emitter\" name");
+ waitForSignal->setSignalName("theSignalName(\"Argument1Type\")");
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForSignal);
+ reaction->setResponseType(Reaction::NextStep);
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+WAITFOR_PARENT_START
+" <waitForSignal emitterName=\"The "emitter" name\" \
+signalName=\"theSignalName("Argument1Type")\"/>\n"
+WAITFOR_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testWaitForSignalEmpty() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ WaitForSignal* waitForSignal = new WaitForSignal();
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForSignal);
+ reaction->setResponseType(Reaction::NextStep);
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+WAITFOR_PARENT_START
+" <waitForSignal/>\n"
+WAITFOR_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testWaitForComposed() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ WaitForSignal* waitForSignalChild = new WaitForSignal();
+ waitForSignalChild->setEmitterName("The emitter name1");
+ waitForSignalChild->setSignalName("theSignalName1()");
+
+ WaitForSignal* waitForSignalGrandChild1 = new WaitForSignal();
+ waitForSignalGrandChild1->setEmitterName("The emitter name2");
+ waitForSignalGrandChild1->setSignalName("theSignalName2()");
+
+ WaitForSignal* waitForSignalGrandChild2 = new WaitForSignal();
+ waitForSignalGrandChild2->setEmitterName("The emitter name3");
+ waitForSignalGrandChild2->setSignalName("theSignalName3()");
+
+ WaitForComposed* waitForOrChild = new WaitForComposed();
+ waitForOrChild->setCompositionType(WaitForComposed::Or);
+ waitForOrChild->addWaitFor(waitForSignalGrandChild1);
+ waitForOrChild->addWaitFor(waitForSignalGrandChild2);
+
+ WaitForComposed* waitForAnd = new WaitForComposed();
+ waitForAnd->setCompositionType(WaitForComposed::And);
+ waitForAnd->addWaitFor(waitForSignalChild);
+ waitForAnd->addWaitFor(waitForOrChild);
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForAnd);
+ reaction->setResponseType(Reaction::NextStep);
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+WAITFOR_PARENT_START
+" <waitForComposed compositionType=\"And\">\n"
+" <waitForSignal emitterName=\"The emitter name1\" \
+signalName=\"theSignalName1()\"/>\n"
+" <waitForComposed compositionType=\"Or\">\n"
+" <waitForSignal emitterName=\"The emitter name2\" \
+signalName=\"theSignalName2()\"/>\n"
+" <waitForSignal emitterName=\"The emitter name3\" \
+signalName=\"theSignalName3()\"/>\n"
+" </waitForComposed>\n"
+" </waitForComposed>\n"
+WAITFOR_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testWaitForComposedEmpty() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ WaitForComposed* waitForAndChild = new WaitForComposed();
+ waitForAndChild->setCompositionType(WaitForComposed::And);
+
+ WaitForComposed* waitForOrChild = new WaitForComposed();
+ waitForOrChild->setCompositionType(WaitForComposed::Or);
+
+ WaitForComposed* waitForAnd = new WaitForComposed();
+ waitForAnd->setCompositionType(WaitForComposed::And);
+ waitForAnd->addWaitFor(waitForAndChild);
+ waitForAnd->addWaitFor(waitForOrChild);
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForAnd);
+ reaction->setResponseType(Reaction::NextStep);
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+WAITFOR_PARENT_START
+" <waitForComposed compositionType=\"And\">\n"
+" <waitForComposed compositionType=\"And\"/>\n"
+" <waitForComposed compositionType=\"Or\"/>\n"
+" </waitForComposed>\n"
+WAITFOR_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testWaitForNot() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ WaitForSignal* waitForSignal = new WaitForSignal();
+ waitForSignal->setEmitterName("The emitter name");
+ waitForSignal->setSignalName("theSignalName()");
+
+ WaitForNot* waitForNot = new WaitForNot();
+ waitForNot->setNegatedWaitFor(waitForSignal);
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForNot);
+ reaction->setResponseType(Reaction::NextStep);
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+WAITFOR_PARENT_START
+" <waitForNot>\n"
+" <waitForSignal emitterName=\"The emitter name\" \
+signalName=\"theSignalName()\"/>\n"
+" </waitForNot>\n"
+WAITFOR_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+void TutorialWriterTest::testWaitForNotWithoutNegatedWaitFor() {
+ Tutorial tutorial;
+ Step* step = new Step();
+ tutorial.addStep(step);
+
+ WaitForNot* waitForNot = new WaitForNot();
+
+ Reaction* reaction = new Reaction();
+ reaction->setTriggerType(Reaction::ConditionMet);
+ reaction->setWaitFor(waitForNot);
+ reaction->setResponseType(Reaction::NextStep);
+ step->addReaction(reaction);
+
+ TutorialWriter saver;
+ QString savedTutorial = saver.writeTutorial(&tutorial);
+
+ QString expected =
+WAITFOR_PARENT_START
+" <waitForNot/>\n"
+WAITFOR_PARENT_END;
+
+ QCOMPARE(savedTutorial, expected);
+}
+
+QTEST_MAIN(TutorialWriterTest)
+
+#include "TutorialWriterTest.moc"
Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/serialization/TutorialWriterTest.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|