camerauis/cameraxui/cxengine/tsrc/unit/unittest_cxesettingsmodelimp/unittest_cxesettingsmodelimp.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 23 61bc0f252b2b
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
     1 /*
       
     2  * Copyright (c) 2009-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:
       
    15  *
       
    16  */
       
    17 #include <QTest>
       
    18 
       
    19 #include "cxeerror.h"
       
    20 #include "e32err.h"
       
    21 #include "cxenamespace.h"
       
    22 #include "cxesettingsmodelimp.h"
       
    23 #include "cxefakesettingsstore.h"
       
    24 #include "unittest_cxesettingsmodelimp.h"
       
    25 
       
    26 // constants
       
    27 static const char* INVALID_KEY = "invalid key";
       
    28 static const char* EMPTY_KEY = "";
       
    29 
       
    30 UnitTestCxeSettingsModelImp::UnitTestCxeSettingsModelImp()
       
    31 {
       
    32 }
       
    33 
       
    34 UnitTestCxeSettingsModelImp::~UnitTestCxeSettingsModelImp()
       
    35 {
       
    36 }
       
    37 
       
    38 // Run before each individual test case
       
    39 void UnitTestCxeSettingsModelImp::init()
       
    40 {
       
    41     CxeSettingsStore *fakeSettingsStore = new CxeFakeSettingsStore();
       
    42     mSettingsModel = new CxeSettingsModelImp(fakeSettingsStore);
       
    43 }
       
    44 
       
    45 // Run after each individual test case
       
    46 void UnitTestCxeSettingsModelImp::cleanup()
       
    47 {
       
    48     delete mSettingsModel;
       
    49     mSettingsModel = NULL;
       
    50 }
       
    51 
       
    52 // test case to test Setting Values
       
    53 // 1. default values of setting keys
       
    54 // 2. set values to setting keys
       
    55 // 3. checking if set values are set correctly
       
    56 // 4. covers also cases where we test with invalid cases
       
    57 void UnitTestCxeSettingsModelImp::testSettingValues()
       
    58 {
       
    59     CxeError::Id error;
       
    60     QVariant result;
       
    61 
       
    62     // case 0: check default value of a real setting for e.g. FNAME_IMAGE_COUNTER
       
    63     error = mSettingsModel->getSettingValue(CxeSettingIds::FNAME_IMAGE_COUNTER, result);
       
    64     QVERIFY(error == CxeError::None);
       
    65     QCOMPARE(result.toInt(), 0);
       
    66 
       
    67     // case 1: setting a value to a valid key
       
    68     error = mSettingsModel->set(CxeSettingIds::FNAME_IMAGE_COUNTER, 12);
       
    69     QVERIFY(error == CxeError::None);
       
    70 
       
    71     // case 2: testing if the value set is right to sharpness key
       
    72     error = mSettingsModel->getSettingValue(CxeSettingIds::FNAME_IMAGE_COUNTER, result);
       
    73     QVERIFY(error == CxeError::None);
       
    74     QCOMPARE(result.toInt(), 12);
       
    75 
       
    76     // case 3: trying to set a value to an invalid key which doesnt exit
       
    77     error = mSettingsModel->set(INVALID_KEY, QVariant(10));
       
    78     QVERIFY(error == CxeError::NotFound);
       
    79 
       
    80     // case 4: trying to get a value from invalid key
       
    81     error = mSettingsModel->getSettingValue(INVALID_KEY, result);
       
    82     QVERIFY(error == CxeError::NotFound);
       
    83 
       
    84     // case 5: try with an empty string
       
    85     error = mSettingsModel->set(EMPTY_KEY, QVariant(10));
       
    86     QVERIFY(error == CxeError::NotFound);
       
    87 
       
    88     // case 6: try with an empty string
       
    89     error = mSettingsModel->getSettingValue(EMPTY_KEY, result);
       
    90     QVERIFY(error == CxeError::NotFound);
       
    91 }
       
    92 
       
    93 // test case to test RuntimeKeys
       
    94 // 1. default values of runtime keys
       
    95 // 2. try set values to runtime keys
       
    96 // 3. covers also cases where we test with invalid cases
       
    97 void UnitTestCxeSettingsModelImp::testRuntimeValues()
       
    98 {
       
    99     CxeError::Id error;
       
   100     QVariant result;
       
   101     QVariantList values;
       
   102 
       
   103     // case 1: check the default value of runtime
       
   104     error = mSettingsModel->getRuntimeValue(CxeRuntimeKeys::PRIMARY_CAMERA_CAPTURE_KEYS, result);
       
   105     QVERIFY(error == CxeError::None);
       
   106     // checking value
       
   107     if( error == CxeError::None ) {
       
   108         values = qVariantValue<QList<QVariant> >(result);
       
   109         QCOMPARE(values[0].toInt(), 1);
       
   110     }
       
   111 
       
   112     // case 2: trying to get a value from invalid key
       
   113     error = mSettingsModel->getRuntimeValue(INVALID_KEY, result);
       
   114     QVERIFY(error == CxeError::NotFound);
       
   115 
       
   116     // case 3: trying to set a value to a runtime key
       
   117     error = mSettingsModel->set(CxeRuntimeKeys::PRIMARY_CAMERA_CAPTURE_KEYS, 10);
       
   118     QVERIFY(error == CxeError::NotFound);
       
   119 
       
   120     // case 4: try with an empty string
       
   121     error = mSettingsModel->set(EMPTY_KEY, 10);
       
   122     QVERIFY(error == CxeError::NotFound);
       
   123 
       
   124     // case 5: try with an empty string
       
   125     error = mSettingsModel->getRuntimeValue(EMPTY_KEY, result);
       
   126     QVERIFY(error == CxeError::NotFound);
       
   127 
       
   128 }
       
   129 
       
   130 
       
   131 // test case to test Image scene Setting Values
       
   132 // 1. default values of setting keys
       
   133 // 2. set values to setting keys
       
   134 // 3. checking if set values are set correctly
       
   135 // 4. covers also cases where we test with invalid cases
       
   136 void UnitTestCxeSettingsModelImp::testImageSceneSettingValues()
       
   137 {
       
   138     CxeError::Id error;
       
   139     QVariant result;
       
   140     // testing for image mode settings
       
   141     mSettingsModel->cameraModeChanged(Cxe::ImageMode);
       
   142 
       
   143     // case 0: check sharpness default value
       
   144     error = mSettingsModel->getSettingValue(CxeSettingIds::SHARPNESS, result);
       
   145     QVERIFY(error == CxeError::None);
       
   146     QCOMPARE(result.toInt(), 0);
       
   147 
       
   148     // case 1: setting a value to a valid key
       
   149     error = mSettingsModel->set(CxeSettingIds::SHARPNESS, QVariant(100));
       
   150     QVERIFY(error == CxeError::None);
       
   151 
       
   152     // case 2: testing if the value set is right to sharpness key
       
   153     error = mSettingsModel->getSettingValue(CxeSettingIds::SHARPNESS, result);
       
   154     QVERIFY(error == CxeError::None);
       
   155     QCOMPARE(result.toInt(), 100);
       
   156 
       
   157     // case 3: trying to set a value to an invalid key which doesnt exit
       
   158     error = mSettingsModel->set(INVALID_KEY, 10);
       
   159     QVERIFY(error == CxeError::NotFound);
       
   160 
       
   161     // case 4: trying to get a value from invalid key
       
   162     error = mSettingsModel->getSettingValue(INVALID_KEY, result);
       
   163     QVERIFY(error == CxeError::NotFound);
       
   164 
       
   165     // case 5: try with an empty string
       
   166     error = mSettingsModel->set(EMPTY_KEY, 10);
       
   167     QVERIFY(error == CxeError::NotFound);
       
   168 
       
   169     // case 6: try with an empty string
       
   170     error = mSettingsModel->getSettingValue(EMPTY_KEY, result);
       
   171     QVERIFY(error == CxeError::NotFound);
       
   172 }
       
   173 
       
   174 
       
   175 // test case to test Image scene Setting Values
       
   176 // 1. default values of setting keys
       
   177 // 2. set values to setting keys
       
   178 // 3. checking if set values are set correctly
       
   179 // 4. covers also cases where we test with invalid cases
       
   180 void UnitTestCxeSettingsModelImp::testVideoSceneSettingValues()
       
   181 {
       
   182     CxeError::Id error;
       
   183     QVariant result;
       
   184     // testing for image mode settings
       
   185     mSettingsModel->cameraModeChanged(Cxe::VideoMode);
       
   186 
       
   187     // case 0: check colortone default value
       
   188     error = mSettingsModel->getSettingValue(CxeSettingIds::COLOR_TONE, result);
       
   189     QVERIFY(error == CxeError::None);
       
   190     QVERIFY(result.toInt() == Cxe::ColortoneNormal);
       
   191 
       
   192     error = mSettingsModel->set(CxeSettingIds::COLOR_TONE, Cxe::ColortoneNegative);
       
   193     QVERIFY(error == CxeError::None);
       
   194 
       
   195     // case 2: testing if the value set to invalid sharpness key
       
   196     error = mSettingsModel->getSettingValue(CxeSettingIds::COLOR_TONE, result);
       
   197     QVERIFY(error == CxeError::None);
       
   198     QVERIFY(result.toInt() == Cxe::ColortoneNegative);
       
   199 
       
   200     // case 1: setting a value to a invalid key
       
   201     error = mSettingsModel->set(CxeSettingIds::SHARPNESS, 100);
       
   202     QVERIFY(error == CxeError::NotFound);
       
   203 
       
   204     // case 2: testing if the value set to invalid sharpness key
       
   205     error = mSettingsModel->getSettingValue(CxeSettingIds::SHARPNESS, result);
       
   206     QVERIFY(error == CxeError::NotFound);
       
   207 
       
   208 
       
   209     // case 3: trying to set a value to an invalid key which doesnt exit
       
   210     error = mSettingsModel->set(INVALID_KEY, 10);
       
   211     QVERIFY(error == CxeError::NotFound);
       
   212 
       
   213     // case 4: trying to get a value from invalid key
       
   214     error = mSettingsModel->getSettingValue(INVALID_KEY, result);
       
   215     QVERIFY(error == CxeError::NotFound);
       
   216 
       
   217     // case 5: try with an empty string
       
   218     error = mSettingsModel->set(EMPTY_KEY, 10);
       
   219     QVERIFY(error == CxeError::NotFound);
       
   220 
       
   221     // case 6: try with an empty string
       
   222     error = mSettingsModel->getSettingValue(EMPTY_KEY, result);
       
   223     QVERIFY(error == CxeError::NotFound);
       
   224 }
       
   225 
       
   226 
       
   227 
       
   228 // test case to test ImageScene
       
   229 // 1. default values of image scene
       
   230 // 2. try set new image scene and checking if its succesful
       
   231 // 3. covers also cases where we test with invalid cases
       
   232 void UnitTestCxeSettingsModelImp::testImageScene()
       
   233 {
       
   234     CxeScene result;
       
   235     CxeError::Id error;
       
   236 
       
   237     // do initialization
       
   238     mSettingsModel->cameraModeChanged(Cxe::ImageMode);
       
   239 
       
   240     // case 1: check the default image scene sharpness value
       
   241     result = mSettingsModel->currentImageScene();
       
   242     QVERIFY(result[CxeSettingIds::SCENE_ID] == Cxe::IMAGE_SCENE_AUTO);
       
   243     QVERIFY(result[CxeSettingIds::SHARPNESS] == Cxe::SharpnessNormal);
       
   244 
       
   245     // case 2: trying to set a new image scene
       
   246     QString sceneId = Cxe::IMAGE_SCENE_PORTRAIT;
       
   247     error = mSettingsModel->setImageScene(sceneId);
       
   248     QVERIFY(error == CxeError::None);
       
   249 
       
   250     // case 3: testing if NIGHT image scene is set correctly. checking its sharpness value
       
   251     result = mSettingsModel->currentImageScene();
       
   252     QVERIFY(result[CxeSettingIds::SCENE_ID] == sceneId);
       
   253     QVERIFY(result[CxeSettingIds::SHARPNESS] == Cxe::SharpnessSoft);
       
   254 
       
   255     // case 3: trying to set a image scene with invalid value
       
   256     error = mSettingsModel->setImageScene(INVALID_KEY);
       
   257     QVERIFY(error == CxeError::NotFound);
       
   258 
       
   259     // case 4: try with an empty string
       
   260     error = mSettingsModel->setImageScene(EMPTY_KEY);
       
   261     QVERIFY(error == CxeError::NotFound);
       
   262 
       
   263 }
       
   264 
       
   265 
       
   266 // test case to test VideoScene
       
   267 // 1. default values of video scene
       
   268 // 2. try set new video scene and checking if its succesful
       
   269 // 3. covers also cases where we test with invalid cases
       
   270 void UnitTestCxeSettingsModelImp::testVideoScene()
       
   271 {
       
   272     CxeScene result;
       
   273     CxeError::Id error;
       
   274 
       
   275     // do initialization
       
   276     mSettingsModel->cameraModeChanged(Cxe::VideoMode);
       
   277 
       
   278     // case 1: check the default image scene
       
   279     result = mSettingsModel->currentVideoScene();
       
   280     QVERIFY(result[CxeSettingIds::SCENE_ID] == Cxe::VIDEO_SCENE_AUTO);
       
   281     QVERIFY(result[CxeSettingIds::FRAME_RATE] == 0);
       
   282 
       
   283     // case 2: trying to set a new image scene
       
   284     QString sceneId = Cxe::VIDEO_SCENE_LOWLIGHT;
       
   285     error = mSettingsModel->setVideoScene(sceneId);
       
   286     QVERIFY(error == CxeError::None);
       
   287 
       
   288     // case 3: testing if NIGHT image scene is set correctly
       
   289     result = mSettingsModel->currentVideoScene();
       
   290     QVERIFY(result[CxeSettingIds::SCENE_ID] == sceneId);
       
   291     QVERIFY(result[CxeSettingIds::FRAME_RATE] == 15);
       
   292 
       
   293     // case 3: trying to set a image scene with invalid value
       
   294     error = mSettingsModel->setVideoScene(INVALID_KEY);
       
   295     QVERIFY(error == CxeError::NotFound);
       
   296 
       
   297     // case 4: try with an empty string
       
   298     error = mSettingsModel->setVideoScene(EMPTY_KEY);
       
   299     QVERIFY(error == CxeError::NotFound);
       
   300 
       
   301 }
       
   302 
       
   303 
       
   304 // main() function non-GUI testing
       
   305 QTEST_APPLESS_MAIN(UnitTestCxeSettingsModelImp);