[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kdeui/tests
From:       Stephen Kelly <steveire () gmail ! com>
Date:       2010-03-22 13:31:08
Message-ID: 20100322133108.39592AC87E () svn ! kde ! org
[Download RAW message or body]

SVN commit 1106321 by skelly:

Add test infrastructure for item moves.

 M  +80 -0     kselectionproxymodeltest.cpp  
 M  +4 -0      kselectionproxymodeltestsuite.h  
 M  +87 -0     proxymodeltestsuite/modelcommander.cpp  
 M  +9 -0      proxymodeltestsuite/modelcommander.h  
 M  +15 -0     proxymodeltestsuite/modelselector.h  
 M  +112 -0    proxymodeltestsuite/proxymodeltest.h  


--- trunk/KDE/kdelibs/kdeui/tests/kselectionproxymodeltest.cpp #1106320:1106321
@@ -50,6 +50,10 @@
   void testRemoveFromTopLevelData() { noop_testRemoveFromTopLevelData(); }
   void testRemoveFromSecondLevelData() { noop_testRemoveFromSecondLevelData(); }
 
+  void testMoveFromRootData() { noop_testMoveFromRootData(); }
+  void testMoveFromTopLevelData() { noop_testMoveFromTopLevelData(); }
+  void testMoveFromSecondLevelData() { noop_testMoveFromSecondLevelData(); }
+
 private:
   ProxyModelTest *m_proxyModelTest;
 };
@@ -130,6 +134,33 @@
   noop_testRemoveFromSecondLevelData();
 }
 
+template<>
+void TestData<ImmediateSelectionStrategy<9>, \
KSelectionProxyModel::ChildrenOfExactSelection>::testMoveFromRootData() +{
+  noop_testMoveFromRootData();
+}
+
+template<>
+void TestData<ImmediateSelectionStrategy<9>, \
KSelectionProxyModel::ChildrenOfExactSelection>::testMoveFromTopLevelData() +{
+  QTest::addColumn<SignalList>("signalList");
+  QTest::addColumn<PersistentChangeList>("changeList");
+
+  IndexFinder indexFinder;
+
+  newMoveTest("move01", indexFinder, 0, 0, 10, indexFinder, 5);
+  newMoveTest("move02", indexFinder, 4, 4, 10, indexFinder, 0);
+  newMoveTest("move03", indexFinder, 4, 4, 10, indexFinder, 10);
+  newMoveTest("move04", indexFinder, 9, 9, 10, indexFinder, 4);
+  newMoveTest("move05", indexFinder, 9, 9, 10, indexFinder, 0);
+}
+
+template<>
+void TestData<ImmediateSelectionStrategy<9>, \
KSelectionProxyModel::ChildrenOfExactSelection>::testMoveFromSecondLevelData() +{
+  noop_testMoveFromSecondLevelData();
+}
+
 //END ChildrenOfExactSelection
 
 //BEGIN ExactSelection
@@ -181,6 +212,37 @@
 {
   noop_testRemoveFromSecondLevelData();
 }
+
+template<>
+void TestData<ImmediateSelectionStrategy<9>, \
KSelectionProxyModel::ExactSelection>::testMoveFromRootData() +{
+  noop_testMoveFromRootData();
+}
+
+template<>
+void TestData<ImmediateSelectionStrategy<9>, \
KSelectionProxyModel::ExactSelection>::testMoveFromTopLevelData() +{
+  QTest::addColumn<SignalList>("signalList");
+  QTest::addColumn<PersistentChangeList>("changeList");
+  noopTest("move01");
+  noopTest("move02");
+  noopTest("move03");
+  noopTest("move04");
+  noopTest("move05");
+}
+
+template<>
+void TestData<ImmediateSelectionStrategy<9>, \
KSelectionProxyModel::ExactSelection>::testMoveFromSecondLevelData() +{
+  QTest::addColumn<SignalList>("signalList");
+  QTest::addColumn<PersistentChangeList>("changeList");
+  noopTest("move01");
+  noopTest("move02");
+  noopTest("move03");
+  noopTest("move04");
+  noopTest("move05");
+}
+
 //END ExactSelection
 
 //BEGIN SubTrees
@@ -233,6 +295,24 @@
   testForwardingRemoveData(IndexFinder(QList<int>() << 0 << 5));
 }
 
+template<>
+void TestData<ImmediateSelectionStrategy<9>, \
KSelectionProxyModel::SubTrees>::testMoveFromRootData() +{
+  noop_testMoveFromRootData();
+}
+
+template<>
+void TestData<ImmediateSelectionStrategy<9>, \
KSelectionProxyModel::SubTrees>::testMoveFromTopLevelData() +{
+  testForwardingMoveData(IndexFinder(QList<int>() << 0), IndexFinder(QList<int>() << \
0)); +}
+
+template<>
+void TestData<ImmediateSelectionStrategy<9>, \
KSelectionProxyModel::SubTrees>::testMoveFromSecondLevelData() +{
+  testForwardingMoveData(IndexFinder(QList<int>() << 0 << 5), \
IndexFinder(QList<int>() << 0 << 5)); +}
+
 //END SubTrees
 
 //END ImmediateSelectionStrategy
