qtmobileextensions/src/keycapture/tsrc/test_xqkeycapture.cpp
changeset 24 9d760f716ca8
parent 14 6fbed849b4f4
child 26 3d09643def13
equal deleted inserted replaced
19:46686fb6258c 24:9d760f716ca8
   117     void testErrorId();
   117     void testErrorId();
   118 	
   118 	
   119 	void testKeyMapperFile();
   119 	void testKeyMapperFile();
   120 
   120 
   121 private:
   121 private:
       
   122 	QString clearString(const QString& line);
   122 	QString clearString(const QString& line, const QString& prefix, const QString& comment);
   123 	QString clearString(const QString& line, const QString& prefix, const QString& comment);
   123     
   124     
   124 private:
   125 private:
   125     XQKeyCapture* keyCapture;
   126     XQKeyCapture* keyCapture;
   126 
   127 
  1567 void TestXQKeyCapture::testErrorId()
  1568 void TestXQKeyCapture::testErrorId()
  1568 {
  1569 {
  1569     keyCapture->errorId();
  1570     keyCapture->errorId();
  1570 }
  1571 }
  1571 
  1572 
       
  1573 QString TestXQKeyCapture::clearString(const QString& line) {
       
  1574     QString s(line);
       
  1575     s.replace(" ", "");
       
  1576     s.replace("\t", "");
       
  1577     return s.trimmed();
       
  1578 }
       
  1579 
  1572 QString TestXQKeyCapture::clearString(const QString& line, const QString& prefix, const QString& comment) {
  1580 QString TestXQKeyCapture::clearString(const QString& line, const QString& prefix, const QString& comment) {
  1573     QString s(line);
  1581     QString s(line);
  1574     s.replace(prefix, comment);
  1582     s.replace(prefix, comment);
  1575     s.replace(" ", "");
  1583     s.replace(" ", "");
  1576     s.replace("\t", "");
  1584     s.replace("\t", "");
  1580 ////////////////////////////////////////////////////////////////
  1588 ////////////////////////////////////////////////////////////////
  1581 // TEST KEY MAPPER FILE
  1589 // TEST KEY MAPPER FILE
  1582 ////////////////////////////////////////////////////////////////
  1590 ////////////////////////////////////////////////////////////////
  1583 void TestXQKeyCapture::testKeyMapperFile()
  1591 void TestXQKeyCapture::testKeyMapperFile()
  1584 {
  1592 {
  1585     QString prefix("    keyMapping.append(KeyMapping(");
  1593     // test only for emulator build
       
  1594     #ifdef __WINSCW__   
       
  1595     
       
  1596     QString firstline("static const KeyMapping keyMapping[] = {");
       
  1597     QString lastline("};");
  1586     QString comment("//");
  1598     QString comment("//");
  1587     
  1599     
  1588     QStringList qt;
  1600     QStringList qt;
  1589     QStringList kc;
  1601     QStringList kc;
  1590 
  1602 
  1591     QFile qtFile("c:\\qkeymapper_s60.cpp");
  1603     QFile qtFile("c:\\qkeymapper_s60.cpp");
  1592     QVERIFY(qtFile.open(QIODevice::ReadOnly | QIODevice::Text));
  1604     QVERIFY2(qtFile.open(QIODevice::ReadOnly | QIODevice::Text), "Failed to open: qtFile");
  1593     
  1605     
  1594     QFile kcFile("c:\\keymapper.cpp");
  1606     QFile kcFile("c:\\keymapper.cpp");
  1595     QVERIFY(kcFile.open(QIODevice::ReadOnly | QIODevice::Text));
  1607     QVERIFY2(kcFile.open(QIODevice::ReadOnly | QIODevice::Text), "Failed to open: kcFile");
  1596     
  1608     
  1597     QTextStream inQtFile(&qtFile);
  1609     QTextStream inQtFile(&qtFile);
       
  1610     bool test(false);
  1598     while (!inQtFile.atEnd()) {
  1611     while (!inQtFile.atEnd()) {
  1599         QString line = inQtFile.readLine();
  1612         QString line = inQtFile.readLine();
  1600         if (line.contains(prefix) && !line.contains(comment)) {
  1613         // trim everything that is on right side of comment and add to list if needed
  1601             qt.append(clearString(line, prefix, comment));
  1614         if (test) qt.append(clearString(line.split(comment).at(0)));
       
  1615         if (line.contains(firstline)) {
       
  1616             test = true;
       
  1617         }
       
  1618         if (line.contains(lastline)) {
       
  1619             test = false;
  1602         }
  1620         }
  1603     }
  1621     }
  1604 
  1622     test = false;
  1605     QTextStream inKcFile(&kcFile);
  1623     QTextStream inKcFile(&kcFile);
  1606     while (!inKcFile.atEnd()) {
  1624     while (!inKcFile.atEnd()) {
  1607         QString line = inKcFile.readLine();
  1625         QString line = inKcFile.readLine();
  1608         if (line.contains(prefix) && !line.contains(comment)) {
  1626         // trim everything that is on right side of comment and add to list if needed
  1609             kc.append(clearString(line, prefix, comment));
  1627         if (test) kc.append(clearString(line.split(comment).at(0)));
       
  1628         if (line.contains(firstline)) {
       
  1629             test = true;
       
  1630         }
       
  1631         if (line.contains(lastline)) {
       
  1632             test = false;
  1610         }
  1633         }
  1611     }
  1634     }
  1612     
  1635     
  1613     QVERIFY(qt.size() == kc.size());
  1636     QVERIFY2(qt.count() == kc.count(), "Amount of lines inside key definition is different");
  1614     
  1637     
  1615     for(int i = 0; i < kc.size(); i++) {
  1638     for(int i = 0; i < kc.size(); i++) {
  1616         QString keys = kc.at(i);
  1639         QString keys = kc.at(i);
  1617         QVERIFY(qt.contains(keys));
  1640         QVERIFY2(qt.contains(keys), "qtFile does not contain key(s) from capture keys");
  1618     }
  1641     }
  1619     
  1642     
  1620     for(int i = 0; i < qt.size(); i++) {
  1643     for(int i = 0; i < qt.size(); i++) {
  1621         QString keys = qt.at(i);
  1644         QString keys = qt.at(i);
  1622         QVERIFY(kc.contains(keys));
  1645         QVERIFY2(kc.contains(keys), "kcFile does not conatin qt keys");
  1623     }    
  1646     }    
       
  1647 #else
       
  1648     // Skip test on hw
       
  1649     QSKIP( "This test is valid only on emulator", SkipSingle);
       
  1650 #endif // __WINSCW__
  1624 }
  1651 }
  1625 
  1652 
  1626 
  1653 
  1627 ////////////////////////////////////////////////////////////////
  1654 ////////////////////////////////////////////////////////////////
  1628 // REQUEST SLOT
  1655 // REQUEST SLOT