|
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 #include <QDate> |
|
18 #include <QTest> |
|
19 #include <QDebug> |
|
20 #include <QSignalSpy> |
|
21 |
|
22 #include <bitdev.h> |
|
23 |
|
24 #include "unittest_cxeimagedataitemsymbian.h" |
|
25 #include "cxeimagedataitemunit.h" |
|
26 #include "cxestillimagesymbian.h" |
|
27 #include "cxutils.h" |
|
28 |
|
29 |
|
30 UnitTestCxeImageDataItemSymbian::UnitTestCxeImageDataItemSymbian() |
|
31 : mImageDataItem(NULL) |
|
32 { |
|
33 } |
|
34 |
|
35 UnitTestCxeImageDataItemSymbian::~UnitTestCxeImageDataItemSymbian() |
|
36 { |
|
37 delete mImageDataItem; |
|
38 } |
|
39 |
|
40 void UnitTestCxeImageDataItemSymbian::init() |
|
41 { |
|
42 CX_DEBUG_ENTER_FUNCTION(); |
|
43 TInt index = 0; |
|
44 mPath = generateImageFileName(index); |
|
45 QByteArray data = "1234"; |
|
46 |
|
47 mImageDataItem = new CxeImageDataItemUnit(index, data, mPath); |
|
48 |
|
49 QVERIFY(mImageDataItem->state() == CxeImageDataItem::SavePending); |
|
50 CX_DEBUG_EXIT_FUNCTION(); |
|
51 } |
|
52 |
|
53 void UnitTestCxeImageDataItemSymbian::cleanup() |
|
54 { |
|
55 CX_DEBUG_ENTER_FUNCTION(); |
|
56 delete mImageDataItem; |
|
57 mImageDataItem = NULL; |
|
58 CX_DEBUG_EXIT_FUNCTION(); |
|
59 } |
|
60 |
|
61 void UnitTestCxeImageDataItemSymbian::testSave() |
|
62 { |
|
63 CX_DEBUG_ENTER_FUNCTION(); |
|
64 const int id = mImageDataItem->id(); |
|
65 |
|
66 QSignalSpy deviceStateSpy(mImageDataItem, SIGNAL(imageSaved(CxeError::Id, const QString&, int))); |
|
67 QVERIFY(deviceStateSpy.isValid()); |
|
68 |
|
69 int returnValue = mImageDataItem->save(); |
|
70 |
|
71 QVERIFY(mImageDataItem->state() == CxeImageDataItem::Saved); |
|
72 QVERIFY(returnValue == KErrNone); |
|
73 |
|
74 QCOMPARE( deviceStateSpy.count(), 1 ); |
|
75 if (deviceStateSpy.count() > 0) { |
|
76 QList<QVariant> initModeArguments = deviceStateSpy.takeFirst(); |
|
77 QVERIFY( initModeArguments.at(0).toInt() == CxeError::None ); |
|
78 QVERIFY( initModeArguments.at(1).toString().compare(mPath) == 0); |
|
79 QVERIFY( initModeArguments.at(2).toInt() == id); |
|
80 } |
|
81 CX_DEBUG_EXIT_FUNCTION(); |
|
82 } |
|
83 |
|
84 |
|
85 void UnitTestCxeImageDataItemSymbian::testSaveFail() |
|
86 { |
|
87 CX_DEBUG_ENTER_FUNCTION(); |
|
88 int returnValue; |
|
89 int index = 1; |
|
90 QString path = NULL; |
|
91 QByteArray data = ""; |
|
92 |
|
93 returnValue = mImageDataItem->save(); |
|
94 QVERIFY(mImageDataItem->state() == CxeImageDataItem::Saved); |
|
95 QVERIFY(returnValue == KErrArgument); |
|
96 |
|
97 delete mImageDataItem; |
|
98 mImageDataItem = NULL; |
|
99 mImageDataItem = new CxeImageDataItemUnit( index, data, path ); |
|
100 returnValue = mImageDataItem->save(); |
|
101 QVERIFY(mImageDataItem->state() == CxeImageDataItem::SaveFailed); |
|
102 QVERIFY(returnValue == KErrArgument); |
|
103 |
|
104 delete mImageDataItem; |
|
105 mImageDataItem = NULL; |
|
106 QString filename = generateImageFileNameWithLetter(++index, "C"); |
|
107 mImageDataItem = new CxeImageDataItemUnit( index, data, filename ); |
|
108 returnValue = mImageDataItem->save(); |
|
109 QVERIFY(mImageDataItem->state() == CxeImageDataItem::SaveFailed); |
|
110 QVERIFY(returnValue != KErrNone); |
|
111 |
|
112 qDebug() << "UnitTestCxeImageDataItemSymbian::testSaveFail3 =>"; |
|
113 delete mImageDataItem; |
|
114 mImageDataItem = NULL; |
|
115 filename = generateImageFileNameWithLetter(++index, ""); |
|
116 mImageDataItem = new CxeImageDataItemUnit( index, data, filename ); |
|
117 returnValue = mImageDataItem->save(); |
|
118 QVERIFY(mImageDataItem->state() == CxeImageDataItem::SaveFailed); |
|
119 QVERIFY(returnValue != KErrNone); |
|
120 |
|
121 qDebug() << "UnitTestCxeImageDataItemSymbian::testSaveFail4 =>"; |
|
122 delete mImageDataItem; |
|
123 mImageDataItem = NULL; |
|
124 filename = generateImageFileNameWithLetter(++index, "12"); |
|
125 mImageDataItem = new CxeImageDataItemUnit( index, data, filename ); |
|
126 returnValue = mImageDataItem->save(); |
|
127 QVERIFY(mImageDataItem->state() == CxeImageDataItem::SaveFailed); |
|
128 QVERIFY(returnValue != KErrNone); |
|
129 |
|
130 qDebug() << "UnitTestCxeImageDataItemSymbian::testSaveFail5 =>"; |
|
131 delete mImageDataItem; |
|
132 mImageDataItem = NULL; |
|
133 filename = generateImageFileNameWithLetter(++index, "Edata"); |
|
134 mImageDataItem = new CxeImageDataItemUnit( index, data, filename ); |
|
135 returnValue = mImageDataItem->save(); |
|
136 QVERIFY(mImageDataItem->state() == CxeImageDataItem::SaveFailed); |
|
137 QVERIFY(returnValue != KErrNone); |
|
138 |
|
139 CX_DEBUG_EXIT_FUNCTION(); |
|
140 } |
|
141 |
|
142 void UnitTestCxeImageDataItemSymbian::testPath() |
|
143 { |
|
144 CX_DEBUG_ENTER_FUNCTION(); |
|
145 QVERIFY(mImageDataItem->path().compare(mPath) == 0); |
|
146 } |
|
147 |
|
148 |
|
149 QString UnitTestCxeImageDataItemSymbian::generateImageFileName(int counter) |
|
150 { |
|
151 CX_DEBUG_ENTER_FUNCTION(); |
|
152 QString monthName = QDate::currentDate().toString("yyyyMM"); |
|
153 QString filename; |
|
154 filename.sprintf("E:\\Images\\Camera\\%s\\%sA0\\%04d_Nokia5800.jpg", |
|
155 monthName.toAscii().data(), |
|
156 monthName.toAscii().data(), |
|
157 counter); |
|
158 CX_DEBUG_EXIT_FUNCTION(); |
|
159 return filename; |
|
160 } |
|
161 |
|
162 QString UnitTestCxeImageDataItemSymbian::generateImageFileNameWithLetter(int counter, QString letter) |
|
163 { |
|
164 CX_DEBUG_ENTER_FUNCTION(); |
|
165 QString monthName = QDate::currentDate().toString("yyyyMM"); |
|
166 QString filename; |
|
167 filename.sprintf("%s:\\Images\\Camera\\%s\\%sA0\\%04d_Nokia5800.jpg", |
|
168 letter.toAscii().data(), |
|
169 monthName.toAscii().data(), |
|
170 monthName.toAscii().data(), |
|
171 counter); |
|
172 CX_DEBUG_EXIT_FUNCTION(); |
|
173 return filename; |
|
174 } |
|
175 |
|
176 // main() function non-GUI testing |
|
177 QTEST_APPLESS_MAIN(UnitTestCxeImageDataItemSymbian); |