--- trunk/KDE/kdelibs/kdeui/tests/kselectionproxymodeltestsuite.h #1106320:1106321
@@ -99,6 +99,10 @@
   /* reimp */ void testRemoveFromRootData() { \
SelectorStrategy::testRemoveFromRootData(); }  /* reimp */ void \
testRemoveFromTopLevelData() { SelectorStrategy::testRemoveFromTopLevelData(); }  /* \
reimp */ void testRemoveFromSecondLevelData() { \
SelectorStrategy::testRemoveFromSecondLevelData(); } +
+  /* reimp */ void testMoveFromRootData() { \
SelectorStrategy::testMoveFromRootData(); } +  /* reimp */ void \
testMoveFromTopLevelData() { SelectorStrategy::testMoveFromTopLevelData(); } +  /* \
reimp */ void testMoveFromSecondLevelData() { \
SelectorStrategy::testMoveFromSecondLevelData(); }  };
 
 /**
--- trunk/KDE/kdelibs/kdeui/tests/proxymodeltestsuite/modelcommander.cpp \
#1106320:1106321 @@ -103,6 +103,21 @@
   initTestModel(dataTag);
 }
 
+void ModelCommander::init_testMoveFromRoot(const QString& dataTag)
+{
+  initTestModel(dataTag);
+}
+
+void ModelCommander::init_testMoveFromSecondLevel(const QString& dataTag)
+{
+  initTestModel(dataTag);
+}
+
+void ModelCommander::init_testMoveFromTopLevel(const QString& dataTag)
+{
+  initTestModel(dataTag);
+}
+
 void ModelCommander::initTestModel(const QString &dataTag)
 {
   Q_UNUSED(dataTag);
@@ -188,6 +203,21 @@
   return executeTestRemove(QList<int>() << 5 << 5, dataTag);
 }
 
+QStringList ModelCommander::execute_testMoveFromRoot(const QString &dataTag)
+{
+  return executeTestMove(QList<int>(), dataTag);
+}
+
+QStringList ModelCommander::execute_testMoveFromTopLevel(const QString &dataTag)
+{
+  return executeTestMove(QList<int>() << 5, dataTag);
+}
+
+QStringList ModelCommander::execute_testMoveFromSecondLevel(const QString &dataTag)
+{
+  return executeTestMove(QList<int>() << 5 << 5, dataTag);
+}
+
 void ModelCommander::execute(ModelChangeCommand* command)
 {
   m_currentCommand = command;
@@ -234,6 +264,63 @@
   return testData;
 }
 
+QStringList ModelCommander::executeTestMove(QList<int> rowAncestors, const QString \
&dataTag) +{
+  static const QStringList testData = QStringList() << "move01"
+                                                    << "move02"
+                                                    << "move03"
+                                                    << "move04"
+                                                    << "move05";
+
+  if(dataTag.isEmpty())
+    return testData;
+
+  ModelMoveCommand *move = new ModelMoveCommand(m_model, this);
+  if (dataTag == testData.at(0))
+  {
+    // Move a single item from the top to the middle in the same parent.
+    move->setAncestorRowNumbers(rowAncestors);
+    move->setStartRow(0);
+    move->setEndRow(0);
+    move->setDestAncestors(rowAncestors);
+    move->setDestRow(5);
+  } else if (dataTag == testData.at(1))
+  {
+    // Move a single item from the middle to the top in the same parent.
+    move->setAncestorRowNumbers(rowAncestors);
+    move->setStartRow(4);
+    move->setEndRow(4);
+    move->setDestAncestors(rowAncestors);
+    move->setDestRow(0);
+  } else if (dataTag == testData.at(2))
+  {
+    // Move a single item from the middle to the bottom in the same parent.
+    move->setAncestorRowNumbers(rowAncestors);
+    move->setStartRow(4);
+    move->setEndRow(4);
+    move->setDestAncestors(rowAncestors);
+    move->setDestRow(10);
+  } else if (dataTag == testData.at(3))
+  {
+    // Move a single item from the bottom to the middle in the same parent.
+    move->setAncestorRowNumbers(rowAncestors);
+    move->setStartRow(9);
+    move->setEndRow(9);
+    move->setDestAncestors(rowAncestors);
+    move->setDestRow(4);
+  } else if (dataTag == testData.at(4))
+  {
+    // Move a single item from the bottom to the top in the same parent.
+    move->setAncestorRowNumbers(rowAncestors);
+    move->setStartRow(9);
+    move->setEndRow(9);
+    move->setDestAncestors(rowAncestors);
+    move->setDestRow(0);
+  }
+  execute(move);
+  return testData;
+}
+
 QStringList ModelCommander::executeTestInsert(QList<int> rowAncestors, const QString \
&dataTag)  {
   static const QStringList testData = QStringList() << "insert01"
--- trunk/KDE/kdelibs/kdeui/tests/proxymodeltestsuite/modelcommander.h \
#1106320:1106321 @@ -44,6 +44,10 @@
   void init_testRemoveFromTopLevel(const QString &dataTag);
   void init_testRemoveFromSecondLevel(const QString &dataTag);
 
+  void init_testMoveFromRoot(const QString &dataTag);
+  void init_testMoveFromTopLevel(const QString &dataTag);
+  void init_testMoveFromSecondLevel(const QString &dataTag);
+
   QStringList execute_testInsertWhenEmpty(const QString &dataTag);
   QStringList execute_testInsertInRoot(const QString &dataTag);
   QStringList execute_testInsertInTopLevel(const QString &dataTag);
@@ -53,9 +57,14 @@
   QStringList execute_testRemoveFromTopLevel(const QString &dataTag);
   QStringList execute_testRemoveFromSecondLevel(const QString &dataTag);
 
+  QStringList execute_testMoveFromRoot(const QString &dataTag);
+  QStringList execute_testMoveFromTopLevel(const QString &dataTag);
+  QStringList execute_testMoveFromSecondLevel(const QString &dataTag);
+
 private:
   QStringList executeTestInsert(QList<int> rowAncestors, const QString &dataTag);
   QStringList executeTestRemove(QList<int> rowAncestors, const QString &dataTag);
+  QStringList executeTestMove(QList<int> rowAncestors, const QString &dataTag);
 
   void initTestModel(const QString &dataTag);
 
--- trunk/KDE/kdelibs/kdeui/tests/proxymodeltestsuite/modelselector.h \
#1106320:1106321 @@ -87,6 +87,21 @@
     dummyTestData();
   }
 
+  void testMoveFromRootData()
+  {
+    dummyTestData();
+  }
+
+  void testMoveFromTopLevelData()
+  {
+    dummyTestData();
+  }
+
+  void testMoveFromSecondLevelData()
+  {
+    dummyTestData();
+  }
+
 protected slots:
   void modelDestroyed() {
     m_model = 0;
--- trunk/KDE/kdelibs/kdeui/tests/proxymodeltestsuite/proxymodeltest.h \
#1106320:1106321 @@ -62,6 +62,9 @@
   virtual void testRemoveFromTopLevelData() = 0;
   virtual void testRemoveFromSecondLevelData() = 0;
 
+  virtual void testMoveFromRootData() = 0;
+  virtual void testMoveFromTopLevelData() = 0;
+  virtual void testMoveFromSecondLevelData() = 0;
 };
 
 class BuiltinTestInterface : BuiltinTestDataInterface
@@ -89,6 +92,16 @@
 
   virtual void testRemoveFromSecondLevel_data() = 0;
   virtual void testRemoveFromSecondLevel() = 0;
+
+  virtual void testMoveFromRoot_data() = 0;
+  virtual void testMoveFromRoot() = 0;
+
+  virtual void testMoveFromTopLevel_data() = 0;
+  virtual void testMoveFromTopLevel() = 0;
+
+  virtual void testMoveFromSecondLevel_data() = 0;
+  virtual void testMoveFromSecondLevel() = 0;
+
 };
 
 class ProxyModelTest : public QObject, protected BuiltinTestInterface
@@ -110,6 +123,8 @@
   QVariantList noSignal() const { return QVariantList() << NoSignal; }
   QVariantList getSignal(SignalType type, IndexFinder parentFinder, int start, int \
end) const  { return QVariantList() << type << QVariant::fromValue(parentFinder) << \
start << end; } +  QVariantList getSignal(SignalType type, IndexFinder srcFinder, int \
start, int end, IndexFinder destFinder, int destStart) const +  { return \
QVariantList() << type << QVariant::fromValue(srcFinder) << start << end << \
QVariant::fromValue(destFinder) << destStart; }  
 protected:
   virtual QAbstractProxyModel* getProxy() = 0;
@@ -127,6 +142,10 @@
   void testRemoveFromTopLevelData();
   void testRemoveFromSecondLevelData();
 
+  void testMoveFromRootData();
+  void testMoveFromTopLevelData();
+  void testMoveFromSecondLevelData();
+
 protected slots:
   void testMappings();
   void verifyModel(const QModelIndex &parent, int start, int end);
@@ -163,6 +182,15 @@
   void testRemoveFromSecondLevel_data() { testRemoveFromSecondLevelData(); }
   void testRemoveFromSecondLevel() { doTest(); }
 
+  void testMoveFromRoot_data() { testMoveFromRootData(); }
+  void testMoveFromRoot() { doTest(); }
+
+  void testMoveFromTopLevel_data() { testMoveFromTopLevelData(); }
+  void testMoveFromTopLevel() { doTest(); }
+
+  void testMoveFromSecondLevel_data() { testMoveFromSecondLevelData(); }
+  void testMoveFromSecondLevel() { doTest(); }
+
 protected:
   void connectTestSignals(QObject *reciever);
   void disconnectTestSignals(QObject *reciever);
@@ -231,6 +259,18 @@
     QTest::newRow(name.toAscii()) << SignalList() << PersistentChangeList();
   }
 
+  void noopLayoutChangeTest(const QString &name)
+  {
+    processTestName(name);
+
+    SignalList signalList;
+
+    signalList << ( QVariantList() << LayoutAboutToBeChanged );
+    signalList << ( QVariantList() << LayoutChanged );
+
+    QTest::newRow(name.toAscii()) << signalList << PersistentChangeList();
+  }
+
   void testForwardingInsertData(const IndexFinder &indexFinder)
   {
     QTest::addColumn<SignalList>("signalList");
@@ -270,6 +310,18 @@
     newRemoveTest("remove03", indexFinder, 9, 9, 10);
   }
 
+  void testForwardingMoveData(const IndexFinder &srcFinder, const IndexFinder \
&destFinder) +  {
+    QTest::addColumn<SignalList>("signalList");
+    QTest::addColumn<PersistentChangeList>("changeList");
+
+    newMoveTest("move01", srcFinder, 0, 0, 10, destFinder, 5);
+    newMoveTest("move02", srcFinder, 4, 4, 10, destFinder, 0);
+    newMoveTest("move03", srcFinder, 4, 4, 10, destFinder, 10);
+    newMoveTest("move04", srcFinder, 9, 9, 10, destFinder, 4);
+    newMoveTest("move05", srcFinder, 9, 9, 10, destFinder, 0);
+  }
+
   void newInsertTest(const QString &name, const IndexFinder &indexFinder, int start, \
int end, int rowCount)  {
     processTestName(name);
@@ -305,6 +357,41 @@
     QTest::newRow(name.toAscii()) << signalList << persistentList;
   }
 
+  void newMoveTest(const QString &name, const IndexFinder &srcFinder, int start, int \
end, int rowCount, const IndexFinder &destFinder, int destStart) +  {
+    processTestName(name);
+
+    SignalList signalList;
+    PersistentChangeList persistentList;
+
+    signalList << m_proxyModelTest->getSignal(RowsAboutToBeMoved, srcFinder, start, \
end, destFinder, destStart); +    signalList << ( QVariantList() << \
LayoutAboutToBeChanged ); +    signalList << m_proxyModelTest->getSignal(RowsMoved, \
srcFinder, start, end, destFinder, destStart); +    signalList << ( QVariantList() << \
LayoutChanged ); +
+    const bool sameParent = (srcFinder == destFinder);
+    const bool movingUp = (start > destStart);
+
+    if ( sameParent )
+    {
+      if ( movingUp )
+      {
+        persistentList << m_proxyModelTest->getChange( srcFinder, destStart, start \
-1, end - start + 1 ); +        persistentList << m_proxyModelTest->getChange( \
srcFinder, start, end, -1 * (start - destStart) ); +      } else {
+        persistentList << m_proxyModelTest->getChange( srcFinder, start, end, \
destStart - end - 1 ); +        persistentList << m_proxyModelTest->getChange( \
srcFinder, end + 1, destStart - 1, -1 * (end - start + 1) ); +      }
+    } else {
+      if ( movingUp )
+      {
+        // TODO
+      }
+    }
+
+    QTest::newRow(name.toAscii()) << signalList << persistentList;
+  }
+
   void noop_testInsertWhenEmptyData()
   {
     QTest::addColumn<SignalList>("signalList");
@@ -376,6 +463,31 @@
     noop_testRemoveFromRootData();
   }
 
+  void noop_testMoveFromRootData()
+  {
+    QTest::addColumn<SignalList>("signalList");
+    QTest::addColumn<PersistentChangeList>("changeList");
+
+    // These commands have no effect because this model shows children of selection.
+
+    noopTest("move01");
+    noopTest("move02");
+    noopTest("move03");
+    noopTest("move04");
+    noopTest("move05");
+  }
+
+  void noop_testMoveFromTopLevelData()
+  {
+    // Same test names etc.
+    noop_testMoveFromRootData();
+  }
+
+  void noop_testMoveFromSecondLevelData()
+  {
+    noop_testMoveFromRootData();
+  }
+
   ProxyModelTest *m_proxyModelTest;
   QString m_currentTestFunction;
   QSet<QString> m_testNames;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic