From a5ab567d491bddcd830f8ed617f30e1940c474e6 Mon Sep 17 00:00:00 2001 From: mzn Date: Fri, 21 Mar 2014 14:19:04 +0000 Subject: [PATCH] Add tests for drag and drop algo. --- src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx | 93 +++++++++++++++++++++ src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h | 2 + 2 files changed, 95 insertions(+) diff --git a/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx b/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx index 720243bb..0b774229 100644 --- a/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx +++ b/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx @@ -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(), aDnD, false, 1 ); + CPPUNIT_ASSERT_EQUAL( false, aRes ); + CPPUNIT_ASSERT_EQUAL( anInitialState, GetObjects( aModel ) ); + + // 2. ALL -> B ( i=1 ) + QList 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() << 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() << 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() << 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() << 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() << 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() << 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() << 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() << 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() << 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 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() << 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() << 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() << 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 diff --git a/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h b/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h index 167b66ef..c8f0eeab 100644 --- a/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h +++ b/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h @@ -8,6 +8,7 @@ class test_HYDROGUI_ZLevelsModel : public CppUnit::TestFixture { CPPUNIT_TEST(testMoveOnTop); CPPUNIT_TEST(testMoveDown); CPPUNIT_TEST(testMoveOnBottom); + CPPUNIT_TEST(testDragAndDrop); CPPUNIT_TEST_SUITE_END(); private: @@ -18,6 +19,7 @@ public: void testMoveOnTop(); void testMoveDown(); void testMoveOnBottom(); + void testDragAndDrop(); }; CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROGUI_ZLevelsModel); -- 2.39.2