--- a/camerauis/cameraxui/cxengine/tsrc/unit/unittest_cxesettingsimp/unittest_cxesettingsimp.cpp Fri Jul 23 11:35:41 2010 +0300
+++ b/camerauis/cameraxui/cxengine/tsrc/unit/unittest_cxesettingsimp/unittest_cxesettingsimp.cpp Wed Aug 18 14:02:45 2010 +0300
@@ -17,16 +17,24 @@
#include <QTest>
#include <QDebug>
#include <QSignalSpy>
+#include <QMetaType>
+#include "cxutils.h"
#include "cxetestutils.h"
-#include "cxefakesettingsmodel.h"
+#include "cxefakesettingsstore.h"
#include "unittest_cxesettingsimp.h"
+#include "cxecenrepkeys.h"
const char* FAIL_TEST_SETTING = "Fail test";
+const char* EMPTY_STRING = "";
+const int CAMERA_MODE_STILL = 0;
+const int CAMERA_MODE_VIDEO = 1;
+//Default EV compensation value for auto still and auto video scene mode
+const int SCENE_AUTO_EV_VALUE = 0;
+const int SIGNAL_TIMEOUT = 3000; //milliseconds
UnitTestCxeSettingsImp::UnitTestCxeSettingsImp() :
- mSettingsModel(NULL),
- mSettingsImp(NULL)
+ mSettingsImp(NULL), mSettingsStore(NULL)
{
qRegisterMetaType<CxeScene>("CxeScene");
qRegisterMetaType<CxeError::Id>("CxeError::Id");
@@ -35,416 +43,444 @@
UnitTestCxeSettingsImp::~UnitTestCxeSettingsImp()
{
- cleanup();
}
void UnitTestCxeSettingsImp::init()
{
- mSettingsModel = new CxeFakeSettingsModel;
- mSettingsImp = new CxeSettingsImp(*mSettingsModel);
+ mSettingsStore = new CxeFakeSettingsStore();
+ mSettingsImp = new CxeSettingsImp(mSettingsStore);
}
void UnitTestCxeSettingsImp::cleanup()
{
- delete mSettingsModel;
- mSettingsModel = NULL;
-
delete mSettingsImp;
mSettingsImp = NULL;
}
-void UnitTestCxeSettingsImp::testLoadSettings()
+/*
+ * Testing loadSettings() with Cxe::ImageMode argument
+ */
+void UnitTestCxeSettingsImp::testLoadImageSettings()
{
- Cxe::CameraMode mode;
+ CX_DEBUG_ENTER_FUNCTION();
+ QSignalSpy spy(mSettingsImp, SIGNAL(settingValueChanged(QString,QVariant)));
+ mSettingsImp->loadSettings(Cxe::ImageMode);
- /* Observe sceneChanged signal from mSettingsImp
- */
- CxeScene sigSce;
- QSignalSpy spyStateChange(mSettingsImp, SIGNAL(sceneChanged(CxeScene &)));
- QVERIFY( spyStateChange.isValid() );
+ //signal should be emitted when loading settings
+ QVERIFY(spy.count() > 0);
+
+ //now let's take a look inside a signal content
+ QList<QVariant> arguments = spy.takeFirst();
+ QVERIFY(arguments.at(0).toString().toAscii() == CxeSettingIds::IMAGE_SCENE);
+ CX_DEBUG_EXIT_FUNCTION();
+}
- /* Test load settings in camera/video mode. Helpper method is used to get the
- * new camera mode to test loadSettings method has set right camera mode
- */
- mSettingsImp->loadSettings(Cxe::ImageMode);
- mode = mSettingsModel->getDummyCameraMode();
- QCOMPARE(mode, Cxe::ImageMode);
- QVERIFY(CxeTestUtils::waitForSignal(spyStateChange, 1000)); // verify statechanges
+/*
+ * Testing loadSettings() with Cxe::VideoMode argument
+ */
+void UnitTestCxeSettingsImp::testLoadVideoSettings()
+{
+ CX_DEBUG_ENTER_FUNCTION();
+ QSignalSpy spy(mSettingsImp, SIGNAL(settingValueChanged(QString,QVariant)));
+ mSettingsImp->loadSettings(Cxe::VideoMode);
- mSettingsImp->loadSettings(Cxe::VideoMode);
- mode = mSettingsModel->getDummyCameraMode();
- QCOMPARE(mode, Cxe::VideoMode);
- QVERIFY(CxeTestUtils::waitForSignal(spyStateChange, 1000)); // verify statechanges
+ //signal should be emitted when loading settings
+ QVERIFY(spy.count() > 0);
+
+ //now let's take a look inside a signal content
+ QList<QVariant> arguments = spy.takeFirst();
+ QVERIFY(arguments.at(0).toString().toAscii() == CxeSettingIds::VIDEO_SCENE);
+
+ CX_DEBUG_EXIT_FUNCTION();
}
+/*
+ * Advanced test case for loadSettings()
+ */
+void UnitTestCxeSettingsImp::testLoadImageAndVideoSettings()
+{
+ CX_DEBUG_ENTER_FUNCTION();
+ QSignalSpy spy(mSettingsImp, SIGNAL(settingValueChanged(QString,QVariant)));
+ mSettingsImp->loadSettings(Cxe::VideoMode);
+ //signal should be emitted when loading settings
+ QVERIFY(spy.count() > 0);
+
+ //now let's take a look inside a signal content
+ QList<QVariant> arguments = spy.takeFirst();
+ QVERIFY(arguments.at(0).toString().toAscii() == CxeSettingIds::VIDEO_SCENE);
+ spy.clear();
+
+ mSettingsImp->loadSettings(Cxe::ImageMode);
+
+ //signal should be emitted when loading settings
+ QVERIFY(spy.count() > 0);
+
+ //now let's take a look inside a signal content
+ arguments = spy.takeFirst();
+ QVERIFY(arguments.at(0).toString().toAscii() == CxeSettingIds::IMAGE_SCENE);
+
+ CX_DEBUG_EXIT_FUNCTION();
+}
+
+/*
+ * Testing inline get(const QString &key)
+ * defined in cxesettings.h as template
+ */
void UnitTestCxeSettingsImp::testGet()
{
+ CX_DEBUG_ENTER_FUNCTION();
CxeError::Id err = CxeError::None;
- QString stringValue;
- QString expectedValue = "1";
+ // The idea of this test case is to test as much of different type of settings
+ // as possible
+
+ // Testing reading brightness setting value
+ int brightnessValue;
QVariant testValue;
- /* Test that get -method accepts key and returns correct value. Fakeclass method
- * is used to check that returned value matches with fakeclass' test values
- */
- err = mSettingsImp->get(CxeSettingIds::BRIGHTNESS, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::BRIGHTNESS, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
-
- /* Test that returned value can be viewed as string and int, since get -method
- * may be used for both strings and integers
- */
- int num = 1;
- QCOMPARE(stringValue, expectedValue);
- QVERIFY(stringValue.toInt() == num);
+ try {
+ brightnessValue = mSettingsImp->CxeSettings::get<int>(CxeSettingIds::BRIGHTNESS);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append(exception.error());
+ QFAIL(message.toAscii());
+ return;
+ }
- err = mSettingsImp->get(CxeSettingIds::COLOR_TONE, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::COLOR_TONE, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
-
- err = mSettingsImp->get(CxeSettingIds::CONTRAST, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::CONTRAST, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
-
- err = mSettingsImp->get(CxeSettingIds::EV_COMPENSATION_VALUE, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::EV_COMPENSATION_VALUE, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
+ mSettingsStore->get(CxeSettingIds::BRIGHTNESS, testValue);
+ QCOMPARE(brightnessValue, testValue.toInt());
- err = mSettingsImp->get(CxeSettingIds::EXPOSURE_MODE, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::EXPOSURE_MODE, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
-
- err = mSettingsImp->get(CxeSettingIds::FLASH_MODE, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FLASH_MODE, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
-
- err = mSettingsImp->get(CxeSettingIds::FNAME_FOLDER_SUFFIX, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FNAME_FOLDER_SUFFIX, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
+ // Testing reading color tone setting value
+ Cxe::Colortone colorTone;
+ try {
+ colorTone = mSettingsImp->CxeSettings::get<Cxe::Colortone>(CxeSettingIds::COLOR_TONE);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append(exception.error());
+ QFAIL(message.toAscii());
+ return;
+ }
- err = mSettingsImp->get(CxeSettingIds::FNAME_IMAGE_COUNTER, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FNAME_IMAGE_COUNTER, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
+ QVariant colorTone2;
+ mSettingsStore->get(CxeSettingIds::COLOR_TONE, colorTone2);
+ QVERIFY(colorTone2 == colorTone);
- err = mSettingsImp->get(CxeSettingIds::FNAME_MONTH_FOLDER, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FNAME_MONTH_FOLDER, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
+ // Testing reading contrast setting value
+ int contrastValue;
+ try {
+ contrastValue = mSettingsImp->CxeSettings::get<int>(CxeSettingIds::CONTRAST);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append(exception.error());
+ QFAIL(message.toAscii());
+ return;
+ }
- err = mSettingsImp->get(CxeSettingIds::FNAME_VIDEO_COUNTER, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FNAME_VIDEO_COUNTER, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
+ mSettingsStore->get(CxeSettingIds::CONTRAST, testValue);
+ QCOMPARE(testValue.toInt(), contrastValue);
- err = mSettingsImp->get(CxeSettingIds::FOCAL_RANGE, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FOCAL_RANGE, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
-
- err = mSettingsImp->get(CxeSettingIds::FRAME_RATE, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FRAME_RATE, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
-
- err = mSettingsImp->get(CxeSettingIds::IMAGE_QUALITY, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::IMAGE_QUALITY, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
+ // Testing reading file name folder suffix setting value
+ QString fnameValue;
+ try {
+ fnameValue = mSettingsImp->CxeSettings::get<QString>(CxeSettingIds::FNAME_FOLDER_SUFFIX);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append(exception.error());
+ QFAIL(message.toAscii());
+ return;
+ }
- err = mSettingsImp->get(CxeSettingIds::IMAGE_SCENE, stringValue);
- QCOMPARE(err, CxeError::None);
- CxeScene scene = mSettingsModel->currentImageScene();
- QCOMPARE(stringValue, scene[CxeSettingIds::SCENE_ID].toString());
+ mSettingsStore->get(CxeSettingIds::FNAME_FOLDER_SUFFIX, testValue);
+ QCOMPARE(testValue.toString(), fnameValue);
- err = mSettingsImp->get(CxeSettingIds::LIGHT_SENSITIVITY, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::LIGHT_SENSITIVITY, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
+ // Testing reading scene data
+ QVariantMap sceneData;
- err = mSettingsImp->get(CxeSettingIds::SCENE_ID, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::SCENE_ID, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
+ // First set the still camera scene to auto
+ mSettingsStore->set(CxeSettingIds::IMAGE_SCENE, Cxe::IMAGE_SCENE_AUTO);
- err = mSettingsImp->get(CxeSettingIds::SECONDARY_CAMERA, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::SECONDARY_CAMERA, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
+ try {
+ sceneData = mSettingsImp->CxeSettings::get<QVariantMap>(CxeSettingIds::IMAGE_SCENE_DATA);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append(exception.error());
+ QFAIL(message.toAscii());
+ return;
+ }
- err = mSettingsImp->get(CxeSettingIds::SELF_TIMER, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::SELF_TIMER, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
-
- err = mSettingsImp->get(CxeSettingIds::SHARPNESS, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::SHARPNESS, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
+ QCOMPARE(sceneData[CxeSettingIds::EV_COMPENSATION_VALUE].toInt(), SCENE_AUTO_EV_VALUE);
- err = mSettingsImp->get(CxeSettingIds::VIDEO_SCENE, stringValue);
- QCOMPARE(err, CxeError::None);
- scene = mSettingsModel->currentVideoScene();
- QCOMPARE(stringValue, scene[CxeSettingIds::SCENE_ID].toString());
+ // Now let's try same with video scene
+ sceneData.clear();
+ mSettingsStore->set(CxeSettingIds::VIDEO_SCENE, Cxe::VIDEO_SCENE_AUTO);
+ try {
+ sceneData = mSettingsImp->CxeSettings::get<QVariantMap>(CxeSettingIds::VIDEO_SCENE_DATA);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append(exception.error());
+ QFAIL(message.toAscii());
+ return;
+ }
- err = mSettingsImp->get(CxeSettingIds::WHITE_BALANCE, stringValue);
- QCOMPARE(err, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::WHITE_BALANCE, testValue);
- QCOMPARE(stringValue, QString(testValue.toString()));
+ QCOMPARE(sceneData[CxeSettingIds::EV_COMPENSATION_VALUE].toInt(), SCENE_AUTO_EV_VALUE);
- /* Test error values
- */
- err = mSettingsImp->get(FAIL_TEST_SETTING , stringValue);
- QCOMPARE(err, CxeError::NotFound);
+ CX_DEBUG_EXIT_FUNCTION();
}
+/*
+ * Testing get(long int uid,
+ * unsigned long int key,
+ * Cxe::SettingKeyType type,
+ * QVariant &value)
+ */
void UnitTestCxeSettingsImp::testGet2()
{
+ CX_DEBUG_ENTER_FUNCTION();
QVariant value;
- QVariant reference;
- mSettingsImp->get(0, 0, Cxe::Repository, value);
- mSettingsModel->getSettingValue(0, 0, Cxe::Repository, reference);
- QCOMPARE(value, reference);
+ mSettingsImp->get(CxSettingsCrUid, FileNameSuffixCr, Cxe::Repository, value);
+ // 42 is just a test value from cxefakesettingsstore
+ // we just check that it is correctly returned
+ QCOMPARE(value.toInt(), 42);
mSettingsImp->get(0, 0, Cxe::PublishAndSubscribe, value);
- mSettingsModel->getSettingValue(0, 0, Cxe::PublishAndSubscribe, reference);
- QCOMPARE(value, reference);
+ // 42 is just a test value from cxefakesettingsstore
+ // we just check that it is correctly returned
+ QCOMPARE(value.toInt(), 42);
+ CX_DEBUG_EXIT_FUNCTION();
+}
+/*
+ * Testing get(const QString &key, const T &defaultValue)
+ * defined in cxesettings.h as template
+ */
+void UnitTestCxeSettingsImp::testGet3()
+{
+ CX_DEBUG_ENTER_FUNCTION();
+ Cxe::Colortone defaultTone = Cxe::ColortoneNormal;
+ mSettingsStore->set(CxeSettingIds::COLOR_TONE, Cxe::ColortoneVivid);
+ Cxe::Colortone colorTone = mSettingsImp->CxeSettings::get<Cxe::Colortone>(
+ CxeSettingIds::COLOR_TONE, defaultTone);
+ QVERIFY(colorTone == Cxe::ColortoneVivid);
+
+ // Now when using this version of the overloaded get<int>()
+ // with invalid key parameter, it should internally
+ // catch the exception and not modify the default value
+ int defaultValue = 0;
+ int value = mSettingsImp->CxeSettings::get<int>(
+ FAIL_TEST_SETTING, defaultValue);
+ QVERIFY(value == defaultValue);
+ CX_DEBUG_EXIT_FUNCTION();
}
+/*
+ * Testing inputting some garbage into CxeSettingsImp::get()
+ */
+void UnitTestCxeSettingsImp::testGetGarbage()
+{
+ CX_DEBUG_ENTER_FUNCTION();
+ int intTestValue = 0;
+ CxeError::Id errorId;
+
+ try {
+ mSettingsImp->CxeSettings::get<int>(EMPTY_STRING, intTestValue);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append(exception.error());
+ errorId = CxeError::Id(exception.error());
+ QCOMPARE(errorId, CxeError::NotFound);
+ }
+
+ try {
+ mSettingsImp->CxeSettings::get<int>(FAIL_TEST_SETTING, intTestValue);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append(exception.error());
+ errorId = CxeError::Id(exception.error());
+ QCOMPARE(errorId, CxeError::NotFound);
+ }
+
+ CX_DEBUG_EXIT_FUNCTION();
+}
+
+/*
+ * Testing inline void set(const QString &key, const T &value)
+ * defined in cxesettings.h
+ */
void UnitTestCxeSettingsImp::testSet()
{
- CxeError::Id error;
- int range = 0;
- QString string = "";
- QVariant variant(1);
- QVariant checkValue;
+ CX_DEBUG_ENTER_FUNCTION();
+
+ // Point of this test case is to try all versions of the set()
+ // method defined in cxesettings.inl
- /* Test that signal is corresponding correctly when setting value is changed
- */
- QList<QVariant> spyArguments;
- QSignalSpy signalSpy(mSettingsImp, SIGNAL(settingValueChanged(QString, QVariant)));
- QVERIFY( signalSpy.isValid() );
-
- error = mSettingsImp->set(CxeSettingIds::BRIGHTNESS, range);
- QCOMPARE(error, CxeError::None);
- QVERIFY(CxeTestUtils::waitForSignal(signalSpy, 1000)); // verify statechanges
-
- spyArguments = signalSpy.takeFirst();
- QCOMPARE(spyArguments.at(0).toString(), QString(CxeSettingIds::BRIGHTNESS));
- QCOMPARE(spyArguments.at(1).toInt(), range);
+ // Testing set<int>() version
+ QVariant value;
+ try {
+ mSettingsImp->set(CxeSettingIds::COLOR_TONE, Cxe::ColortoneBlackAndWhite);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append(exception.error());
+ QFAIL(message.toAscii());
+ return;
+ }
+ mSettingsStore->get(CxeSettingIds::COLOR_TONE, value);
+ QCOMPARE(value.toInt(), (int)Cxe::ColortoneBlackAndWhite);
- /* Test parameters
- */
- error = mSettingsImp->set(CxeSettingIds::BRIGHTNESS, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::BRIGHTNESS, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
-
- error = mSettingsImp->set(CxeSettingIds::COLOR_TONE, Cxe::ColortoneNormal);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::COLOR_TONE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::ColortoneNormal));
+ // Testing set<QString>() version
+ QString stringValue = "some text";
+ try {
+ mSettingsImp->set(CxeSettingIds::FNAME_FOLDER_SUFFIX, stringValue);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append(exception.error());
+ QFAIL(message.toAscii());
+ return;
+ }
+ mSettingsStore->get(CxeSettingIds::FNAME_FOLDER_SUFFIX, value);
+ QCOMPARE(value.toString(), stringValue);
- error = mSettingsImp->set(CxeSettingIds::COLOR_TONE, Cxe::ColortoneSepia);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::COLOR_TONE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::ColortoneSepia));
-
- error = mSettingsImp->set(CxeSettingIds::COLOR_TONE, Cxe::ColortoneNegative);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::COLOR_TONE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::ColortoneNegative));
-
- error = mSettingsImp->set(CxeSettingIds::COLOR_TONE, Cxe::ColortoneBlackAndWhite);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::COLOR_TONE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::ColortoneBlackAndWhite));
-
- error = mSettingsImp->set(CxeSettingIds::COLOR_TONE, Cxe::ColortoneVivid);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::COLOR_TONE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::ColortoneVivid));
+ // Testing set<bool>() version
+ bool boolValue = true;
+ try {
+ mSettingsImp->set(CxeSettingIds::STILL_SHOWCAPTURED, boolValue);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append(exception.error());
+ QFAIL(message.toAscii());
+ return;
+ }
+ mSettingsStore->get(CxeSettingIds::STILL_SHOWCAPTURED, value);
+ QCOMPARE(value.toBool(), boolValue);
- error = mSettingsImp->set(CxeSettingIds::CONTRAST, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::CONTRAST, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
-
- error = mSettingsImp->set(CxeSettingIds::EV_COMPENSATION_VALUE, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::EV_COMPENSATION_VALUE, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
+ // Testing set<qreal>() version
+ qreal qrealValue = -1.25;
+ try {
+ mSettingsImp->set(CxeSettingIds::EV_COMPENSATION_VALUE, qrealValue);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append(exception.error());
+ QFAIL(message.toAscii());
+ return;
+ }
+ mSettingsStore->get(CxeSettingIds::EV_COMPENSATION_VALUE, value);
+ QCOMPARE(value.toReal(), qrealValue);
- error = mSettingsImp->set(CxeSettingIds::EXPOSURE_MODE, Cxe::ExposureAuto);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::EXPOSURE_MODE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::ExposureAuto));
+ // Testing set<QVariantMap>() version
+ CxeScene testSceneData;
- error = mSettingsImp->set(CxeSettingIds::EXPOSURE_MODE, Cxe::ExposureBacklight);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::EXPOSURE_MODE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::ExposureBacklight));
-
- error = mSettingsImp->set(CxeSettingIds::EXPOSURE_MODE, Cxe::ExposureNight);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::EXPOSURE_MODE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::ExposureNight));
+ testSceneData.insert(CxeSettingIds::SCENE_ID, Cxe::IMAGE_SCENE_AUTO);
+ testSceneData.insert(CxeSettingIds::WHITE_BALANCE, Cxe::WhitebalanceAutomatic);
+ testSceneData.insert(CxeSettingIds::EXPOSURE_MODE, Cxe::ExposureAuto);
+ testSceneData.insert(CxeSettingIds::COLOR_TONE, Cxe::ColortoneNormal);
+ testSceneData.insert(CxeSettingIds::CONTRAST, 5);
+ testSceneData.insert(CxeSettingIds::SHARPNESS, Cxe::SharpnessNormal);
+ testSceneData.insert(CxeSettingIds::LIGHT_SENSITIVITY, Cxe::LightSensitivityAutomatic);
+ testSceneData.insert(CxeSettingIds::EV_COMPENSATION_VALUE, -2);
+ testSceneData.insert(CxeSettingIds::BRIGHTNESS, 8);
+ testSceneData.insert(CxeSettingIds::FLASH_MODE, Cxe::FlashAuto);
+ testSceneData.insert(CxeSettingIds::FACE_TRACKING, 1);
- error = mSettingsImp->set(CxeSettingIds::EXPOSURE_MODE, Cxe::ExposureSport);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::EXPOSURE_MODE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::ExposureSport));
+ // First set the still camera scene to auto
+ mSettingsStore->set(CxeSettingIds::IMAGE_SCENE, Cxe::IMAGE_SCENE_AUTO);
- error = mSettingsImp->set(CxeSettingIds::FLASH_MODE, Cxe::FlashAntiRedEye);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FLASH_MODE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::FlashAntiRedEye));
-
- error = mSettingsImp->set(CxeSettingIds::FLASH_MODE, Cxe::FlashAuto);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FLASH_MODE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::FlashAuto));
+ // Now setting the value
+ try {
+ //This should throw an exception with CxeError::NotSupported
+ mSettingsImp->set(CxeSettingIds::IMAGE_SCENE_DATA, testSceneData);
+ }
+ catch (CxeException exception) {
+ QString message = "Exception thrown, error id = ";
+ message.append((int)exception.error());
+ QCOMPARE(exception.error(), (int)CxeError::NotSupported);
+ }
- error = mSettingsImp->set(CxeSettingIds::FLASH_MODE, Cxe::FlashOff);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FLASH_MODE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::FlashOff));
+ CX_DEBUG_EXIT_FUNCTION();
+}
- error = mSettingsImp->set(CxeSettingIds::FLASH_MODE, Cxe::FlashOn);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FLASH_MODE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::FlashOn));
+/*
+ * This will test calling void method of reset()
+ */
+void UnitTestCxeSettingsImp::testReset()
+{
+ CX_DEBUG_ENTER_FUNCTION();
+ mSettingsImp->reset();
+ CX_DEBUG_EXIT_FUNCTION();
+}
- error = mSettingsImp->set(CxeSettingIds::FNAME_FOLDER_SUFFIX, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FNAME_FOLDER_SUFFIX, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
-
- error = mSettingsImp->set(CxeSettingIds::FNAME_IMAGE_COUNTER, range);
+void UnitTestCxeSettingsImp::testGetVariationSetting()
+{
+ CX_DEBUG_ENTER_FUNCTION();
+ QVariant value;
+ CxeError::Id error = mSettingsImp->getVariationValue(CxeVariationKeys::STILL_MAX_ZOOM_LIMITS, value);
QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FNAME_IMAGE_COUNTER, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
- error = mSettingsImp->set(CxeSettingIds::FNAME_MONTH_FOLDER, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FNAME_MONTH_FOLDER, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
+ error = mSettingsImp->getVariationValue(FAIL_TEST_SETTING, value);
+ QCOMPARE(error, CxeError::NotFound);
+ CX_DEBUG_EXIT_FUNCTION();
+}
- error = mSettingsImp->set(CxeSettingIds::FNAME_VIDEO_COUNTER, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FNAME_VIDEO_COUNTER, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
+void UnitTestCxeSettingsImp::testListenForSetting()
+{
+ CX_DEBUG_ENTER_FUNCTION();
- error = mSettingsImp->set(CxeSettingIds::FOCAL_RANGE, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::FOCAL_RANGE, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
-
- error = mSettingsImp->set(CxeSettingIds::IMAGE_QUALITY, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::IMAGE_QUALITY, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
+ // This test case will initialize listening for certain setting changes
+ // and will verify that listener has succesfully deployed the signal
- error = mSettingsImp->set(CxeSettingIds::IMAGE_SCENE, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::IMAGE_SCENE, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
+ // First let's initialize a signal spy
+ QSignalSpy spy(mSettingsImp, SIGNAL(settingValueChanged(QString, QVariant)));
- error = mSettingsImp->set(CxeSettingIds::LIGHT_SENSITIVITY, Cxe::LightSensitivityAutomatic);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::LIGHT_SENSITIVITY, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::LightSensitivityAutomatic));
-
- error = mSettingsImp->set(CxeSettingIds::LIGHT_SENSITIVITY, Cxe::LightSensitivityHigh);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::LIGHT_SENSITIVITY, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::LightSensitivityHigh));
+ // Initializing the original value to make sure it changes later on
+ mSettingsStore->set(CxeSettingIds::CAMERA_MODE, Cxe::ImageMode);
- error = mSettingsImp->set(CxeSettingIds::LIGHT_SENSITIVITY, Cxe::LightSensitivityLow);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::LIGHT_SENSITIVITY, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::LightSensitivityLow));
+ // Now start listening and verify that starting was succesfull
+ bool result = mSettingsImp->listenForSetting(CxeSettingIds::CAMERA_MODE, this, SLOT(testSlot()));
+ QVERIFY(result);
- error = mSettingsImp->set(CxeSettingIds::LIGHT_SENSITIVITY, Cxe::LightSensitivityMedium);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::LIGHT_SENSITIVITY, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::LightSensitivityMedium));
-
- error = mSettingsImp->set(CxeSettingIds::SCENE_ID, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::SCENE_ID, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
+ // Now change the setting and wait for the signal
+ //mSettingsStore->set(CxeSettingIds::CAMERA_MODE, Cxe::VideoMode);
+ mSettingsImp->set(CxeSettingIds::CAMERA_MODE, Cxe::VideoMode);
- error = mSettingsImp->set(CxeSettingIds::SECONDARY_CAMERA, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::SECONDARY_CAMERA, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
- error = mSettingsImp->set(CxeSettingIds::SELF_TIMER, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::SELF_TIMER, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
-
- error = mSettingsImp->set(CxeSettingIds::SHARPNESS, Cxe::SharpnessHard);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::SHARPNESS, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::SharpnessHard));
+ // Check that signal was emitted
+ QVERIFY(CxeTestUtils::waitForSignal(spy, SIGNAL_TIMEOUT));
- error = mSettingsImp->set(CxeSettingIds::SHARPNESS, Cxe::SharpnessNormal);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::SHARPNESS, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::SharpnessNormal));
+ // One more check with invalid input parameter
+ result = mSettingsImp->listenForSetting(FAIL_TEST_SETTING, this, SLOT(testSlot()));
+ QVERIFY(!result);
- error = mSettingsImp->set(CxeSettingIds::SHARPNESS, Cxe::SharpnessSoft);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::SHARPNESS, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::SharpnessSoft));
-
- error = mSettingsImp->set(CxeSettingIds::VIDEO_SCENE, range);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::VIDEO_SCENE, checkValue);
- QCOMPARE(int(checkValue.toInt()), range);
+ // Now disconnecting the listener and checking if the signal is still emitted
+ disconnect(mSettingsImp, SIGNAL(settingValueChanged(QString,QVariant)), this, SLOT(testSlot()));
+ delete mSettingsImp;
+ mSettingsImp = NULL;
- error = mSettingsImp->set(CxeSettingIds::WHITE_BALANCE, Cxe::WhitebalanceAutomatic);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::WHITE_BALANCE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::WhitebalanceAutomatic));
+ mSettingsStore->set(CxeSettingIds::CAMERA_MODE, Cxe::ImageMode);
- error = mSettingsImp->set(CxeSettingIds::WHITE_BALANCE, Cxe::WhitebalanceCloudy);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::WHITE_BALANCE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::WhitebalanceCloudy));
-
- error = mSettingsImp->set(CxeSettingIds::WHITE_BALANCE, Cxe::WhitebalanceFluorescent);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::WHITE_BALANCE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::WhitebalanceFluorescent));
+ // Make sure that no additional signals are emitted
+ QVERIFY(!CxeTestUtils::waitForSignal(spy, SIGNAL_TIMEOUT));
- error = mSettingsImp->set(CxeSettingIds::WHITE_BALANCE, Cxe::WhitebalanceIncandescent);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::WHITE_BALANCE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::WhitebalanceIncandescent));
+ CX_DEBUG_EXIT_FUNCTION();
+}
- error = mSettingsImp->set(CxeSettingIds::WHITE_BALANCE, Cxe::WhitebalanceSunny);
- QCOMPARE(error, CxeError::None);
- mSettingsModel->getSettingValue(CxeSettingIds::WHITE_BALANCE, checkValue);
- QCOMPARE(int(checkValue.toInt()), ((int)Cxe::WhitebalanceSunny));
-
- /* Test fail parameter
- */
- error = mSettingsImp->set(FAIL_TEST_SETTING, Cxe::ColortoneNormal);
- QCOMPARE(error, CxeError::NotFound);
+/*
+ * Just a dummy slot
+ */
+void UnitTestCxeSettingsImp::testSlot()
+{
+ CX_DEBUG_IN_FUNCTION();
}
// main() function non-GUI testing