浏览代码

ctkWorkflow - No backward/forward steps are associated with step not added in workflow

Also added regression test
Jean-Christophe Fillion-Robin 14 年之前
父节点
当前提交
820507c290
共有 2 个文件被更改,包括 24 次插入6 次删除
  1. 20 2
      Libs/Core/Testing/Cpp/ctkWorkflowTest1.cpp
  2. 4 4
      Libs/Core/ctkWorkflow.cpp

+ 20 - 2
Libs/Core/Testing/Cpp/ctkWorkflowTest1.cpp

@@ -267,13 +267,31 @@ int ctkWorkflowTest1(int argc, char * argv [] )
     }
 
   // --------------------------------------------------------------------------
-  // workflow with three steps
+  // Step3
 
-  // add a third step manually
   ctkExampleDerivedWorkflowStep *step3 = new ctkExampleDerivedWorkflowStep(workflow, "Step 3");
   step3->setName("Step 3");
   step3->setDescription("Description for step 3");
 
+  // --------------------------------------------------------------------------
+  // Attempt to retrieve the forward or backward steps of step not yet added to the workflow
+
+  if (workflow->forwardSteps(step3).count() != 0)
+    {
+    std::cerr << "No forward steps should be associated with step3";
+    return EXIT_FAILURE;
+    }
+
+  if (workflow->backwardSteps(step3).count() != 0)
+    {
+    std::cerr << "No backward steps should be associated with step3";
+    return EXIT_FAILURE;
+    }
+
+  // --------------------------------------------------------------------------
+  // workflow with three steps
+
+  // add a third step manually
   if (!workflow->addTransition(step2, step3, "", ctkWorkflow::Forward))
     {
     std::cerr << "could not add step 3 with forward transition";

+ 4 - 4
Libs/Core/ctkWorkflow.cpp

@@ -649,11 +649,11 @@ QList<ctkWorkflowStep*> ctkWorkflow::forwardSteps(ctkWorkflowStep* step)const
 {
   Q_D(const ctkWorkflow);
   // use the given step if provided, otherwise use the workflow's current step
-  if (step)
+  if (step && d->StepToForwardAndBackwardStepMap.contains(step))
     {
     return d->StepToForwardAndBackwardStepMap.value(step)->forwardSteps();
     }
-  else if (d->CurrentStep)
+  else if (d->CurrentStep && d->StepToForwardAndBackwardStepMap.contains(d->CurrentStep))
     {
     return d->StepToForwardAndBackwardStepMap.value(d->CurrentStep)->forwardSteps();
     }
@@ -668,11 +668,11 @@ QList<ctkWorkflowStep*> ctkWorkflow::backwardSteps(ctkWorkflowStep* step)const
 {
   Q_D(const ctkWorkflow);
   // use the current step if provided, otherwise use the workflow's current step
-  if (step)
+  if (step && d->StepToForwardAndBackwardStepMap.contains(step))
     {
     return d->StepToForwardAndBackwardStepMap.value(step)->backwardSteps();
     }
-  else if (d->CurrentStep)
+  else if (d->CurrentStep && d->StepToForwardAndBackwardStepMap.contains(d->CurrentStep))
     {
     return d->StepToForwardAndBackwardStepMap.value(d->CurrentStep)->backwardSteps();
     }