testfwuis/symbianunittestui/qt/testitemlist.cpp
changeset 2 453d490c84a5
equal deleted inserted replaced
1:753e33780645 2:453d490c84a5
       
     1 /*
       
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: class to setup mapping of individual test cases and dll files.
       
    15  *
       
    16  */
       
    17 
       
    18 #include "testitemlist.h"
       
    19 
       
    20 TestItemList::TestItemList()
       
    21     {
       
    22     }
       
    23 
       
    24 TestItemList::~TestItemList()
       
    25     {
       
    26     removeAll();
       
    27     }
       
    28 
       
    29 void TestItemList::removeAll()
       
    30     {
       
    31     for (QList<TestItem*>::iterator iter = listItems.begin(); iter
       
    32             < listItems.end(); ++iter)
       
    33         {
       
    34         delete (*iter);
       
    35         }
       
    36     listItems.clear();
       
    37     }
       
    38 
       
    39 bool TestItemList::findItem(const QString& item, TestItem*& testItem) const
       
    40     {
       
    41     for (QList<TestItem*>::const_iterator iter = listItems.begin(); iter
       
    42             < listItems.end(); ++iter)
       
    43         {
       
    44         if ((*iter)->itemName.compare(item) == 0)
       
    45             {
       
    46             testItem = *iter;
       
    47             return true;
       
    48             }
       
    49         }
       
    50     return false;
       
    51     }
       
    52 
       
    53 void TestItemList::removeItem(const QString& item)
       
    54     {
       
    55     TestItem* temp;
       
    56     if (findItem(item, temp))
       
    57         {
       
    58         listItems.removeOne(temp);
       
    59         delete temp;
       
    60         }
       
    61     }
       
    62 
       
    63 void TestItemList::removeOneSubItem(const QString& item,
       
    64         const QString& subItem)
       
    65     {
       
    66     TestItem* temp;
       
    67     if (findItem(item, temp))
       
    68         {
       
    69         temp->subItemNames.removeOne(subItem);
       
    70         if (temp->subItemNames.count() == 0)
       
    71             {
       
    72             removeItem(item);
       
    73             }
       
    74         }
       
    75     }
       
    76 
       
    77 void TestItemList::addItemExclusively(const QString& item,
       
    78         const QStringList& subItem)
       
    79     {
       
    80     TestItem* temp;
       
    81     if (!findItem(item, temp))
       
    82         {
       
    83         listItems.append(new TestItem(item, subItem));
       
    84         }
       
    85     }
       
    86 
       
    87 void TestItemList::addItemExclusively(const QString& item)
       
    88     {
       
    89     TestItem* temp;
       
    90     if (!findItem(item, temp))
       
    91         {
       
    92         QStringList subItem;
       
    93         listItems.append(new TestItem(item, subItem));
       
    94         }
       
    95     }
       
    96 
       
    97 void TestItemList::addOneSubItem(const QString& item, const QString& subItem)
       
    98     {
       
    99     TestItem* temp;
       
   100     if (!findItem(item, temp))
       
   101         {
       
   102         QStringList subItems;
       
   103         subItems << subItem;
       
   104         addItemExclusively(item, subItems);
       
   105         }
       
   106     else if (!temp->subItemNames.contains(subItem))
       
   107         {
       
   108         (temp->subItemNames) << subItem;
       
   109         }
       
   110     }
       
   111 
       
   112 int TestItemList::count() const
       
   113     {
       
   114     return listItems.count();
       
   115     }
       
   116 
       
   117 QStringList TestItemList::items() const
       
   118     {
       
   119     QStringList temp;
       
   120     for (QList<TestItem*>::const_iterator iter = listItems.begin(); iter
       
   121             < listItems.end(); ++iter)
       
   122         {
       
   123         temp << (*iter)->itemName;
       
   124         }
       
   125     return temp;
       
   126     }
       
   127 
       
   128 QStringList TestItemList::subItems() const
       
   129     {
       
   130     QStringList temp;
       
   131     for (QList<TestItem*>::const_iterator iter = listItems.begin(); iter
       
   132             < listItems.end(); ++iter)
       
   133         {
       
   134         temp << (*iter)->subItemNames;
       
   135         }
       
   136     return temp;
       
   137     }
       
   138 
       
   139 bool TestItemList::empty() const
       
   140     {
       
   141     return listItems.count() == 0;
       
   142     }
       
   143 
       
   144 bool TestItemList::exists(const QString& itemName) const
       
   145     {
       
   146     TestItem* temp;
       
   147     return findItem(itemName, temp);
       
   148     }
       
   149 
       
   150 bool TestItemList::isEqual(const TestItemList* itemList)
       
   151     {
       
   152     bool ret = this->count() == itemList->count();
       
   153     if (ret)
       
   154         {
       
   155         QStringList subItems = this->subItems();
       
   156         ret = subItems.count() == itemList->subItems().count();
       
   157         if (ret)
       
   158             {
       
   159             QStringList items = this->items();
       
   160             foreach(QString tempItem, itemList->items())
       
   161                     {
       
   162                     if (!items.contains(tempItem, Qt::CaseInsensitive))
       
   163                         {
       
   164                         return false;
       
   165                         }
       
   166                     }
       
   167             foreach(QString tempSubItem, itemList->subItems())
       
   168                     {
       
   169                     if (!subItems.contains(tempSubItem, Qt::CaseInsensitive))
       
   170                         {
       
   171                         return false;
       
   172                         }
       
   173                     }
       
   174             }
       
   175         }
       
   176     return ret;
       
   177     }
       
   178 
       
   179 TestItemList::TestItem::TestItem()
       
   180     {
       
   181     }
       
   182 
       
   183 TestItemList::TestItem::TestItem(QString name, QStringList cases) :
       
   184     itemName(name), subItemNames(cases)
       
   185     {
       
   186     }
       
   187 
       
   188 TestItemList::TestItem::~TestItem()
       
   189     {
       
   190     }
       
   191 
       
   192 QString TestItemList::TestItem::getFullQulifiedCaseName(const QString& str)
       
   193     {
       
   194     // TODO
       
   195     return QString(str);
       
   196     }
       
   197 
       
   198 bool TestItemList::TestItem::isEqual(const TestItem& item)
       
   199     {
       
   200     // TODO: to be extended.
       
   201     return itemName.compare(item.itemName) == 0;
       
   202     }