|
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 #include <QByteArray> |
|
20 #include <QSignalSpy> |
|
21 #include <QThread> |
|
22 |
|
23 #include "unittest_cxefilesavethreadsymbian.h" |
|
24 #include "cxefilesavethreadsymbian.h" |
|
25 #include "cxefakeimagedataitem.h" |
|
26 #include "cxeimagedataitem.h" |
|
27 #include "cxetestutils.h" |
|
28 |
|
29 |
|
30 |
|
31 /** |
|
32 * UnitTestCxeFileSaveThreadSymbian::UnitTestCxeFileSaveThreadSymbian() |
|
33 */ |
|
34 UnitTestCxeFileSaveThreadSymbian::UnitTestCxeFileSaveThreadSymbian() |
|
35 : mFileSaveThread(NULL) |
|
36 { |
|
37 } |
|
38 |
|
39 /** |
|
40 * UnitTestCxeFileSaveThreadSymbian::~UnitTestCxeFileSaveThreadSymbian() |
|
41 */ |
|
42 UnitTestCxeFileSaveThreadSymbian::~UnitTestCxeFileSaveThreadSymbian() |
|
43 { |
|
44 cleanup(); |
|
45 } |
|
46 |
|
47 /** |
|
48 * UnitTestCxeFileSaveThreadSymbian::init() |
|
49 */ |
|
50 void UnitTestCxeFileSaveThreadSymbian::init() |
|
51 { |
|
52 mFileSaveThread = new CxeFileSaveThreadSymbian(this); |
|
53 } |
|
54 |
|
55 /** |
|
56 * UnitTestCxeFileSaveThreadSymbian::cleanup() |
|
57 */ |
|
58 void UnitTestCxeFileSaveThreadSymbian::cleanup() |
|
59 { |
|
60 delete mFileSaveThread; |
|
61 mFileSaveThread = NULL; |
|
62 } |
|
63 |
|
64 |
|
65 /** |
|
66 * UnitTestCxeFileSaveThreadSymbian::testSave() |
|
67 */ |
|
68 void UnitTestCxeFileSaveThreadSymbian::testSave() |
|
69 { |
|
70 QString filename("e:\\testdata.txt"); |
|
71 |
|
72 // Case 0: Checking if a file is saved with all valid parameters |
|
73 const int index(2); |
|
74 const int id(7); |
|
75 CxeImageDataItem *imageDataItem = new CxeFakeImageDataItem(index, QByteArray("unit test successful"), filename, id); |
|
76 |
|
77 QSignalSpy imageItemStateSpy(imageDataItem, SIGNAL(imageSaved(CxeError::Id, const QString&, int))); |
|
78 |
|
79 QVERIFY(imageItemStateSpy.isValid()); |
|
80 |
|
81 QCOMPARE(imageDataItem->state(), CxeImageDataItem::SavePending); |
|
82 //Saving thread takes ownership of dataItem |
|
83 mFileSaveThread->save(imageDataItem); |
|
84 // wait for imageSavedSignal |
|
85 QVERIFY(CxeTestUtils::waitForSignal(imageItemStateSpy, 100)); |
|
86 |
|
87 QCOMPARE(imageItemStateSpy.count(), 1); |
|
88 if (imageItemStateSpy.count() > 0) { |
|
89 QList<QVariant> initModeArguments = imageItemStateSpy.takeFirst(); |
|
90 QCOMPARE(initModeArguments.at(0).toInt(), (int)CxeError::None); |
|
91 QCOMPARE(initModeArguments.at(1).toString(), filename); |
|
92 QCOMPARE(initModeArguments.at(2).toInt(), id); |
|
93 } |
|
94 |
|
95 QVERIFY(mFileSaveThread->isRunning()); |
|
96 |
|
97 // case 1: checking with CxeImageDataItem = NULL |
|
98 mFileSaveThread->save(NULL); |
|
99 |
|
100 } |
|
101 |
|
102 // main() function |
|
103 QTEST_MAIN(UnitTestCxeFileSaveThreadSymbian); |
|
104 |
|
105 // end of file |