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 <QDate> |
|
18 #include <QTest> |
|
19 #include <QDebug> |
|
20 |
|
21 #include "unittest_cxefilenamegeneratorsymbian.h" |
|
22 #include "cxefilenamegeneratorsymbian.h" |
|
23 #include "cxesettings.h" |
|
24 #include "cxefakesettings.h" |
|
25 |
|
26 namespace |
|
27 { |
|
28 static const char* FILENAME_SUFFIX = "CxTest"; |
|
29 } |
|
30 |
|
31 UnitTestCxeFilenameGeneratorSymbian::UnitTestCxeFilenameGeneratorSymbian() |
|
32 : mFileNameGenerator(NULL), mFakeSettings(NULL), mMode(Cxe::ImageMode) |
|
33 { |
|
34 } |
|
35 |
|
36 UnitTestCxeFilenameGeneratorSymbian::~UnitTestCxeFilenameGeneratorSymbian() |
|
37 { |
|
38 delete mFileNameGenerator; |
|
39 delete mFakeSettings; |
|
40 } |
|
41 |
|
42 // Run before each individual test case |
|
43 void UnitTestCxeFilenameGeneratorSymbian::init() |
|
44 { |
|
45 mFakeSettings = new CxeFakeSettings(); |
|
46 |
|
47 mFakeSettings->set(CxeSettingIds::FNAME_MONTH_FOLDER, QDate::currentDate().toString("yyyyMM")); |
|
48 mFakeSettings->set(CxeSettingIds::FNAME_IMAGE_COUNTER, 0); |
|
49 mFakeSettings->set(CxeSettingIds::FNAME_VIDEO_COUNTER, 0); |
|
50 mFakeSettings->set(CxeSettingIds::FNAME_FOLDER_SUFFIX, FILENAME_SUFFIX); |
|
51 |
|
52 mFileNameGenerator = new CxeFilenameGeneratorSymbian(*mFakeSettings, mMode); |
|
53 mFileNameGenerator->init(mMode); |
|
54 } |
|
55 |
|
56 // Run after each individual test case |
|
57 void UnitTestCxeFilenameGeneratorSymbian::cleanup() |
|
58 { |
|
59 delete mFileNameGenerator; |
|
60 mFileNameGenerator = NULL; |
|
61 delete mFakeSettings; |
|
62 mFakeSettings = NULL; |
|
63 } |
|
64 |
|
65 void UnitTestCxeFilenameGeneratorSymbian::testStartNewImageFilenameSequence() |
|
66 { |
|
67 mFileNameGenerator->startNewImageFilenameSequence(); |
|
68 } |
|
69 |
|
70 void UnitTestCxeFilenameGeneratorSymbian::testNextImageFilenameInSequence() |
|
71 { |
|
72 mFileNameGenerator->startNewImageFilenameSequence(); |
|
73 QString filename; |
|
74 QString ext(".jpg"); |
|
75 CxeError::Id error = mFileNameGenerator->nextImageFilenameInSequence(filename, ext); |
|
76 filename = removeDrive(filename); |
|
77 QString reference(generateSequenceImageFileName(0, 0)); |
|
78 |
|
79 qDebug() << "UnitTestCxeFilenameGeneratorSymbian - Check generated sequence filename (root path removed).."; |
|
80 qDebug() << "UnitTestCxeFilenameGeneratorSymbian - Generated: [" << filename << "]"; |
|
81 qDebug() << "UnitTestCxeFilenameGeneratorSymbian - Reference: [" << reference << "]"; |
|
82 QVERIFY(QString::compare(removeDrive(filename), reference, Qt::CaseInsensitive) == 0); |
|
83 } |
|
84 |
|
85 void UnitTestCxeFilenameGeneratorSymbian::testGenerateFilename() |
|
86 { |
|
87 QString filename; |
|
88 QString ext(".jpg"); |
|
89 CxeError::Id error = mFileNameGenerator->generateFilename(filename, ext); |
|
90 filename = removeDrive(filename); |
|
91 QString reference(generateImageFileName(0)); |
|
92 qDebug() << "UnitTestCxeFilenameGeneratorSymbian - Check generated filename (root path removed).."; |
|
93 qDebug() << "UnitTestCxeFilenameGeneratorSymbian - Generated: [" << filename << "]"; |
|
94 qDebug() << "UnitTestCxeFilenameGeneratorSymbian - Reference: [" << reference << "]"; |
|
95 QVERIFY(QString::compare(filename, generateImageFileName(0), Qt::CaseInsensitive) == 0); |
|
96 } |
|
97 |
|
98 QString UnitTestCxeFilenameGeneratorSymbian::generateImageFileName(int counter) |
|
99 { |
|
100 // get the file name suffix |
|
101 //QString fileNameSuffix; |
|
102 //qobject_cast<CxeSettings*>(mFakeSettings)->get(CxeSettingIds::FNAME_FOLDER_SUFFIX, fileNameSuffix); |
|
103 //QString fileNameSuffix(""); |
|
104 //QString cleanedFileNameSuffix = fnFormat.arg(fileNameSuffix); |
|
105 |
|
106 QString monthName = QDate::currentDate().toString("yyyyMM"); |
|
107 QString filename; |
|
108 //filename.sprintf("\\Images\\Camera\\%s\\%sA0\\%04d%s.jpg", monthName.toAscii().data(), monthName.toAscii().data(), counter, fileNameSuffix); |
|
109 filename.sprintf("\\Images\\Camera\\%s\\%sA0\\%04d.jpg", monthName.toAscii().data(), monthName.toAscii().data(), counter); |
|
110 return filename; |
|
111 } |
|
112 |
|
113 QString UnitTestCxeFilenameGeneratorSymbian::generateSequenceImageFileName(int counter, int burstIndex) |
|
114 { |
|
115 // For now, burst image names are created like normal unique names |
|
116 QString filename = generateImageFileName(counter); |
|
117 // get the file name suffix |
|
118 /*QString fileNameSuffix; |
|
119 qobject_cast<CxeSettings*>(mFakeSettings)->get(CxeSettingIds::FNAME_FOLDER_SUFFIX, fileNameSuffix); |
|
120 |
|
121 QString monthName = QDate::currentDate().toString("yyyyMM"); |
|
122 QString filename; |
|
123 filename.sprintf("\\Images\\Camera\\%s\\%sA0\\%04d%s(%02d).jpg", monthName.toAscii().data(), monthName.toAscii().data(), counter, fileNameSuffix, burstIndex); |
|
124 */ |
|
125 return filename; |
|
126 } |
|
127 |
|
128 QString UnitTestCxeFilenameGeneratorSymbian::removeDrive(const QString &filename) |
|
129 { |
|
130 // File name generator may return paths that point to C, E, or F drives. |
|
131 // In order to simplify path verification, all drive letters are removed. |
|
132 |
|
133 QString res = filename; |
|
134 res.remove(QRegExp("^c:\\\\data", Qt::CaseInsensitive)); |
|
135 res.remove(QRegExp("^e:", Qt::CaseInsensitive)); |
|
136 res.remove(QRegExp("^f:", Qt::CaseInsensitive)); |
|
137 return res; |
|
138 } |
|
139 |
|
140 // main() function non-GUI testing |
|
141 QTEST_MAIN(UnitTestCxeFilenameGeneratorSymbian); |
|