Salome HOME
Add tests for drag and drop algo.
[modules/hydro.git] / src / HYDROGUI / test_HYDROGUI_ZLevelsModel.cxx
index 720243bbdb19f8465c66446c3417ffebd60d0e92..0b774229ea738ad343c38cd7b787b6953d37637e 100644 (file)
@@ -315,3 +315,96 @@ void test_HYDROGUI_ZLevelsModel::testMoveOnBottom()
 
   delete aModel;
 }
+
+/**
+  Test drag and drop algorithm.
+*/
+void test_HYDROGUI_ZLevelsModel::testDragAndDrop()
+{
+  HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel();
+  aModel->setObjects( CreateTestObjects( 8 ) );
+  const HYDROGUI_ZLevelsModel::OpType aDnD = HYDROGUI_ZLevelsModel::DragAndDrop;
+
+  // 0. Check the initial state
+  std::string anInitialState = std::string( "*A, B, *C, D, *E, F, *G, H" );
+  CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+  // 1. [] -> B ( i=1 )
+  bool aRes = aModel->move( QList<int>(), aDnD, false, 1 );
+  CPPUNIT_ASSERT_EQUAL( false, aRes );
+  CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+  // 2. ALL -> B ( i=1 )
+  QList<int> anAll;
+  anAll << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7;
+  aRes = aModel->move( anAll, aDnD, false, 1 );
+  CPPUNIT_ASSERT_EQUAL( false, aRes );
+  CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+  // 3. [D, *E, *G] -> D : drop item is among dragged items ( at the beginning )
+  aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 3 );
+  CPPUNIT_ASSERT_EQUAL( false, aRes );
+  CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+  // 4. [D, *E, *G] -> *E : drop item is among dragged items ( in the middle )
+  aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 4 );
+  CPPUNIT_ASSERT_EQUAL( false, aRes );
+  CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+  // 5. [D, *E, *G] -> *G : drop item is among dragged items ( at the end )
+  aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 6 );
+  CPPUNIT_ASSERT_EQUAL( false, aRes );
+  CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+  // 6. [D, *E, *G] -> -1 : drop item index is out of range ( less than zero )
+  aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, -1 );
+  CPPUNIT_ASSERT_EQUAL( false, aRes );
+  CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+  // 7. [D, *E, *G] -> -1 : drop item index is out of range ( more than than (list length - 1) )
+  aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 8 );
+  CPPUNIT_ASSERT_EQUAL( false, aRes );
+  CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) );
+
+  // 8. [D, *E, *G] -> B ( i = 1 )
+  aRes = aModel->move( QList<int>() << 3 << 4 << 6, aDnD, false, 1 );
+  CPPUNIT_ASSERT_EQUAL( true, aRes );
+  CPPUNIT_ASSERT_EQUAL( std::string( "*A, D, *E, *G, B, *C, F, H" ), GetObjects( aModel ) );
+
+  // 9. [*E, F] -> *G
+  aRes = aModel->move( QList<int>() << 2 << 6, aDnD, false, 3 );
+  CPPUNIT_ASSERT_EQUAL( true, aRes );
+  CPPUNIT_ASSERT_EQUAL( std::string( "*A, D, *E, F, *G, B, *C, H" ), GetObjects( aModel ) );
+
+  // 10. [*E, F, *G] -> *A
+  aRes = aModel->move( QList<int>() << 2 << 3 << 4, aDnD, false, 0 );
+  CPPUNIT_ASSERT_EQUAL( true, aRes );
+  CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *G, *A, D, B, *C, H" ), GetObjects( aModel ) );
+
+  // 11. [*G, D, *C, H] -> B
+  aRes = aModel->move( QList<int>() << 2 << 4 << 6 << 7, aDnD, false, 5 );
+  CPPUNIT_ASSERT_EQUAL( true, aRes );
+  CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, *G, D, *C, H, B" ), GetObjects( aModel ) );
+
+  // 12. [F, *A, *G, D, *C, H, B] -> *E
+  QList<int> anAllWithoutFirst;
+  anAllWithoutFirst << 1 << 2 << 3 << 4 << 5 << 6 << 7;
+  aRes = aModel->move( anAllWithoutFirst, aDnD, false, 0 );
+  CPPUNIT_ASSERT_EQUAL( true, aRes );
+  CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, D, *C, H, B, *E" ), GetObjects( aModel ) );
+
+  // 13. [*A, *G] -> D : no changes
+  aRes = aModel->move(  QList<int>() << 1 << 2, aDnD, false, 3 );
+  CPPUNIT_ASSERT_EQUAL( true, aRes );
+  CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, D, *C, H, B, *E" ), GetObjects( aModel ) );
+
+  // 14. [F, *G] -> D
+  aRes = aModel->move(  QList<int>() << 0 << 2, aDnD, false, 3 );
+  CPPUNIT_ASSERT_EQUAL( true, aRes );
+  CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, *G, D, *C, H, B, *E" ), GetObjects( aModel ) );
+
+  // 15. [*A, *G, *C, H, *E] -> D
+  aRes = aModel->move(  QList<int>() << 0 << 2 << 4 << 5 << 7, aDnD, false, 3 );
+  CPPUNIT_ASSERT_EQUAL( true, aRes );
+  CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, *G, *C, H, *E, D, B" ), GetObjects( aModel ) );
+}
\ No newline at end of file