camerauis/cameraxui/cxengine/tsrc/unit/unittest_cxesettingscenrepstore/unittest_cxesettingscenrepstore.cpp
changeset 19 d9aefe59d544
child 24 2094593137f5
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 "cxeerror.h"
       
    21 #include "cxutils.h"
       
    22 #include "cxesettingscenrepstore.h"
       
    23 #include "unittest_cxesettingscenrepstore.h"
       
    24 #include "cxenamespace.h"
       
    25 #include "cxecenrepkeys.h"
       
    26 
       
    27 // constants
       
    28 static const char* INVALID_KEY = "invalid key";
       
    29 static const char* EMPTY_KEY = "";
       
    30 
       
    31 /**
       
    32 * UnitTestCxeSettingsCenrepStore::UnitTestCxeSettingsCenrepStore()
       
    33 */
       
    34 UnitTestCxeSettingsCenrepStore::UnitTestCxeSettingsCenrepStore()
       
    35 : mSettingsCenrepStore(NULL)
       
    36 {
       
    37 }
       
    38 
       
    39 /**
       
    40 * UnitTestCxeSettingsCenrepStore::~UnitTestCxeSettingsCenrepStore()
       
    41 */
       
    42 UnitTestCxeSettingsCenrepStore::~UnitTestCxeSettingsCenrepStore()
       
    43 {
       
    44     cleanup();
       
    45 }
       
    46 
       
    47 /**
       
    48 * UnitTestCxeSettingsCenrepStore::init()
       
    49 */
       
    50 void UnitTestCxeSettingsCenrepStore::init()
       
    51 {
       
    52     mSettingsCenrepStore = new CxeSettingsCenRepStore();
       
    53 }
       
    54 
       
    55 /**
       
    56 * UnitTestCxeSettingsCenrepStore::cleanup()
       
    57 */
       
    58 void UnitTestCxeSettingsCenrepStore::cleanup()
       
    59 {
       
    60     delete mSettingsCenrepStore;
       
    61     mSettingsCenrepStore = NULL;
       
    62 }
       
    63 
       
    64 
       
    65 /**
       
    66 * UnitTestCxeSettingsCenrepStore::testSettingValues()
       
    67 */
       
    68 void UnitTestCxeSettingsCenrepStore::testSettingValues()
       
    69 {
       
    70     QString runtimekey = CxeRuntimeKeys::PRIMARY_CAMERA_CAPTURE_KEYS;
       
    71     QString settingkey = CxeSettingIds::FNAME_MONTH_FOLDER;
       
    72     QString scenekey = CxeSettingIds::COLOR_TONE;
       
    73     QVariant result;
       
    74     QVariant value = QVariant(2);
       
    75     CxeError::Id error;
       
    76     
       
    77     // case 0: check default value of a runtime key, real setting key and scene key
       
    78     error = mSettingsCenrepStore->get(runtimekey, result);
       
    79     QVERIFY(error == CxeError::None);
       
    80     QCOMPARE(result.toInt(), 1);
       
    81     
       
    82     error = mSettingsCenrepStore->get(settingkey, result);
       
    83     QVERIFY(error == CxeError::None);
       
    84     QCOMPARE(result.toInt(), 1);
       
    85     
       
    86     // scene key shouldnt be read from cenrepstore 
       
    87     error = mSettingsCenrepStore->get(scenekey, result);
       
    88     QVERIFY(error == CxeError::NotFound);
       
    89 
       
    90     
       
    91     // case 1: try setting a value to a run-time key and real setting key
       
    92     error = mSettingsCenrepStore->set(runtimekey, value);
       
    93     QVERIFY(error == CxeError::NotFound);
       
    94     
       
    95     error = mSettingsCenrepStore->set(settingkey, value);
       
    96     QVERIFY(error == CxeError::None);
       
    97     
       
    98     error = mSettingsCenrepStore->set(scenekey, value);
       
    99     QVERIFY(error == CxeError::NotFound);
       
   100     
       
   101     // case 2: try setting with invalid key
       
   102     error = mSettingsCenrepStore->set(INVALID_KEY, value);
       
   103     QVERIFY(error == CxeError::NotFound);
       
   104     
       
   105     error = mSettingsCenrepStore->set(EMPTY_KEY, value);
       
   106     QVERIFY(error == CxeError::NotFound);
       
   107     
       
   108     // case 3: try reading a value with invalid key
       
   109     error = mSettingsCenrepStore->get(INVALID_KEY, value);
       
   110     QVERIFY(error == CxeError::NotFound);
       
   111     
       
   112     error = mSettingsCenrepStore->get(EMPTY_KEY, value);
       
   113     QVERIFY(error == CxeError::NotFound);
       
   114 
       
   115     // case 4: check if the new value is properly set to a real setting key
       
   116     error = mSettingsCenrepStore->get(settingkey, result);
       
   117     QVERIFY(error == CxeError::None);
       
   118     QCOMPARE(result.toInt(), 2);
       
   119 }
       
   120 
       
   121 /**
       
   122 * UnitTestCxeSettingsCenrepStore::testloadSettings
       
   123 */
       
   124 void UnitTestCxeSettingsCenrepStore::testloadSettings()
       
   125 {
       
   126     QList<QString> keys;
       
   127     keys.append(CxeRuntimeKeys::PRIMARY_CAMERA_CAPTURE_KEYS);
       
   128     keys.append(CxeRuntimeKeys::PRIMARY_CAMERA_AUTOFOCUS_KEYS);
       
   129     keys.append(CxeRuntimeKeys::SECONDARY_CAMERA_CAPTURE_KEYS);
       
   130     keys.append(CxeRuntimeKeys::CONTRAST_ITEMS);
       
   131     QHash<QString, QVariantList> runtimesettings =  mSettingsCenrepStore->loadRuntimeSettings(keys);
       
   132     
       
   133     foreach(QString runtimekey, keys) {
       
   134         QVariant result;
       
   135         CxeError::Id error = mSettingsCenrepStore->get(runtimekey, result);
       
   136         QVERIFY(error == CxeError::None);
       
   137         QCOMPARE(result.toInt(), 1);
       
   138     }
       
   139     
       
   140 }
       
   141 
       
   142 
       
   143 /*
       
   144  * UnitTestCxeSettingsCenrepStore::testReset()
       
   145  */
       
   146 void UnitTestCxeSettingsCenrepStore::testReset()
       
   147 {
       
   148     // Case 0: Set a value to a known setting
       
   149     QString settingkey = CxeSettingIds::FNAME_MONTH_FOLDER;
       
   150     QVariant value = QVariant(2);
       
   151     QVariant result;
       
   152     CxeError::Id error;
       
   153     
       
   154     error = mSettingsCenrepStore->set(settingkey, value);
       
   155     QVERIFY(error == CxeError::None);
       
   156     
       
   157     // now test if the value is set right
       
   158     error = mSettingsCenrepStore->get(settingkey, result);
       
   159     QVERIFY(error == CxeError::None);
       
   160     QCOMPARE(result.toInt(), 2);
       
   161     
       
   162     // Case 1: reset the cenrep
       
   163     mSettingsCenrepStore->reset();
       
   164     
       
   165     //! TODO: handle the reset case when the real implementation of reset changes.
       
   166     // for now reset doesnt reset the cenrep store as there is no real way of doing it
       
   167     // from xqsettingsmanager.
       
   168 }
       
   169 
       
   170 // main() function
       
   171 QTEST_APPLESS_MAIN(UnitTestCxeSettingsCenrepStore);
       
   172 
       
   173 // end of file