camerauis/cameraxui/cxengine/tsrc/unit/unittest_cxefeaturemanagerimp/unittest_cxefeaturemanagerimp.cpp
changeset 19 d9aefe59d544
child 37 64817133cd1d
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QTest>
       
    19 
       
    20 #include "unittest_cxefeaturemanagerimp.h"
       
    21 #include "cxefakesettingsmodel.h"
       
    22 #include "cxefeaturemanagerimp.h"
       
    23 
       
    24 UnitTestCxeFeatureManager::UnitTestCxeFeatureManager()
       
    25 : mFakeSettingsModel(NULL), mFeatureManager(NULL)
       
    26 {
       
    27 }
       
    28 
       
    29 UnitTestCxeFeatureManager::~UnitTestCxeFeatureManager()
       
    30 {
       
    31 
       
    32 }
       
    33 
       
    34 // Run before each individual test case
       
    35 void UnitTestCxeFeatureManager::init()
       
    36 {
       
    37     mFakeSettingsModel = new CxeFakeSettingsModel();
       
    38     mFeatureManager = new CxeFeatureManagerImp(*mFakeSettingsModel);
       
    39 }
       
    40 
       
    41 // Run after each individual test case
       
    42 void UnitTestCxeFeatureManager::cleanup()
       
    43 {
       
    44     delete mFakeSettingsModel;
       
    45     mFakeSettingsModel = 0;
       
    46 
       
    47     delete mFeatureManager;
       
    48     mFeatureManager = 0;
       
    49 }
       
    50 
       
    51 // Testing that isFeatureSupported function returns correct values
       
    52 void UnitTestCxeFeatureManager::testSupportedKeys()
       
    53 {
       
    54     // Create a key that won't be added to test data
       
    55     QString falseKey = QString("testKeyFalse");
       
    56     bool isSupported;
       
    57     CxeError::Id err;
       
    58 
       
    59     // Test that key that is not added to test data is not found
       
    60     // also boolean value isSupported should return false as key is not found
       
    61     err = mFeatureManager->isFeatureSupported(falseKey, isSupported);
       
    62     QVERIFY(!isSupported);
       
    63     QCOMPARE(err, CxeError::NotFound);
       
    64 
       
    65     // create and set test data with "testKeyTrue" key
       
    66     QString trueKey = QString("testKeyTrue");
       
    67     QList<QVariant> value;
       
    68     value.append(1);
       
    69     value.append(2);
       
    70     value.append(3);
       
    71     mFakeSettingsModel->set(trueKey, value);
       
    72 
       
    73     // the false key should return the same values as before adding true key to test data
       
    74     err = mFeatureManager->isFeatureSupported(falseKey, isSupported);
       
    75     QVERIFY(!isSupported);
       
    76     QCOMPARE(err, CxeError::NotFound);
       
    77 
       
    78     // check that just added key can be found from test data and no error occurs
       
    79     err = mFeatureManager->isFeatureSupported(trueKey, isSupported);
       
    80     QVERIFY(isSupported);
       
    81     QCOMPARE(err, CxeError::None);
       
    82 
       
    83 }
       
    84 
       
    85 // test that configuredValues function returns a correct error code and not any values
       
    86 // with any arbitrary key when there is no data set
       
    87 void UnitTestCxeFeatureManager::testConfiguredValuesEmptyData()
       
    88 {
       
    89     QString falseKey = QString("testKeyFalse");
       
    90     QList<int> values;
       
    91     CxeError::Id err;
       
    92 
       
    93     // no data
       
    94     err = mFeatureManager->configuredValues(falseKey,values);
       
    95     QCOMPARE(err, CxeError::NotFound);
       
    96     QCOMPARE(values.count(), 0);
       
    97 
       
    98 }
       
    99 
       
   100 // test that configuredValues function returns a correct error code and not any values
       
   101 // with any arbitrary key when there is data set but not for false key
       
   102 void UnitTestCxeFeatureManager::testConfiguredValuesFalseKey()
       
   103 {
       
   104     QString falseKey = QString("testKeyFalse");
       
   105     QString trueKey = QString("testKeyTrue");
       
   106     QList<QVariant> value;
       
   107     value.append(1);
       
   108     value.append(2);
       
   109     value.append(3);
       
   110     mFakeSettingsModel->set(trueKey, value);
       
   111 
       
   112     CxeError::Id err;
       
   113     QList<int> values;
       
   114 
       
   115     // false key
       
   116     err = mFeatureManager->configuredValues(falseKey, values);
       
   117     QCOMPARE(err, CxeError::NotFound);
       
   118     // as key is not found values list should be empty
       
   119     QCOMPARE(values.count(), 0);
       
   120 }
       
   121 
       
   122 // test data is set with the same key that is used for fetching configured values
       
   123 // Now error code should be None as the key should be found from the data
       
   124 // Also value count should match with the amount of set values
       
   125 void UnitTestCxeFeatureManager::testConfiguredValuesTrueKeyAndData()
       
   126 {
       
   127     QString trueKey = QString("testKeyTrue");
       
   128     QList<QVariant> value;
       
   129     // values added to key
       
   130     value.append(1);
       
   131     value.append(2);
       
   132     value.append(3);
       
   133     mFakeSettingsModel->set(trueKey, value);
       
   134 
       
   135     CxeError::Id err;
       
   136     QList<int> values;
       
   137 
       
   138     // true key
       
   139     err = mFeatureManager->configuredValues(trueKey, values);
       
   140     QCOMPARE(err, CxeError::None);
       
   141     QCOMPARE(values.count(), 3);
       
   142 }
       
   143 
       
   144 // Currently only integer type values can be fetched with configuredValues-function.
       
   145 // Test that proper error code is returned when data values are something else than integers
       
   146 void UnitTestCxeFeatureManager::testConfiguredValuesFalseData()
       
   147 {
       
   148     QString trueKey = QString("testKeyTrue");
       
   149     QList<QVariant> value;
       
   150     value.append(1);
       
   151     value.append(2);
       
   152     value.append(true); // add boolean value which is not supported
       
   153     mFakeSettingsModel->set(trueKey, value);
       
   154 
       
   155     CxeError::Id err;
       
   156     QList<int> values;
       
   157 
       
   158     // getting configured values should fail as boolean values are not supported
       
   159     err = mFeatureManager->configuredValues(trueKey, values);
       
   160     QCOMPARE(err, CxeError::NotSupported);
       
   161 
       
   162 }
       
   163 
       
   164 // main() function non-GUI testing
       
   165 QTEST_MAIN(UnitTestCxeFeatureManager);