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