void KisStrokeTest::testRegularStroke() { KisStroke stroke(new KisTestingStrokeStrategy()); QQueue<KisStrokeJob*> &queue = stroke.testingGetQueue(); QCOMPARE(queue.size(), 1); SCOMPARE(getJobName(queue[0]), "init"); QCOMPARE(stroke.isEnded(), false); stroke.addJob(0); QCOMPARE(queue.size(), 2); SCOMPARE(getJobName(queue[0]), "init"); SCOMPARE(getJobName(queue[1]), "dab"); QCOMPARE(stroke.isEnded(), false); stroke.endStroke(); QCOMPARE(queue.size(), 3); SCOMPARE(getJobName(queue[0]), "init"); SCOMPARE(getJobName(queue[1]), "dab"); SCOMPARE(getJobName(queue[2]), "finish"); QCOMPARE(stroke.isEnded(), true); // uncomment this line to catch an assert: // stroke.addJob(0); KisStrokeJob* job; job = stroke.popOneJob(); delete job; QCOMPARE(queue.size(), 2); SCOMPARE(getJobName(queue[0]), "dab"); SCOMPARE(getJobName(queue[1]), "finish"); job = stroke.popOneJob(); delete job; QCOMPARE(queue.size(), 1); SCOMPARE(getJobName(queue[0]), "finish"); job = stroke.popOneJob(); delete job; QCOMPARE(queue.size(), 0); job = stroke.popOneJob(); QCOMPARE(job, (KisStrokeJob*)0); }
void KisStrokeTest::testCancelStrokeCase1() { KisStroke stroke(new KisTestingStrokeStrategy()); QQueue<KisStrokeJob*> &queue = stroke.testingGetQueue(); stroke.addJob(0); // "not initialized, has jobs" QCOMPARE(queue.size(), 2); SCOMPARE(getJobName(queue[0]), "init"); SCOMPARE(getJobName(queue[1]), "dab"); QCOMPARE(stroke.isEnded(), false); stroke.cancelStroke(); QCOMPARE(queue.size(), 0); QCOMPARE(stroke.isEnded(), true); stroke.clearQueue(); }
void KisStrokeTest::testCancelStrokeCase5() { KisStroke stroke(new KisTestingStrokeStrategy()); QQueue<KisStrokeJob*> &queue = stroke.testingGetQueue(); // initialized, no jobs, not finished stroke.addJob(0); delete stroke.popOneJob(); // init delete stroke.popOneJob(); // dab QCOMPARE(stroke.isEnded(), false); stroke.cancelStroke(); QCOMPARE(queue.size(), 1); SCOMPARE(getJobName(queue[0]), "cancel"); QCOMPARE(stroke.isEnded(), true); delete stroke.popOneJob(); // cancel }
void KisStrokeStrategyUndoCommandBasedTest::testFinishedStroke() { QString result; KUndo2CommandSP initCommand(new TestingUndoCommand(kundo2_noi18n("init"), result)); KUndo2CommandSP dabCommand(new TestingUndoCommand(kundo2_noi18n("dab"), result)); KUndo2CommandSP finishCommand(new TestingUndoCommand(kundo2_noi18n("finish"), result)); KisStrokeStrategy *strategy = new KisStrokeStrategyUndoCommandBased(kundo2_noi18n("test"), false, 0, initCommand, finishCommand); KisStroke stroke(strategy); stroke.addJob( new KisStrokeStrategyUndoCommandBased::Data(dabCommand)); stroke.endStroke(); executeStrokeJobs(&stroke); SCOMPARE(result.trimmed(), "init_redo dab_redo finish_redo"); }
void KisStrokeStrategyUndoCommandBasedTest::testCancelledStroke() { QString result; KUndo2CommandSP initCommand(new TestingUndoCommand(kundo2_noi18n("init"), result)); KUndo2CommandSP dabCommand(new TestingUndoCommand(kundo2_noi18n("dab"), result)); KUndo2CommandSP finishCommand(new TestingUndoCommand(kundo2_noi18n("finish"), result)); const KoColorSpace *cs = KoColorSpaceRegistry::instance()->rgb8(); KisImageSP image = new KisImage(0, 300, 300, cs, "test", true); KisStrokeStrategy *strategy = new KisStrokeStrategyUndoCommandBased(kundo2_noi18n("test"), false, image->postExecutionUndoAdapter(), initCommand, finishCommand); KisStrokeId id = image->startStroke(strategy); image->addJob(id, new KisStrokeStrategyUndoCommandBased::Data(dabCommand)); QTest::qSleep(500); image->cancelStroke(id); image->waitForDone(); SCOMPARE(result.trimmed(), "init_redo dab_redo dab_undo init_undo"); }