|
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 <QThread> |
|
20 #include <QByteArray> |
|
21 #include <QSignalSpy> |
|
22 #include <locationtrailpskeys.h> |
|
23 #include <rlocationtrail.h> |
|
24 |
|
25 #include "unittest_cxegeotaggingtrail.h" |
|
26 #include "cxefakestillcapturecontrol.h" |
|
27 #include "cxefakevideocapturecontrol.h" |
|
28 #include "cxegeotaggingtrail.h" |
|
29 #include "cxefakesettings.h" |
|
30 #include "cxetestutils.h" |
|
31 #include "cxenamespace.h" |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 /** |
|
37 * UnitTestCxeGeoTaggingTrail::UnitTestCxeGeoTaggingTrail() |
|
38 */ |
|
39 UnitTestCxeGeoTaggingTrail::UnitTestCxeGeoTaggingTrail() |
|
40 : mTrail(NULL), mSettings(NULL) |
|
41 { |
|
42 } |
|
43 |
|
44 /** |
|
45 * UnitTestCxeGeoTaggingTrail::~UnitTestCxeGeoTaggingTrail() |
|
46 */ |
|
47 UnitTestCxeGeoTaggingTrail::~UnitTestCxeGeoTaggingTrail() |
|
48 { |
|
49 cleanup(); |
|
50 } |
|
51 |
|
52 /** |
|
53 * UnitTestCxeGeoTaggingTrail::init() |
|
54 */ |
|
55 void UnitTestCxeGeoTaggingTrail::init() |
|
56 { |
|
57 CxeFakeStillCaptureControl *fakeStillControl = new CxeFakeStillCaptureControl(); |
|
58 CxeFakeVideoCaptureControl *fakeVideoControl = new CxeFakeVideoCaptureControl(); |
|
59 mSettings = new CxeFakeSettings(); |
|
60 |
|
61 CxeStillCaptureControl *stillControl = qobject_cast<CxeStillCaptureControl*>(fakeStillControl); |
|
62 CxeVideoCaptureControl *videoControl = qobject_cast<CxeVideoCaptureControl*>(fakeVideoControl); |
|
63 |
|
64 // trail is started automatically during construction |
|
65 mTrail = new CxeGeoTaggingTrail(*stillControl, *videoControl, *mSettings); |
|
66 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::NotConnected); |
|
67 } |
|
68 |
|
69 /** |
|
70 * UnitTestCxeGeoTaggingTrail::cleanup() |
|
71 */ |
|
72 void UnitTestCxeGeoTaggingTrail::cleanup() |
|
73 { |
|
74 delete mTrail; |
|
75 mTrail = NULL; |
|
76 |
|
77 delete mSettings; |
|
78 mSettings = NULL; |
|
79 } |
|
80 |
|
81 |
|
82 /** |
|
83 * UnitTestCxeGeoTaggingTrail::testStart() |
|
84 */ |
|
85 void UnitTestCxeGeoTaggingTrail::testStart() |
|
86 { |
|
87 int settingValue; |
|
88 // case 1: try to start/stop geotagging trail when setting is off |
|
89 settingValue = 0; |
|
90 mSettings->set(CxeSettingIds::GEOTAGGING, settingValue); |
|
91 mTrail->start(); |
|
92 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::NotConnected); |
|
93 |
|
94 mTrail->stop(); |
|
95 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::NotConnected); |
|
96 |
|
97 // case 2: geotagging setting is ON, starting trail and emulating real state changes in P&S key |
|
98 settingValue = 1; |
|
99 mSettings->set(CxeSettingIds::GEOTAGGING, settingValue); |
|
100 mTrail->start(); |
|
101 |
|
102 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::TrailStarted); |
|
103 |
|
104 // trail started, emulate as if P&S key has state updates from RLocationTrail. |
|
105 int newState = RLocationTrail::ETrailStarted; |
|
106 mSettings->emulate(KPSUidLocationTrail.iUid, KLocationTrailState, newState); |
|
107 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::DataAvailable); |
|
108 |
|
109 // case 3: geotagging setting on, trail started, but RLocationTrail doesnt get trail ongoing |
|
110 settingValue = 1; |
|
111 mSettings->set(CxeSettingIds::GEOTAGGING, settingValue); |
|
112 mTrail->start(); |
|
113 |
|
114 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::DataAvailable); |
|
115 |
|
116 // trail started, emulate as if P&S key has state updates from RLocationTrail. |
|
117 newState = RLocationTrail::EWaitingGPSData; |
|
118 mSettings->emulate(KPSUidLocationTrail.iUid, KLocationTrailState, newState); |
|
119 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::DataAvailable); |
|
120 |
|
121 // we now try to stop trail |
|
122 mTrail->stop(); |
|
123 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::Connected); |
|
124 |
|
125 // Case 4: just changing the setting value |
|
126 // setting value is ON, trail should start |
|
127 settingValue = 1; |
|
128 mSettings->set(CxeSettingIds::GEOTAGGING, settingValue); |
|
129 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::TrailStarted); |
|
130 |
|
131 // trail started, emulate as if P&S key has state updates from RLocationTrail. |
|
132 newState = RLocationTrail::ETrailStarted; |
|
133 mSettings->emulate(KPSUidLocationTrail.iUid, KLocationTrailState, newState); |
|
134 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::DataAvailable); |
|
135 |
|
136 // setting value is OFF, trail should stop |
|
137 settingValue = 0; |
|
138 mSettings->set(CxeSettingIds::GEOTAGGING, settingValue); |
|
139 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::Connected); |
|
140 |
|
141 } |
|
142 |
|
143 /** |
|
144 * UnitTestCxeGeoTaggingTrail::testStop() |
|
145 */ |
|
146 void UnitTestCxeGeoTaggingTrail::testStop() |
|
147 { |
|
148 // case 1: Trying to stop the trail even before starting |
|
149 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::NotConnected); |
|
150 mTrail->stop(); |
|
151 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::NotConnected); |
|
152 |
|
153 // case 2: trail connected but not started |
|
154 int settingValue = 1; |
|
155 mSettings->set(CxeSettingIds::GEOTAGGING, settingValue); |
|
156 mTrail->start(); |
|
157 |
|
158 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::TrailStarted); |
|
159 |
|
160 // now stopping trail: |
|
161 mTrail->stop(); |
|
162 // here we are connected to trail but trail not started. |
|
163 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::Connected); |
|
164 |
|
165 // trying to stop the trail again |
|
166 mTrail->stop(); |
|
167 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::Connected); |
|
168 |
|
169 } |
|
170 |
|
171 |
|
172 |
|
173 /** |
|
174 * UnitTestCxeGeoTaggingTrail::testState() |
|
175 */ |
|
176 void UnitTestCxeGeoTaggingTrail::testState() |
|
177 { |
|
178 QCOMPARE(mTrail->state(), CxeGeoTaggingTrail::NotConnected); |
|
179 } |
|
180 |
|
181 // main() function |
|
182 QTEST_MAIN(UnitTestCxeGeoTaggingTrail); |
|
183 |
|
184 // end of file |