Merge lp:~michihenning/storage-framework/remote-client-coverage into lp:storage-framework/devel
- remote-client-coverage
- Merge into devel
Status: | Merged |
---|---|
Approved by: | James Henstridge |
Approved revision: | 60 |
Merged at revision: | 57 |
Proposed branch: | lp:~michihenning/storage-framework/remote-client-coverage |
Merge into: | lp:storage-framework/devel |
Diff against target: |
1244 lines (+766/-105) 14 files modified
demo/provider_test/provider-test.cpp (+1/-1) src/provider/internal/TestServerImpl.cpp (+1/-1) src/provider/testing/TestServer.cpp (+0/-1) src/qt/client/internal/remote_client/AccountImpl.cpp (+2/-6) src/qt/client/internal/remote_client/RuntimeImpl.cpp (+8/-2) tests/provider-ProviderInterface/CMakeLists.txt (+0/-14) tests/provider-ProviderInterface/ProviderInterface_test.cpp (+21/-66) tests/remote-client/CMakeLists.txt (+3/-2) tests/remote-client/MockProvider.cpp (+236/-0) tests/remote-client/MockProvider.h (+96/-0) tests/remote-client/remote-client_test.cpp (+254/-10) tests/utils/CMakeLists.txt (+16/-2) tests/utils/ProviderFixture.cpp (+79/-0) tests/utils/ProviderFixture.h (+49/-0) |
To merge this branch: | bzr merge lp:~michihenning/storage-framework/remote-client-coverage |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Henstridge | Approve | ||
unity-api-1-bot | continuous-integration | Approve | |
Review via email:
|
Commit message
Increased remote client coverage.
Description of the change
Refactored the fake provider from the provider test into test/utils.
Added mock provider for remote client test. (This is currently mostly
a copy of the original; I'll pare that down to something simpler as I flesh out coverage some more.)
This is incomplete, but I don't want the MR to get any larger, so I'll push this in stages.
Added coverage tests to make sure that we are handling a destroyed runtime correctly if the runtime is destroyed while the reply to a dbus request is outstanding.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
unity-api-1-bot (unity-api-1-bot) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:57
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
James Henstridge (jamesh) wrote : | # |
I've noted a few things that need attention as inline comments
- 58. By Michi Henning
-
Review comments from James.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Michi Henning (michihenning) wrote : | # |
Thanks for that!
I've renamed the test class to ProviderFixture and addressed the other issues.
- 59. By Michi Henning
-
Oops, missed change in MockProvider.cpp.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:58
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:59
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
James Henstridge (jamesh) wrote : | # |
The class still seems to be called FakeProvider?
- 60. By Michi Henning
-
Renamed FakeProvider -> ProviderFixture.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Michi Henning (michihenning) wrote : | # |
Oh boy, I shouldn't be writing code when I'm sick :-(
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:60
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:60
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === modified file 'demo/provider_test/provider-test.cpp' | |||
2 | --- demo/provider_test/provider-test.cpp 2016-08-18 09:25:51 +0000 | |||
3 | +++ demo/provider_test/provider-test.cpp 2016-08-23 01:48:44 +0000 | |||
4 | @@ -161,7 +161,7 @@ | |||
5 | 161 | if (page_token != "") | 161 | if (page_token != "") |
6 | 162 | { | 162 | { |
7 | 163 | string msg = string("Item::list(): invalid page token: \"") + page_token + "\""; | 163 | string msg = string("Item::list(): invalid page token: \"") + page_token + "\""; |
9 | 164 | return make_exceptional_future<tuple<ItemList,string>>(msg); | 164 | return make_exceptional_future<tuple<ItemList,string>>(LogicException(msg)); |
10 | 165 | } | 165 | } |
11 | 166 | ItemList children = | 166 | ItemList children = |
12 | 167 | { | 167 | { |
13 | 168 | 168 | ||
14 | === modified file 'src/provider/internal/TestServerImpl.cpp' | |||
15 | --- src/provider/internal/TestServerImpl.cpp 2016-08-12 01:34:34 +0000 | |||
16 | +++ src/provider/internal/TestServerImpl.cpp 2016-08-23 01:48:44 +0000 | |||
17 | @@ -56,7 +56,7 @@ | |||
18 | 56 | new ProviderAdaptor(interface_.get()); | 56 | new ProviderAdaptor(interface_.get()); |
19 | 57 | 57 | ||
20 | 58 | if (!connection_.registerObject(QString::fromStdString(object_path_), | 58 | if (!connection_.registerObject(QString::fromStdString(object_path_), |
22 | 59 | interface_.get())) | 59 | interface_.get())) |
23 | 60 | { | 60 | { |
24 | 61 | string msg = "Could not register provider on connection: " + connection_.lastError().message().toStdString(); | 61 | string msg = "Could not register provider on connection: " + connection_.lastError().message().toStdString(); |
25 | 62 | throw ResourceException(msg, int(connection_.lastError().type())); | 62 | throw ResourceException(msg, int(connection_.lastError().type())); |
26 | 63 | 63 | ||
27 | === modified file 'src/provider/testing/TestServer.cpp' | |||
28 | --- src/provider/testing/TestServer.cpp 2016-08-11 04:29:36 +0000 | |||
29 | +++ src/provider/testing/TestServer.cpp 2016-08-23 01:48:44 +0000 | |||
30 | @@ -22,7 +22,6 @@ | |||
31 | 22 | 22 | ||
32 | 23 | #include <OnlineAccounts/Account> | 23 | #include <OnlineAccounts/Account> |
33 | 24 | 24 | ||
34 | 25 | |||
35 | 26 | using namespace std; | 25 | using namespace std; |
36 | 27 | 26 | ||
37 | 28 | namespace unity | 27 | namespace unity |
38 | 29 | 28 | ||
39 | === modified file 'src/qt/client/internal/remote_client/AccountImpl.cpp' | |||
40 | --- src/qt/client/internal/remote_client/AccountImpl.cpp 2016-08-11 07:34:49 +0000 | |||
41 | +++ src/qt/client/internal/remote_client/AccountImpl.cpp 2016-08-23 01:48:44 +0000 | |||
42 | @@ -55,10 +55,6 @@ | |||
43 | 55 | auto rt_impl = dynamic_pointer_cast<RuntimeImpl>(runtime.lock()->p_); | 55 | auto rt_impl = dynamic_pointer_cast<RuntimeImpl>(runtime.lock()->p_); |
44 | 56 | assert(rt_impl); | 56 | assert(rt_impl); |
45 | 57 | provider_.reset(new ProviderInterface(bus_name, object_path, rt_impl->connection())); | 57 | provider_.reset(new ProviderInterface(bus_name, object_path, rt_impl->connection())); |
46 | 58 | if (!provider_->isValid()) | ||
47 | 59 | { | ||
48 | 60 | throw LocalCommsException("AccountImpl(): " + provider_->lastError().message()); | ||
49 | 61 | } | ||
50 | 62 | } | 58 | } |
51 | 63 | 59 | ||
52 | 64 | QString AccountImpl::owner() const | 60 | QString AccountImpl::owner() const |
53 | @@ -85,9 +81,9 @@ | |||
54 | 85 | { | 81 | { |
55 | 86 | runtime(); // Throws if runtime was destroyed. | 82 | runtime(); // Throws if runtime was destroyed. |
56 | 87 | } | 83 | } |
58 | 88 | catch (RuntimeDestroyedException const& e) | 84 | catch (RuntimeDestroyedException const&) |
59 | 89 | { | 85 | { |
61 | 90 | return make_exceptional_future<QVector<Root::SPtr>>(e); | 86 | return make_exceptional_future<QVector<Root::SPtr>>(RuntimeDestroyedException("Account::roots()")); |
62 | 91 | } | 87 | } |
63 | 92 | 88 | ||
64 | 93 | auto reply = provider_->Roots(); | 89 | auto reply = provider_->Roots(); |
65 | 94 | 90 | ||
66 | === modified file 'src/qt/client/internal/remote_client/RuntimeImpl.cpp' | |||
67 | --- src/qt/client/internal/remote_client/RuntimeImpl.cpp 2016-08-19 03:16:52 +0000 | |||
68 | +++ src/qt/client/internal/remote_client/RuntimeImpl.cpp 2016-08-23 01:48:44 +0000 | |||
69 | @@ -84,9 +84,9 @@ | |||
70 | 84 | shutdown(); | 84 | shutdown(); |
71 | 85 | } | 85 | } |
72 | 86 | // LCOV_EXCL_START | 86 | // LCOV_EXCL_START |
74 | 87 | catch (std::exception const&) | 87 | catch (std::exception const& e) |
75 | 88 | { | 88 | { |
77 | 89 | qCritical() << "shutdown error"; // TODO, log the error properly | 89 | qCritical() << "shutdown error" << e.what(); |
78 | 90 | } | 90 | } |
79 | 91 | // LCOV_EXCL_STOP | 91 | // LCOV_EXCL_STOP |
80 | 92 | } | 92 | } |
81 | @@ -130,8 +130,10 @@ | |||
82 | 130 | { | 130 | { |
83 | 131 | if (destroyed_) | 131 | if (destroyed_) |
84 | 132 | { | 132 | { |
85 | 133 | // LCOV_EXCL_START | ||
86 | 133 | make_exceptional_future(qf_, RuntimeDestroyedException("Runtime::accounts()")); | 134 | make_exceptional_future(qf_, RuntimeDestroyedException("Runtime::accounts()")); |
87 | 134 | return; | 135 | return; |
88 | 136 | // LCOV_EXCL_STOP | ||
89 | 135 | } | 137 | } |
90 | 136 | 138 | ||
91 | 137 | timer_.stop(); | 139 | timer_.stop(); |
92 | @@ -161,16 +163,20 @@ | |||
93 | 161 | accounts_ = accounts; | 163 | accounts_ = accounts; |
94 | 162 | make_ready_future(qf_, accounts); | 164 | make_ready_future(qf_, accounts); |
95 | 163 | } | 165 | } |
96 | 166 | // LCOV_EXCL_START | ||
97 | 164 | catch (StorageException const& e) | 167 | catch (StorageException const& e) |
98 | 165 | { | 168 | { |
99 | 166 | make_exceptional_future(qf_, e); | 169 | make_exceptional_future(qf_, e); |
100 | 167 | } | 170 | } |
101 | 171 | // LCOV_EXCL_STOP | ||
102 | 168 | } | 172 | } |
103 | 169 | 173 | ||
104 | 174 | // LCOV_EXCL_START | ||
105 | 170 | void RuntimeImpl::timeout() | 175 | void RuntimeImpl::timeout() |
106 | 171 | { | 176 | { |
107 | 172 | make_exceptional_future(qf_, ResourceException("Runtime::accounts(): timeout retrieving Online accounts", 0)); | 177 | make_exceptional_future(qf_, ResourceException("Runtime::accounts(): timeout retrieving Online accounts", 0)); |
108 | 173 | } | 178 | } |
109 | 179 | // LCOV_EXCL_STOP | ||
110 | 174 | 180 | ||
111 | 175 | shared_ptr<Account> RuntimeImpl::make_test_account(QString const& bus_name, | 181 | shared_ptr<Account> RuntimeImpl::make_test_account(QString const& bus_name, |
112 | 176 | QString const& object_path) | 182 | QString const& object_path) |
113 | 177 | 183 | ||
114 | === modified file 'tests/provider-ProviderInterface/CMakeLists.txt' | |||
115 | --- tests/provider-ProviderInterface/CMakeLists.txt 2016-08-11 08:21:23 +0000 | |||
116 | +++ tests/provider-ProviderInterface/CMakeLists.txt 2016-08-23 01:48:44 +0000 | |||
117 | @@ -1,17 +1,3 @@ | |||
118 | 1 | |||
119 | 2 | |||
120 | 3 | set_source_files_properties(${CMAKE_SOURCE_DIR}/data/provider.xml PROPERTIES | ||
121 | 4 | CLASSNAME ProviderClient | ||
122 | 5 | INCLUDE unity/storage/internal/dbusmarshal.h | ||
123 | 6 | ) | ||
124 | 7 | qt5_add_dbus_interface(generated_files | ||
125 | 8 | ${CMAKE_SOURCE_DIR}/data/provider.xml | ||
126 | 9 | ProviderClient | ||
127 | 10 | ) | ||
128 | 11 | set_source_files_properties(${generated_files} PROPERTIES | ||
129 | 12 | GENERATED TRUE | ||
130 | 13 | ) | ||
131 | 14 | |||
132 | 15 | add_executable(provider-ProviderInterface_test | 1 | add_executable(provider-ProviderInterface_test |
133 | 16 | ProviderInterface_test.cpp | 2 | ProviderInterface_test.cpp |
134 | 17 | TestProvider.cpp | 3 | TestProvider.cpp |
135 | 18 | 4 | ||
136 | === modified file 'tests/provider-ProviderInterface/ProviderInterface_test.cpp' | |||
137 | --- tests/provider-ProviderInterface/ProviderInterface_test.cpp 2016-08-12 06:29:15 +0000 | |||
138 | +++ tests/provider-ProviderInterface/ProviderInterface_test.cpp 2016-08-23 01:48:44 +0000 | |||
139 | @@ -21,9 +21,8 @@ | |||
140 | 21 | #include <unity/storage/provider/testing/TestServer.h> | 21 | #include <unity/storage/provider/testing/TestServer.h> |
141 | 22 | 22 | ||
142 | 23 | #include "TestProvider.h" | 23 | #include "TestProvider.h" |
143 | 24 | #include "ProviderClient.h" | ||
144 | 25 | 24 | ||
146 | 26 | #include <utils/DBusEnvironment.h> | 25 | #include <utils/ProviderFixture.h> |
147 | 27 | 26 | ||
148 | 28 | #include <gtest/gtest.h> | 27 | #include <gtest/gtest.h> |
149 | 29 | #include <OnlineAccounts/Account> | 28 | #include <OnlineAccounts/Account> |
150 | @@ -55,69 +54,25 @@ | |||
151 | 55 | 54 | ||
152 | 56 | } | 55 | } |
153 | 57 | 56 | ||
156 | 58 | 57 | class ProviderInterfaceTest : public ProviderFixture | |
155 | 59 | class ProviderInterfaceTest : public ::testing::Test | ||
157 | 60 | { | 58 | { |
158 | 61 | public: | ||
159 | 62 | QDBusConnection const& connection() | ||
160 | 63 | { | ||
161 | 64 | return dbus_->connection(); | ||
162 | 65 | } | ||
163 | 66 | |||
164 | 67 | void make_provider(unique_ptr<ProviderBase>&& provider) | ||
165 | 68 | { | ||
166 | 69 | account_manager_->waitForReady(); | ||
167 | 70 | OnlineAccounts::Account* account = account_manager_->account( | ||
168 | 71 | 2, "oauth2-service"); | ||
169 | 72 | ASSERT_NE(nullptr, account); | ||
170 | 73 | |||
171 | 74 | test_server_.reset( | ||
172 | 75 | new TestServer(move(provider), account, | ||
173 | 76 | *service_connection_, BUS_PATH.toStdString())); | ||
174 | 77 | |||
175 | 78 | client_.reset(new ProviderClient(service_connection_->baseService(), | ||
176 | 79 | BUS_PATH, | ||
177 | 80 | connection())); | ||
178 | 81 | } | ||
179 | 82 | |||
180 | 83 | void wait_for(QDBusPendingCall const& call) { | ||
181 | 84 | QDBusPendingCallWatcher watcher(call); | ||
182 | 85 | QSignalSpy spy(&watcher, &QDBusPendingCallWatcher::finished); | ||
183 | 86 | ASSERT_TRUE(spy.wait()); | ||
184 | 87 | } | ||
185 | 88 | |||
186 | 89 | protected: | 59 | protected: |
187 | 90 | void SetUp() override | 60 | void SetUp() override |
188 | 91 | { | 61 | { |
196 | 92 | dbus_.reset(new DBusEnvironment); | 62 | client_.reset(new ProviderClient(service_connection_->baseService(), BUS_PATH, connection())); |
190 | 93 | dbus_->start_services(); | ||
191 | 94 | service_connection_.reset( | ||
192 | 95 | new QDBusConnection(QDBusConnection::connectToBus( | ||
193 | 96 | dbus_->busAddress(), SERVICE_CONNECTION_NAME))); | ||
194 | 97 | account_manager_.reset(new OnlineAccounts::Manager( | ||
195 | 98 | "", *service_connection_)); | ||
197 | 99 | } | 63 | } |
198 | 100 | 64 | ||
199 | 101 | void TearDown() override | 65 | void TearDown() override |
200 | 102 | { | 66 | { |
201 | 103 | client_.reset(); | 67 | client_.reset(); |
202 | 104 | test_server_.reset(); | ||
203 | 105 | service_connection_.reset(); | ||
204 | 106 | QDBusConnection::disconnectFromBus(SERVICE_CONNECTION_NAME); | ||
205 | 107 | dbus_.reset(); | ||
206 | 108 | } | 68 | } |
207 | 109 | 69 | ||
213 | 110 | unique_ptr<DBusEnvironment> dbus_; | 70 | std::unique_ptr<ProviderClient> client_; |
209 | 111 | unique_ptr<QDBusConnection> service_connection_; | ||
210 | 112 | unique_ptr<OnlineAccounts::Manager> account_manager_; | ||
211 | 113 | unique_ptr<TestServer> test_server_; | ||
212 | 114 | unique_ptr<ProviderClient> client_; | ||
214 | 115 | }; | 71 | }; |
215 | 116 | 72 | ||
216 | 117 | |||
217 | 118 | TEST_F(ProviderInterfaceTest, roots) | 73 | TEST_F(ProviderInterfaceTest, roots) |
218 | 119 | { | 74 | { |
220 | 120 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 75 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
221 | 121 | 76 | ||
222 | 122 | auto reply = client_->Roots(); | 77 | auto reply = client_->Roots(); |
223 | 123 | wait_for(reply); | 78 | wait_for(reply); |
224 | @@ -133,7 +88,7 @@ | |||
225 | 133 | 88 | ||
226 | 134 | TEST_F(ProviderInterfaceTest, list) | 89 | TEST_F(ProviderInterfaceTest, list) |
227 | 135 | { | 90 | { |
229 | 136 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 91 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
230 | 137 | 92 | ||
231 | 138 | auto reply = client_->List("root_id", ""); | 93 | auto reply = client_->List("root_id", ""); |
232 | 139 | wait_for(reply); | 94 | wait_for(reply); |
233 | @@ -171,7 +126,7 @@ | |||
234 | 171 | 126 | ||
235 | 172 | TEST_F(ProviderInterfaceTest, lookup) | 127 | TEST_F(ProviderInterfaceTest, lookup) |
236 | 173 | { | 128 | { |
238 | 174 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 129 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
239 | 175 | 130 | ||
240 | 176 | auto reply = client_->Lookup("root_id", "Filename"); | 131 | auto reply = client_->Lookup("root_id", "Filename"); |
241 | 177 | wait_for(reply); | 132 | wait_for(reply); |
242 | @@ -187,7 +142,7 @@ | |||
243 | 187 | 142 | ||
244 | 188 | TEST_F(ProviderInterfaceTest, metadata) | 143 | TEST_F(ProviderInterfaceTest, metadata) |
245 | 189 | { | 144 | { |
247 | 190 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 145 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
248 | 191 | 146 | ||
249 | 192 | auto reply = client_->Metadata("root_id"); | 147 | auto reply = client_->Metadata("root_id"); |
250 | 193 | wait_for(reply); | 148 | wait_for(reply); |
251 | @@ -201,7 +156,7 @@ | |||
252 | 201 | 156 | ||
253 | 202 | TEST_F(ProviderInterfaceTest, create_folder) | 157 | TEST_F(ProviderInterfaceTest, create_folder) |
254 | 203 | { | 158 | { |
256 | 204 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 159 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
257 | 205 | 160 | ||
258 | 206 | auto reply = client_->CreateFolder("root_id", "New Folder"); | 161 | auto reply = client_->CreateFolder("root_id", "New Folder"); |
259 | 207 | wait_for(reply); | 162 | wait_for(reply); |
260 | @@ -215,7 +170,7 @@ | |||
261 | 215 | 170 | ||
262 | 216 | TEST_F(ProviderInterfaceTest, create_file) | 171 | TEST_F(ProviderInterfaceTest, create_file) |
263 | 217 | { | 172 | { |
265 | 218 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 173 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
266 | 219 | 174 | ||
267 | 220 | const std::string file_contents = "Hello world!"; | 175 | const std::string file_contents = "Hello world!"; |
268 | 221 | QString upload_id; | 176 | QString upload_id; |
269 | @@ -263,7 +218,7 @@ | |||
270 | 263 | 218 | ||
271 | 264 | TEST_F(ProviderInterfaceTest, update) | 219 | TEST_F(ProviderInterfaceTest, update) |
272 | 265 | { | 220 | { |
274 | 266 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 221 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
275 | 267 | 222 | ||
276 | 268 | const std::string file_contents = "Hello world!"; | 223 | const std::string file_contents = "Hello world!"; |
277 | 269 | QString upload_id; | 224 | QString upload_id; |
278 | @@ -309,7 +264,7 @@ | |||
279 | 309 | 264 | ||
280 | 310 | TEST_F(ProviderInterfaceTest, upload_short_write) | 265 | TEST_F(ProviderInterfaceTest, upload_short_write) |
281 | 311 | { | 266 | { |
283 | 312 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 267 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
284 | 313 | 268 | ||
285 | 314 | QString upload_id; | 269 | QString upload_id; |
286 | 315 | QDBusUnixFileDescriptor socket; | 270 | QDBusUnixFileDescriptor socket; |
287 | @@ -329,7 +284,7 @@ | |||
288 | 329 | 284 | ||
289 | 330 | TEST_F(ProviderInterfaceTest, upload_long_write) | 285 | TEST_F(ProviderInterfaceTest, upload_long_write) |
290 | 331 | { | 286 | { |
292 | 332 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 287 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
293 | 333 | 288 | ||
294 | 334 | const std::string file_contents = "Hello world!"; | 289 | const std::string file_contents = "Hello world!"; |
295 | 335 | QString upload_id; | 290 | QString upload_id; |
296 | @@ -374,7 +329,7 @@ | |||
297 | 374 | 329 | ||
298 | 375 | TEST_F(ProviderInterfaceTest, cancel_upload) | 330 | TEST_F(ProviderInterfaceTest, cancel_upload) |
299 | 376 | { | 331 | { |
301 | 377 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 332 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
302 | 378 | 333 | ||
303 | 379 | QString upload_id; | 334 | QString upload_id; |
304 | 380 | QDBusUnixFileDescriptor socket; | 335 | QDBusUnixFileDescriptor socket; |
305 | @@ -392,7 +347,7 @@ | |||
306 | 392 | 347 | ||
307 | 393 | TEST_F(ProviderInterfaceTest, finish_upload_unknown) | 348 | TEST_F(ProviderInterfaceTest, finish_upload_unknown) |
308 | 394 | { | 349 | { |
310 | 395 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 350 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
311 | 396 | 351 | ||
312 | 397 | auto reply = client_->FinishUpload("no-such-upload"); | 352 | auto reply = client_->FinishUpload("no-such-upload"); |
313 | 398 | wait_for(reply); | 353 | wait_for(reply); |
314 | @@ -403,7 +358,7 @@ | |||
315 | 403 | 358 | ||
316 | 404 | TEST_F(ProviderInterfaceTest, download) | 359 | TEST_F(ProviderInterfaceTest, download) |
317 | 405 | { | 360 | { |
319 | 406 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 361 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
320 | 407 | 362 | ||
321 | 408 | QString download_id; | 363 | QString download_id; |
322 | 409 | QDBusUnixFileDescriptor socket; | 364 | QDBusUnixFileDescriptor socket; |
323 | @@ -446,7 +401,7 @@ | |||
324 | 446 | 401 | ||
325 | 447 | TEST_F(ProviderInterfaceTest, download_short_read) | 402 | TEST_F(ProviderInterfaceTest, download_short_read) |
326 | 448 | { | 403 | { |
328 | 449 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 404 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
329 | 450 | 405 | ||
330 | 451 | QString download_id; | 406 | QString download_id; |
331 | 452 | QDBusUnixFileDescriptor socket; | 407 | QDBusUnixFileDescriptor socket; |
332 | @@ -466,7 +421,7 @@ | |||
333 | 466 | 421 | ||
334 | 467 | TEST_F(ProviderInterfaceTest, finish_download_unknown) | 422 | TEST_F(ProviderInterfaceTest, finish_download_unknown) |
335 | 468 | { | 423 | { |
337 | 469 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 424 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
338 | 470 | 425 | ||
339 | 471 | auto reply = client_->FinishDownload("no-such-download"); | 426 | auto reply = client_->FinishDownload("no-such-download"); |
340 | 472 | wait_for(reply); | 427 | wait_for(reply); |
341 | @@ -477,7 +432,7 @@ | |||
342 | 477 | 432 | ||
343 | 478 | TEST_F(ProviderInterfaceTest, delete_) | 433 | TEST_F(ProviderInterfaceTest, delete_) |
344 | 479 | { | 434 | { |
346 | 480 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 435 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
347 | 481 | 436 | ||
348 | 482 | auto reply = client_->Delete("item_id"); | 437 | auto reply = client_->Delete("item_id"); |
349 | 483 | wait_for(reply); | 438 | wait_for(reply); |
350 | @@ -486,7 +441,7 @@ | |||
351 | 486 | 441 | ||
352 | 487 | TEST_F(ProviderInterfaceTest, move) | 442 | TEST_F(ProviderInterfaceTest, move) |
353 | 488 | { | 443 | { |
355 | 489 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 444 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
356 | 490 | 445 | ||
357 | 491 | auto reply = client_->Move("child_id", "new_parent_id", "New name"); | 446 | auto reply = client_->Move("child_id", "new_parent_id", "New name"); |
358 | 492 | wait_for(reply); | 447 | wait_for(reply); |
359 | @@ -500,7 +455,7 @@ | |||
360 | 500 | 455 | ||
361 | 501 | TEST_F(ProviderInterfaceTest, copy) | 456 | TEST_F(ProviderInterfaceTest, copy) |
362 | 502 | { | 457 | { |
364 | 503 | make_provider(unique_ptr<ProviderBase>(new TestProvider)); | 458 | set_provider(unique_ptr<ProviderBase>(new TestProvider)); |
365 | 504 | 459 | ||
366 | 505 | auto reply = client_->Copy("child_id", "new_parent_id", "New name"); | 460 | auto reply = client_->Copy("child_id", "new_parent_id", "New name"); |
367 | 506 | wait_for(reply); | 461 | wait_for(reply); |
368 | 507 | 462 | ||
369 | === modified file 'tests/remote-client/CMakeLists.txt' | |||
370 | --- tests/remote-client/CMakeLists.txt 2016-08-11 04:07:55 +0000 | |||
371 | +++ tests/remote-client/CMakeLists.txt 2016-08-23 01:48:44 +0000 | |||
372 | @@ -1,10 +1,11 @@ | |||
374 | 1 | add_executable(remote-client_test remote-client_test.cpp) | 1 | add_executable(remote-client_test remote-client_test.cpp MockProvider.cpp) |
375 | 2 | set_target_properties(remote-client_test PROPERTIES AUTOMOC TRUE) | 2 | set_target_properties(remote-client_test PROPERTIES AUTOMOC TRUE) |
376 | 3 | 3 | ||
378 | 4 | add_definitions(-DTEST_DIR="${CMAKE_CURRENT_BINARY_DIR}") | 4 | add_definitions(-DTEST_DIR="${CMAKE_CURRENT_BINARY_DIR}" -DBOOST_THREAD_VERSION=4) |
379 | 5 | include_directories(${GLIB_DEPS_INCLUDE_DIRS}) | 5 | include_directories(${GLIB_DEPS_INCLUDE_DIRS}) |
380 | 6 | 6 | ||
381 | 7 | target_link_libraries(remote-client_test | 7 | target_link_libraries(remote-client_test |
382 | 8 | storage-framework-provider | ||
383 | 8 | storage-framework-qt-client | 9 | storage-framework-qt-client |
384 | 9 | Qt5::Network | 10 | Qt5::Network |
385 | 10 | Qt5::Test | 11 | Qt5::Test |
386 | 11 | 12 | ||
387 | === added file 'tests/remote-client/MockProvider.cpp' | |||
388 | --- tests/remote-client/MockProvider.cpp 1970-01-01 00:00:00 +0000 | |||
389 | +++ tests/remote-client/MockProvider.cpp 2016-08-23 01:48:44 +0000 | |||
390 | @@ -0,0 +1,236 @@ | |||
391 | 1 | /* | ||
392 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
393 | 3 | * | ||
394 | 4 | * This program is free software: you can redistribute it and/or modify | ||
395 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
396 | 6 | * published by the Free Software Foundation. | ||
397 | 7 | * | ||
398 | 8 | * This program is distributed in the hope that it will be useful, | ||
399 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
400 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
401 | 11 | * GNU Lesser General Public License for more details. | ||
402 | 12 | * | ||
403 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
404 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
405 | 15 | * | ||
406 | 16 | * Authors: Michi Henning <michi.henning@canonical.com> | ||
407 | 17 | */ | ||
408 | 18 | |||
409 | 19 | #include "MockProvider.h" | ||
410 | 20 | |||
411 | 21 | #include <unity/storage/provider/Exceptions.h> | ||
412 | 22 | #include <unity/storage/provider/metadata_keys.h> | ||
413 | 23 | |||
414 | 24 | #include <boost/thread.hpp> | ||
415 | 25 | #include <boost/thread/future.hpp> | ||
416 | 26 | |||
417 | 27 | #include <chrono> | ||
418 | 28 | #include <thread> | ||
419 | 29 | #include <inttypes.h> | ||
420 | 30 | |||
421 | 31 | using namespace unity::storage; | ||
422 | 32 | using namespace unity::storage::provider; | ||
423 | 33 | using namespace std; | ||
424 | 34 | |||
425 | 35 | using boost::make_exceptional_future; | ||
426 | 36 | using boost::make_ready_future; | ||
427 | 37 | |||
428 | 38 | MockProvider::MockProvider() | ||
429 | 39 | { | ||
430 | 40 | } | ||
431 | 41 | |||
432 | 42 | MockProvider::MockProvider(string const& cmd) | ||
433 | 43 | : cmd_(cmd) | ||
434 | 44 | { | ||
435 | 45 | } | ||
436 | 46 | |||
437 | 47 | boost::future<ItemList> MockProvider::roots(Context const&) | ||
438 | 48 | { | ||
439 | 49 | ItemList roots = | ||
440 | 50 | { | ||
441 | 51 | {"root_id", {}, "Root", "etag", ItemType::root, {}} | ||
442 | 52 | }; | ||
443 | 53 | return make_ready_future<ItemList>(roots); | ||
444 | 54 | } | ||
445 | 55 | |||
446 | 56 | boost::future<tuple<ItemList,string>> MockProvider::list( | ||
447 | 57 | string const& item_id, string const& page_token, | ||
448 | 58 | Context const&) | ||
449 | 59 | { | ||
450 | 60 | if (item_id != "root_id") | ||
451 | 61 | { | ||
452 | 62 | string msg = string("Item::list(): no such item: \"") + item_id + "\""; | ||
453 | 63 | return make_exceptional_future<tuple<ItemList,string>>(NotExistsException(msg, item_id)); | ||
454 | 64 | } | ||
455 | 65 | if (page_token != "") | ||
456 | 66 | { | ||
457 | 67 | string msg = string("Item::list(): invalid page token: \"") + page_token + "\""; | ||
458 | 68 | return make_exceptional_future<tuple<ItemList,string>>(LogicException("invalid page token")); | ||
459 | 69 | } | ||
460 | 70 | ItemList children = | ||
461 | 71 | { | ||
462 | 72 | { | ||
463 | 73 | "child_id", { "root_id" }, "Child", "etag", ItemType::file, | ||
464 | 74 | { { SIZE_IN_BYTES, 0 }, { LAST_MODIFIED_TIME, "2007-04-05T14:30Z" } } | ||
465 | 75 | } | ||
466 | 76 | }; | ||
467 | 77 | boost::promise<tuple<ItemList,string>> p; | ||
468 | 78 | p.set_value(make_tuple(children, string())); | ||
469 | 79 | return p.get_future(); | ||
470 | 80 | } | ||
471 | 81 | |||
472 | 82 | boost::future<ItemList> MockProvider::lookup( | ||
473 | 83 | string const& parent_id, string const& name, Context const&) | ||
474 | 84 | { | ||
475 | 85 | if (parent_id != "root_id") | ||
476 | 86 | { | ||
477 | 87 | string msg = string("Folder::lookup(): no such item: \"") + parent_id + "\""; | ||
478 | 88 | return make_exceptional_future<ItemList>(NotExistsException(msg, parent_id)); | ||
479 | 89 | } | ||
480 | 90 | if (name != "Child") | ||
481 | 91 | { | ||
482 | 92 | string msg = string("Folder::lookup(): no such item: \"") + name + "\""; | ||
483 | 93 | return make_exceptional_future<ItemList>(NotExistsException(msg, name)); | ||
484 | 94 | } | ||
485 | 95 | ItemList children = | ||
486 | 96 | { | ||
487 | 97 | { "child_id", { "root_id" }, "Child", "etag", ItemType::file, | ||
488 | 98 | { { SIZE_IN_BYTES, 0 }, { LAST_MODIFIED_TIME, "2007-04-05T14:30Z" } } } | ||
489 | 99 | }; | ||
490 | 100 | return make_ready_future<ItemList>(children); | ||
491 | 101 | } | ||
492 | 102 | |||
493 | 103 | boost::future<Item> MockProvider::metadata(string const& item_id, Context const&) | ||
494 | 104 | { | ||
495 | 105 | if (item_id == "root_id") | ||
496 | 106 | { | ||
497 | 107 | Item metadata{"root_id", {}, "Root", "etag", ItemType::root, {}}; | ||
498 | 108 | return make_ready_future<Item>(metadata); | ||
499 | 109 | } | ||
500 | 110 | else if (item_id == "child_id") | ||
501 | 111 | { | ||
502 | 112 | Item metadata | ||
503 | 113 | { | ||
504 | 114 | "child_id", { "root_id" }, "Child", "etag", ItemType::file, | ||
505 | 115 | { { SIZE_IN_BYTES, 0 }, { LAST_MODIFIED_TIME, "2007-04-05T14:30Z" } } | ||
506 | 116 | }; | ||
507 | 117 | return make_ready_future<Item>(metadata); | ||
508 | 118 | } | ||
509 | 119 | else if (item_id == "child_folder_id") | ||
510 | 120 | { | ||
511 | 121 | Item metadata{"child_folder_id", { "root_id" }, "Child_Folder", "etag", ItemType::folder, {}}; | ||
512 | 122 | return make_ready_future<Item>(metadata); | ||
513 | 123 | } | ||
514 | 124 | return make_exceptional_future<Item>(NotExistsException("metadata(): no such item: " + item_id, item_id)); | ||
515 | 125 | } | ||
516 | 126 | |||
517 | 127 | boost::future<Item> MockProvider::create_folder( | ||
518 | 128 | string const& parent_id, string const& name, | ||
519 | 129 | Context const&) | ||
520 | 130 | { | ||
521 | 131 | Item metadata{"new_folder_id", { parent_id }, name, "etag", ItemType::folder, {}}; | ||
522 | 132 | return make_ready_future<Item>(metadata); | ||
523 | 133 | } | ||
524 | 134 | |||
525 | 135 | string make_job_id() | ||
526 | 136 | { | ||
527 | 137 | static int last_job_id = 0; | ||
528 | 138 | return to_string(++last_job_id); | ||
529 | 139 | } | ||
530 | 140 | |||
531 | 141 | boost::future<unique_ptr<UploadJob>> MockProvider::create_file( | ||
532 | 142 | string const&, string const&, | ||
533 | 143 | int64_t, string const&, bool, Context const&) | ||
534 | 144 | { | ||
535 | 145 | return make_ready_future<unique_ptr<UploadJob>>(new MockUploadJob(make_job_id())); | ||
536 | 146 | } | ||
537 | 147 | |||
538 | 148 | boost::future<unique_ptr<UploadJob>> MockProvider::update( | ||
539 | 149 | string const&, int64_t, string const&, Context const&) | ||
540 | 150 | { | ||
541 | 151 | return make_ready_future<unique_ptr<UploadJob>>(new MockUploadJob(make_job_id())); | ||
542 | 152 | } | ||
543 | 153 | |||
544 | 154 | boost::future<unique_ptr<DownloadJob>> MockProvider::download( | ||
545 | 155 | string const&, Context const&) | ||
546 | 156 | { | ||
547 | 157 | unique_ptr<DownloadJob> job(new MockDownloadJob(make_job_id())); | ||
548 | 158 | const char contents[] = "Hello world"; | ||
549 | 159 | if (write(job->write_socket(), contents, sizeof(contents)) != sizeof(contents)) | ||
550 | 160 | { | ||
551 | 161 | ResourceException e("download(): write failed", errno); | ||
552 | 162 | job->report_error(make_exception_ptr(e)); | ||
553 | 163 | return make_exceptional_future<unique_ptr<DownloadJob>>(e); | ||
554 | 164 | } | ||
555 | 165 | job->report_complete(); | ||
556 | 166 | return make_ready_future(std::move(job)); | ||
557 | 167 | } | ||
558 | 168 | |||
559 | 169 | boost::future<void> MockProvider::delete_item( | ||
560 | 170 | string const&, Context const&) | ||
561 | 171 | { | ||
562 | 172 | return make_ready_future(); | ||
563 | 173 | } | ||
564 | 174 | |||
565 | 175 | boost::future<Item> MockProvider::move( | ||
566 | 176 | string const& item_id, string const& new_parent_id, | ||
567 | 177 | string const& new_name, Context const&) | ||
568 | 178 | { | ||
569 | 179 | Item metadata{item_id, { new_parent_id }, new_name, "etag", ItemType::file, {}}; | ||
570 | 180 | return make_ready_future(metadata); | ||
571 | 181 | } | ||
572 | 182 | |||
573 | 183 | boost::future<Item> MockProvider::copy( | ||
574 | 184 | string const&, string const& new_parent_id, | ||
575 | 185 | string const& new_name, Context const&) | ||
576 | 186 | { | ||
577 | 187 | Item metadata{"new_item_id", { new_parent_id }, new_name, "etag", ItemType::file, {}}; | ||
578 | 188 | return make_ready_future(metadata); | ||
579 | 189 | } | ||
580 | 190 | |||
581 | 191 | MockUploadJob::MockUploadJob() | ||
582 | 192 | : UploadJob("some_id") | ||
583 | 193 | { | ||
584 | 194 | } | ||
585 | 195 | |||
586 | 196 | MockUploadJob::MockUploadJob(string const& cmd) | ||
587 | 197 | : UploadJob("some_id") | ||
588 | 198 | , cmd_(cmd) | ||
589 | 199 | { | ||
590 | 200 | } | ||
591 | 201 | |||
592 | 202 | boost::future<void> MockUploadJob::cancel() | ||
593 | 203 | { | ||
594 | 204 | return make_ready_future(); | ||
595 | 205 | } | ||
596 | 206 | |||
597 | 207 | boost::future<Item> MockUploadJob::finish() | ||
598 | 208 | { | ||
599 | 209 | Item metadata | ||
600 | 210 | { | ||
601 | 211 | "some_id", { "root_id" }, "some_upload", "etag", ItemType::file, | ||
602 | 212 | { { SIZE_IN_BYTES, 10 }, { LAST_MODIFIED_TIME, "2011-04-05T14:30:10.005Z" } } | ||
603 | 213 | }; | ||
604 | 214 | return make_ready_future(metadata); | ||
605 | 215 | } | ||
606 | 216 | |||
607 | 217 | MockDownloadJob::MockDownloadJob() | ||
608 | 218 | : DownloadJob("some_id") | ||
609 | 219 | { | ||
610 | 220 | } | ||
611 | 221 | |||
612 | 222 | MockDownloadJob::MockDownloadJob(string const& cmd) | ||
613 | 223 | : DownloadJob("some_id") | ||
614 | 224 | , cmd_(cmd) | ||
615 | 225 | { | ||
616 | 226 | } | ||
617 | 227 | |||
618 | 228 | boost::future<void> MockDownloadJob::cancel() | ||
619 | 229 | { | ||
620 | 230 | return make_ready_future(); | ||
621 | 231 | } | ||
622 | 232 | |||
623 | 233 | boost::future<void> MockDownloadJob::finish() | ||
624 | 234 | { | ||
625 | 235 | return make_ready_future(); | ||
626 | 236 | } | ||
627 | 0 | 237 | ||
628 | === added file 'tests/remote-client/MockProvider.h' | |||
629 | --- tests/remote-client/MockProvider.h 1970-01-01 00:00:00 +0000 | |||
630 | +++ tests/remote-client/MockProvider.h 2016-08-23 01:48:44 +0000 | |||
631 | @@ -0,0 +1,96 @@ | |||
632 | 1 | /* | ||
633 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
634 | 3 | * | ||
635 | 4 | * This program is free software: you can redistribute it and/or modify | ||
636 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
637 | 6 | * published by the Free Software Foundation. | ||
638 | 7 | * | ||
639 | 8 | * This program is distributed in the hope that it will be useful, | ||
640 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
641 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
642 | 11 | * GNU Lesser General Public License for more details. | ||
643 | 12 | * | ||
644 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
645 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
646 | 15 | * | ||
647 | 16 | * Authors: Michi Henning <michi.henning@canonical.com> | ||
648 | 17 | */ | ||
649 | 18 | |||
650 | 19 | #pragma once | ||
651 | 20 | |||
652 | 21 | #include <unity/storage/provider/DownloadJob.h> | ||
653 | 22 | #include <unity/storage/provider/ProviderBase.h> | ||
654 | 23 | #include <unity/storage/provider/UploadJob.h> | ||
655 | 24 | |||
656 | 25 | class MockProvider : public unity::storage::provider::ProviderBase | ||
657 | 26 | { | ||
658 | 27 | public: | ||
659 | 28 | MockProvider(); | ||
660 | 29 | MockProvider(std::string const& cmd); | ||
661 | 30 | |||
662 | 31 | boost::future<unity::storage::provider::ItemList> roots(unity::storage::provider::Context const& ctx) override; | ||
663 | 32 | boost::future<std::tuple<unity::storage::provider::ItemList, std::string>> list( | ||
664 | 33 | std::string const& item_id, std::string const& page_token, | ||
665 | 34 | unity::storage::provider::Context const& ctx) override; | ||
666 | 35 | boost::future<unity::storage::provider::ItemList> lookup( | ||
667 | 36 | std::string const& parent_id, std::string const& name, | ||
668 | 37 | unity::storage::provider::Context const& ctx) override; | ||
669 | 38 | boost::future<unity::storage::provider::Item> metadata( | ||
670 | 39 | std::string const& item_id, unity::storage::provider::Context const& ctx) override; | ||
671 | 40 | boost::future<unity::storage::provider::Item> create_folder( | ||
672 | 41 | std::string const& parent_id, std::string const& name, | ||
673 | 42 | unity::storage::provider::Context const& ctx) override; | ||
674 | 43 | |||
675 | 44 | boost::future<std::unique_ptr<unity::storage::provider::UploadJob>> create_file( | ||
676 | 45 | std::string const& parent_id, std::string const& name, | ||
677 | 46 | int64_t size, std::string const& content_type, bool allow_overwrite, | ||
678 | 47 | unity::storage::provider::Context const& ctx) override; | ||
679 | 48 | boost::future<std::unique_ptr<unity::storage::provider::UploadJob>> update( | ||
680 | 49 | std::string const& item_id, int64_t size, std::string const& old_etag, | ||
681 | 50 | unity::storage::provider::Context const& ctx) override; | ||
682 | 51 | |||
683 | 52 | boost::future<std::unique_ptr<unity::storage::provider::DownloadJob>> download( | ||
684 | 53 | std::string const& item_id, unity::storage::provider::Context const& ctx) override; | ||
685 | 54 | |||
686 | 55 | boost::future<void> delete_item( | ||
687 | 56 | std::string const& item_id, unity::storage::provider::Context const& ctx) override; | ||
688 | 57 | boost::future<unity::storage::provider::Item> move( | ||
689 | 58 | std::string const& item_id, std::string const& new_parent_id, | ||
690 | 59 | std::string const& new_name, unity::storage::provider::Context const& ctx) override; | ||
691 | 60 | boost::future<unity::storage::provider::Item> copy( | ||
692 | 61 | std::string const& item_id, std::string const& new_parent_id, | ||
693 | 62 | std::string const& new_name, unity::storage::provider::Context const& ctx) override; | ||
694 | 63 | |||
695 | 64 | private: | ||
696 | 65 | std::string cmd_; | ||
697 | 66 | }; | ||
698 | 67 | |||
699 | 68 | class MockUploadJob : public unity::storage::provider::UploadJob | ||
700 | 69 | { | ||
701 | 70 | public: | ||
702 | 71 | using UploadJob::UploadJob; | ||
703 | 72 | |||
704 | 73 | MockUploadJob(); | ||
705 | 74 | MockUploadJob(std::string const& cmd); | ||
706 | 75 | |||
707 | 76 | boost::future<void> cancel() override; | ||
708 | 77 | boost::future<unity::storage::provider::Item> finish() override; | ||
709 | 78 | |||
710 | 79 | private: | ||
711 | 80 | std::string cmd_; | ||
712 | 81 | }; | ||
713 | 82 | |||
714 | 83 | class MockDownloadJob : public unity::storage::provider::DownloadJob | ||
715 | 84 | { | ||
716 | 85 | public: | ||
717 | 86 | using DownloadJob::DownloadJob; | ||
718 | 87 | |||
719 | 88 | MockDownloadJob(); | ||
720 | 89 | MockDownloadJob(const std::string& cmd); | ||
721 | 90 | |||
722 | 91 | boost::future<void> cancel() override; | ||
723 | 92 | boost::future<void> finish() override; | ||
724 | 93 | |||
725 | 94 | private: | ||
726 | 95 | std::string cmd_; | ||
727 | 96 | }; | ||
728 | 0 | 97 | ||
729 | === modified file 'tests/remote-client/remote-client_test.cpp' | |||
730 | --- tests/remote-client/remote-client_test.cpp 2016-08-19 03:16:52 +0000 | |||
731 | +++ tests/remote-client/remote-client_test.cpp 2016-08-23 01:48:44 +0000 | |||
732 | @@ -19,6 +19,8 @@ | |||
733 | 19 | #include <unity/storage/qt/client/client-api.h> | 19 | #include <unity/storage/qt/client/client-api.h> |
734 | 20 | 20 | ||
735 | 21 | #include <utils/DBusEnvironment.h> | 21 | #include <utils/DBusEnvironment.h> |
736 | 22 | #include <utils/ProviderFixture.h> | ||
737 | 23 | #include <MockProvider.h> | ||
738 | 22 | 24 | ||
739 | 23 | #include <gtest/gtest.h> | 25 | #include <gtest/gtest.h> |
740 | 24 | #include <QCoreApplication> | 26 | #include <QCoreApplication> |
741 | @@ -71,37 +73,64 @@ | |||
742 | 71 | class FileTest : public RemoteClientTest {}; | 73 | class FileTest : public RemoteClientTest {}; |
743 | 72 | class ItemTest : public RemoteClientTest {}; | 74 | class ItemTest : public RemoteClientTest {}; |
744 | 73 | 75 | ||
745 | 76 | class DestroyedTest : public ProviderFixture | ||
746 | 77 | { | ||
747 | 78 | protected: | ||
748 | 79 | void SetUp() override | ||
749 | 80 | { | ||
750 | 81 | runtime_ = Runtime::create(connection()); | ||
751 | 82 | acc_ = runtime_->make_test_account(service_connection_->baseService(), bus_path()); | ||
752 | 83 | } | ||
753 | 84 | |||
754 | 85 | void TearDown() override | ||
755 | 86 | { | ||
756 | 87 | } | ||
757 | 88 | |||
758 | 89 | Runtime::SPtr runtime_; | ||
759 | 90 | Account::SPtr acc_; | ||
760 | 91 | }; | ||
761 | 92 | |||
762 | 74 | // Bunch of helper functions to reduce the amount of noise in the tests. | 93 | // Bunch of helper functions to reduce the amount of noise in the tests. |
763 | 75 | 94 | ||
764 | 76 | template<typename T> | 95 | template<typename T> |
766 | 77 | void wait(T fut) | 96 | bool wait(T fut) |
767 | 78 | { | 97 | { |
768 | 79 | QFutureWatcher<decltype(fut.result())> w; | 98 | QFutureWatcher<decltype(fut.result())> w; |
769 | 80 | QSignalSpy spy(&w, &decltype(w)::finished); | 99 | QSignalSpy spy(&w, &decltype(w)::finished); |
770 | 81 | w.setFuture(fut); | 100 | w.setFuture(fut); |
772 | 82 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | 101 | bool rc = spy.wait(SIGNAL_WAIT_TIME); |
773 | 102 | EXPECT_TRUE(rc); | ||
774 | 103 | return rc; | ||
775 | 83 | } | 104 | } |
776 | 84 | 105 | ||
777 | 85 | template<> | 106 | template<> |
779 | 86 | void wait(QFuture<void> fut) | 107 | bool wait(QFuture<void> fut) |
780 | 87 | { | 108 | { |
781 | 88 | QFutureWatcher<void> w; | 109 | QFutureWatcher<void> w; |
782 | 89 | QSignalSpy spy(&w, &decltype(w)::finished); | 110 | QSignalSpy spy(&w, &decltype(w)::finished); |
783 | 90 | w.setFuture(fut); | 111 | w.setFuture(fut); |
785 | 91 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | 112 | bool rc = spy.wait(SIGNAL_WAIT_TIME); |
786 | 113 | EXPECT_TRUE(rc); | ||
787 | 114 | return rc; | ||
788 | 92 | } | 115 | } |
789 | 93 | 116 | ||
790 | 94 | template <typename T> | 117 | template <typename T> |
791 | 95 | T call(QFuture<T> fut) | 118 | T call(QFuture<T> fut) |
792 | 96 | { | 119 | { |
794 | 97 | wait(fut); | 120 | if (!wait(fut)) |
795 | 121 | { | ||
796 | 122 | throw runtime_error("call timed out"); | ||
797 | 123 | } | ||
798 | 98 | return fut.result(); | 124 | return fut.result(); |
799 | 99 | } | 125 | } |
800 | 100 | 126 | ||
801 | 101 | template <> | 127 | template <> |
802 | 102 | void call(QFuture<void> fut) | 128 | void call(QFuture<void> fut) |
803 | 103 | { | 129 | { |
805 | 104 | wait(fut); | 130 | if (!wait(fut)) |
806 | 131 | { | ||
807 | 132 | throw runtime_error("call timed out"); | ||
808 | 133 | } | ||
809 | 105 | fut.waitForFinished(); | 134 | fut.waitForFinished(); |
810 | 106 | } | 135 | } |
811 | 107 | 136 | ||
812 | @@ -114,7 +143,14 @@ | |||
813 | 114 | qCritical() << "Configure at least one online account for a provider in System Settings -> Online Accounts"; | 143 | qCritical() << "Configure at least one online account for a provider in System Settings -> Online Accounts"; |
814 | 115 | return nullptr; | 144 | return nullptr; |
815 | 116 | } | 145 | } |
817 | 117 | return accounts[0]; | 146 | for (auto acc : accounts) |
818 | 147 | { | ||
819 | 148 | if (acc->owner_id() == "google-drive-scope") | ||
820 | 149 | { | ||
821 | 150 | return acc; | ||
822 | 151 | } | ||
823 | 152 | } | ||
824 | 153 | abort(); // Impossible | ||
825 | 118 | } | 154 | } |
826 | 119 | 155 | ||
827 | 120 | Root::SPtr get_root(Runtime::SPtr const& runtime) | 156 | Root::SPtr get_root(Runtime::SPtr const& runtime) |
828 | @@ -139,7 +175,7 @@ | |||
829 | 139 | assert(items.size() != 0); // TODO: temporary hack for use with demo provider | 175 | assert(items.size() != 0); // TODO: temporary hack for use with demo provider |
830 | 140 | for (auto i : items) | 176 | for (auto i : items) |
831 | 141 | { | 177 | { |
833 | 142 | wait(i->delete_item()); | 178 | call(i->delete_item()); |
834 | 143 | } | 179 | } |
835 | 144 | } | 180 | } |
836 | 145 | 181 | ||
837 | @@ -282,7 +318,7 @@ | |||
838 | 282 | 318 | ||
839 | 283 | TEST_F(RuntimeTest, runtime_destroyed_exceptions) | 319 | TEST_F(RuntimeTest, runtime_destroyed_exceptions) |
840 | 284 | { | 320 | { |
842 | 285 | // Gettting an account after shutting down the runtime must fail. | 321 | // Getting the runtime from an account after shutting down the runtime must fail. |
843 | 286 | { | 322 | { |
844 | 287 | auto runtime = Runtime::create(connection()); | 323 | auto runtime = Runtime::create(connection()); |
845 | 288 | auto acc = get_account(runtime); | 324 | auto acc = get_account(runtime); |
846 | @@ -298,7 +334,7 @@ | |||
847 | 298 | } | 334 | } |
848 | 299 | } | 335 | } |
849 | 300 | 336 | ||
851 | 301 | // Getting an account after destroying the runtime must fail. | 337 | // Getting the runtime from an account after destroying the runtime must fail. |
852 | 302 | { | 338 | { |
853 | 303 | auto runtime = Runtime::create(connection()); | 339 | auto runtime = Runtime::create(connection()); |
854 | 304 | auto acc = get_account(runtime); | 340 | auto acc = get_account(runtime); |
855 | @@ -329,6 +365,22 @@ | |||
856 | 329 | } | 365 | } |
857 | 330 | } | 366 | } |
858 | 331 | 367 | ||
859 | 368 | // Getting roots from an account after shutting down the runtime must fail. | ||
860 | 369 | { | ||
861 | 370 | auto runtime = Runtime::create(connection()); | ||
862 | 371 | auto acc = get_account(runtime); | ||
863 | 372 | runtime->shutdown(); | ||
864 | 373 | try | ||
865 | 374 | { | ||
866 | 375 | call(acc->roots()); | ||
867 | 376 | FAIL(); | ||
868 | 377 | } | ||
869 | 378 | catch (RuntimeDestroyedException const& e) | ||
870 | 379 | { | ||
871 | 380 | EXPECT_EQ("Account::roots(): runtime was destroyed previously", e.error_message()); | ||
872 | 381 | } | ||
873 | 382 | } | ||
874 | 383 | |||
875 | 332 | // Getting the account from a root with a destroyed runtime must fail. | 384 | // Getting the account from a root with a destroyed runtime must fail. |
876 | 333 | { | 385 | { |
877 | 334 | auto runtime = Runtime::create(connection()); | 386 | auto runtime = Runtime::create(connection()); |
878 | @@ -888,6 +940,198 @@ | |||
879 | 888 | } | 940 | } |
880 | 889 | } | 941 | } |
881 | 890 | 942 | ||
882 | 943 | TEST_F(DestroyedTest, roots_destroyed_while_reply_outstanding) | ||
883 | 944 | { | ||
884 | 945 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider)); | ||
885 | 946 | |||
886 | 947 | auto fut = acc_->roots(); | ||
887 | 948 | runtime_->shutdown(); | ||
888 | 949 | try | ||
889 | 950 | { | ||
890 | 951 | ASSERT_TRUE(wait(fut)); | ||
891 | 952 | fut.result(); | ||
892 | 953 | FAIL(); | ||
893 | 954 | } | ||
894 | 955 | catch (RuntimeDestroyedException const& e) | ||
895 | 956 | { | ||
896 | 957 | EXPECT_EQ("Account::roots(): runtime was destroyed previously", e.error_message()); | ||
897 | 958 | } | ||
898 | 959 | } | ||
899 | 960 | |||
900 | 961 | TEST_F(DestroyedTest, get_destroyed_while_reply_outstanding) | ||
901 | 962 | { | ||
902 | 963 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("metadata slow"))); | ||
903 | 964 | |||
904 | 965 | auto root = call(acc_->roots())[0]; | ||
905 | 966 | auto fut = root->get("root_id"); | ||
906 | 967 | runtime_->shutdown(); | ||
907 | 968 | try | ||
908 | 969 | { | ||
909 | 970 | ASSERT_TRUE(wait(fut)); | ||
910 | 971 | fut.result(); | ||
911 | 972 | FAIL(); | ||
912 | 973 | } | ||
913 | 974 | catch (RuntimeDestroyedException const& e) | ||
914 | 975 | { | ||
915 | 976 | EXPECT_EQ("Root::get(): runtime was destroyed previously", e.error_message()); | ||
916 | 977 | } | ||
917 | 978 | } | ||
918 | 979 | |||
919 | 980 | TEST_F(DestroyedTest, copy_destroyed_while_reply_outstanding) | ||
920 | 981 | { | ||
921 | 982 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | ||
922 | 983 | |||
923 | 984 | auto root = call(acc_->roots())[0]; | ||
924 | 985 | auto fut = root->copy(root, "new name"); | ||
925 | 986 | runtime_->shutdown(); | ||
926 | 987 | try | ||
927 | 988 | { | ||
928 | 989 | ASSERT_TRUE(wait(fut)); | ||
929 | 990 | fut.result(); | ||
930 | 991 | FAIL(); | ||
931 | 992 | } | ||
932 | 993 | catch (RuntimeDestroyedException const& e) | ||
933 | 994 | { | ||
934 | 995 | EXPECT_EQ("Item::copy(): runtime was destroyed previously", e.error_message()); | ||
935 | 996 | } | ||
936 | 997 | } | ||
937 | 998 | |||
938 | 999 | TEST_F(DestroyedTest, move_destroyed_while_reply_outstanding) | ||
939 | 1000 | { | ||
940 | 1001 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("move slow"))); | ||
941 | 1002 | |||
942 | 1003 | auto root = call(acc_->roots())[0]; | ||
943 | 1004 | auto file = dynamic_pointer_cast<File>(call(root->get("child_id"))); | ||
944 | 1005 | auto fut = file->move(root, "new name"); | ||
945 | 1006 | runtime_->shutdown(); | ||
946 | 1007 | try | ||
947 | 1008 | { | ||
948 | 1009 | ASSERT_TRUE(wait(fut)); | ||
949 | 1010 | fut.result(); | ||
950 | 1011 | FAIL(); | ||
951 | 1012 | } | ||
952 | 1013 | catch (RuntimeDestroyedException const& e) | ||
953 | 1014 | { | ||
954 | 1015 | EXPECT_EQ("Item::move(): runtime was destroyed previously", e.error_message()); | ||
955 | 1016 | } | ||
956 | 1017 | } | ||
957 | 1018 | |||
958 | 1019 | TEST_F(DestroyedTest, list_destroyed_while_reply_outstanding) | ||
959 | 1020 | { | ||
960 | 1021 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("list slow"))); | ||
961 | 1022 | |||
962 | 1023 | auto root = call(acc_->roots())[0]; | ||
963 | 1024 | auto fut = root->list(); | ||
964 | 1025 | runtime_->shutdown(); | ||
965 | 1026 | try | ||
966 | 1027 | { | ||
967 | 1028 | ASSERT_TRUE(wait(fut)); | ||
968 | 1029 | fut.result(); | ||
969 | 1030 | FAIL(); | ||
970 | 1031 | } | ||
971 | 1032 | catch (RuntimeDestroyedException const& e) | ||
972 | 1033 | { | ||
973 | 1034 | EXPECT_EQ("Folder::list(): runtime was destroyed previously", e.error_message()); | ||
974 | 1035 | } | ||
975 | 1036 | } | ||
976 | 1037 | |||
977 | 1038 | TEST_F(DestroyedTest, lookup_destroyed_while_reply_outstanding) | ||
978 | 1039 | { | ||
979 | 1040 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("lookup slow"))); | ||
980 | 1041 | |||
981 | 1042 | auto root = call(acc_->roots())[0]; | ||
982 | 1043 | auto fut = root->lookup("Child"); | ||
983 | 1044 | runtime_->shutdown(); | ||
984 | 1045 | try | ||
985 | 1046 | { | ||
986 | 1047 | ASSERT_TRUE(wait(fut)); | ||
987 | 1048 | fut.result(); | ||
988 | 1049 | FAIL(); | ||
989 | 1050 | } | ||
990 | 1051 | catch (RuntimeDestroyedException const& e) | ||
991 | 1052 | { | ||
992 | 1053 | EXPECT_EQ("Folder::lookup(): runtime was destroyed previously", e.error_message()); | ||
993 | 1054 | } | ||
994 | 1055 | } | ||
995 | 1056 | |||
996 | 1057 | TEST_F(DestroyedTest, create_folder_destroyed_while_reply_outstanding) | ||
997 | 1058 | { | ||
998 | 1059 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("create_folder slow"))); | ||
999 | 1060 | |||
1000 | 1061 | auto root = call(acc_->roots())[0]; | ||
1001 | 1062 | auto fut = root->create_folder("Child"); | ||
1002 | 1063 | runtime_->shutdown(); | ||
1003 | 1064 | try | ||
1004 | 1065 | { | ||
1005 | 1066 | ASSERT_TRUE(wait(fut)); | ||
1006 | 1067 | fut.result(); | ||
1007 | 1068 | FAIL(); | ||
1008 | 1069 | } | ||
1009 | 1070 | catch (RuntimeDestroyedException const& e) | ||
1010 | 1071 | { | ||
1011 | 1072 | EXPECT_EQ("Folder::create_folder(): runtime was destroyed previously", e.error_message()); | ||
1012 | 1073 | } | ||
1013 | 1074 | } | ||
1014 | 1075 | |||
1015 | 1076 | TEST_F(DestroyedTest, create_file_destroyed_while_reply_outstanding) | ||
1016 | 1077 | { | ||
1017 | 1078 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("create_file slow"))); | ||
1018 | 1079 | |||
1019 | 1080 | auto root = call(acc_->roots())[0]; | ||
1020 | 1081 | auto fut = root->create_file("Child", 0); | ||
1021 | 1082 | runtime_->shutdown(); | ||
1022 | 1083 | try | ||
1023 | 1084 | { | ||
1024 | 1085 | ASSERT_TRUE(wait(fut)); | ||
1025 | 1086 | fut.result(); | ||
1026 | 1087 | FAIL(); | ||
1027 | 1088 | } | ||
1028 | 1089 | catch (RuntimeDestroyedException const& e) | ||
1029 | 1090 | { | ||
1030 | 1091 | EXPECT_EQ("Folder::create_file(): runtime was destroyed previously", e.error_message()); | ||
1031 | 1092 | } | ||
1032 | 1093 | } | ||
1033 | 1094 | |||
1034 | 1095 | TEST_F(DestroyedTest, create_uploader_destroyed_while_reply_outstanding) | ||
1035 | 1096 | { | ||
1036 | 1097 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("create_file slow"))); | ||
1037 | 1098 | |||
1038 | 1099 | auto root = call(acc_->roots())[0]; | ||
1039 | 1100 | auto file = dynamic_pointer_cast<File>(call(root->get("child_id"))); | ||
1040 | 1101 | auto fut = file->create_uploader(ConflictPolicy::overwrite, 0); | ||
1041 | 1102 | runtime_->shutdown(); | ||
1042 | 1103 | try | ||
1043 | 1104 | { | ||
1044 | 1105 | ASSERT_TRUE(wait(fut)); | ||
1045 | 1106 | fut.result(); | ||
1046 | 1107 | FAIL(); | ||
1047 | 1108 | } | ||
1048 | 1109 | catch (RuntimeDestroyedException const& e) | ||
1049 | 1110 | { | ||
1050 | 1111 | EXPECT_EQ("File::create_uploader(): runtime was destroyed previously", e.error_message()); | ||
1051 | 1112 | } | ||
1052 | 1113 | } | ||
1053 | 1114 | |||
1054 | 1115 | TEST_F(DestroyedTest, create_downloader_destroyed_while_reply_outstanding) | ||
1055 | 1116 | { | ||
1056 | 1117 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("create_file slow"))); | ||
1057 | 1118 | |||
1058 | 1119 | auto root = call(acc_->roots())[0]; | ||
1059 | 1120 | auto file = dynamic_pointer_cast<File>(call(root->get("child_id"))); | ||
1060 | 1121 | auto fut = file->create_downloader(); | ||
1061 | 1122 | runtime_->shutdown(); | ||
1062 | 1123 | try | ||
1063 | 1124 | { | ||
1064 | 1125 | ASSERT_TRUE(wait(fut)); | ||
1065 | 1126 | fut.result(); | ||
1066 | 1127 | FAIL(); | ||
1067 | 1128 | } | ||
1068 | 1129 | catch (RuntimeDestroyedException const& e) | ||
1069 | 1130 | { | ||
1070 | 1131 | EXPECT_EQ("File::create_downloader(): runtime was destroyed previously", e.error_message()); | ||
1071 | 1132 | } | ||
1072 | 1133 | } | ||
1073 | 1134 | |||
1074 | 891 | int main(int argc, char** argv) | 1135 | int main(int argc, char** argv) |
1075 | 892 | { | 1136 | { |
1076 | 893 | QCoreApplication app(argc, argv); | 1137 | QCoreApplication app(argc, argv); |
1077 | 894 | 1138 | ||
1078 | === modified file 'tests/utils/CMakeLists.txt' | |||
1079 | --- tests/utils/CMakeLists.txt 2016-07-12 06:42:53 +0000 | |||
1080 | +++ tests/utils/CMakeLists.txt 2016-08-23 01:48:44 +0000 | |||
1081 | @@ -1,9 +1,23 @@ | |||
1082 | 1 | pkg_check_modules(QTDBUSTEST_DEPS libqtdbustest-1 REQUIRED) | 1 | pkg_check_modules(QTDBUSTEST_DEPS libqtdbustest-1 REQUIRED) |
1083 | 2 | 2 | ||
1084 | 3 | set_source_files_properties(${CMAKE_SOURCE_DIR}/data/provider.xml PROPERTIES | ||
1085 | 4 | CLASSNAME ProviderClient | ||
1086 | 5 | INCLUDE unity/storage/internal/dbusmarshal.h | ||
1087 | 6 | ) | ||
1088 | 7 | qt5_add_dbus_interface(generated_files | ||
1089 | 8 | ${CMAKE_SOURCE_DIR}/data/provider.xml | ||
1090 | 9 | ProviderClient | ||
1091 | 10 | ) | ||
1092 | 11 | set_source_files_properties(${generated_files} PROPERTIES GENERATED TRUE) | ||
1093 | 12 | |||
1094 | 3 | add_library(testutils STATIC | 13 | add_library(testutils STATIC |
1095 | 4 | DBusEnvironment.cpp | 14 | DBusEnvironment.cpp |
1096 | 15 | ProviderFixture.cpp | ||
1097 | 16 | ${generated_files} | ||
1098 | 5 | ) | 17 | ) |
1100 | 6 | target_compile_options(testutils PRIVATE ${QTDBUSTEST_DEPS_CFLAGS}) | 18 | target_compile_options(testutils PRIVATE ${QTDBUSTEST_DEPS_CFLAGS} ${ONLINEACCOUNTS_DEPS_CFLAGS}) |
1101 | 7 | target_link_libraries(testutils | 19 | target_link_libraries(testutils |
1102 | 8 | PUBLIC Qt5::DBus Qt5::Core | 20 | PUBLIC Qt5::DBus Qt5::Core |
1104 | 9 | PRIVATE ${QTDBUSTEST_DEPS_LIBRARIES}) | 21 | PRIVATE Qt5::Test ${QTDBUSTEST_DEPS_LIBRARIES} ${ONLINEAACOUNTS_DEPS_LIBRARIES}) |
1105 | 22 | |||
1106 | 23 | add_definitions(-DBOOST_THREAD_VERSION=4) | ||
1107 | 10 | 24 | ||
1108 | === added file 'tests/utils/ProviderFixture.cpp' | |||
1109 | --- tests/utils/ProviderFixture.cpp 1970-01-01 00:00:00 +0000 | |||
1110 | +++ tests/utils/ProviderFixture.cpp 2016-08-23 01:48:44 +0000 | |||
1111 | @@ -0,0 +1,79 @@ | |||
1112 | 1 | /* | ||
1113 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
1114 | 3 | * | ||
1115 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1116 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
1117 | 6 | * published by the Free Software Foundation. | ||
1118 | 7 | * | ||
1119 | 8 | * This program is distributed in the hope that it will be useful, | ||
1120 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1121 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1122 | 11 | * GNU Lesser General Public License for more details. | ||
1123 | 12 | * | ||
1124 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1125 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1126 | 15 | * | ||
1127 | 16 | * Authors: James Henstridge <james.henstridge@canonical.com> | ||
1128 | 17 | */ | ||
1129 | 18 | |||
1130 | 19 | #include "ProviderFixture.h" | ||
1131 | 20 | |||
1132 | 21 | #include <unity/storage/internal/dbus_error.h> | ||
1133 | 22 | |||
1134 | 23 | #include <QSignalSpy> | ||
1135 | 24 | |||
1136 | 25 | using namespace unity::storage::provider; | ||
1137 | 26 | using namespace std; | ||
1138 | 27 | |||
1139 | 28 | namespace | ||
1140 | 29 | { | ||
1141 | 30 | |||
1142 | 31 | const auto SERVICE_CONNECTION_NAME = QStringLiteral("service-session-bus"); | ||
1143 | 32 | const auto BUS_PATH = QStringLiteral("/provider"); | ||
1144 | 33 | |||
1145 | 34 | } // namespace | ||
1146 | 35 | |||
1147 | 36 | ProviderFixture::ProviderFixture() | ||
1148 | 37 | { | ||
1149 | 38 | dbus_.reset(new DBusEnvironment); | ||
1150 | 39 | dbus_->start_services(); | ||
1151 | 40 | service_connection_.reset(new QDBusConnection(QDBusConnection::connectToBus(dbus_->busAddress(), | ||
1152 | 41 | SERVICE_CONNECTION_NAME))); | ||
1153 | 42 | account_manager_.reset(new OnlineAccounts::Manager("", *service_connection_)); | ||
1154 | 43 | } | ||
1155 | 44 | |||
1156 | 45 | ProviderFixture::~ProviderFixture() | ||
1157 | 46 | { | ||
1158 | 47 | test_server_.reset(); | ||
1159 | 48 | service_connection_.reset(); | ||
1160 | 49 | QDBusConnection::disconnectFromBus(SERVICE_CONNECTION_NAME); | ||
1161 | 50 | dbus_.reset(); | ||
1162 | 51 | } | ||
1163 | 52 | |||
1164 | 53 | QDBusConnection const& ProviderFixture::connection() const | ||
1165 | 54 | { | ||
1166 | 55 | return dbus_->connection(); | ||
1167 | 56 | } | ||
1168 | 57 | |||
1169 | 58 | void ProviderFixture::set_provider(unique_ptr<ProviderBase>&& provider) | ||
1170 | 59 | { | ||
1171 | 60 | account_manager_->waitForReady(); | ||
1172 | 61 | OnlineAccounts::Account* account = account_manager_->account(2, "oauth2-service"); | ||
1173 | 62 | ASSERT_NE(nullptr, account); | ||
1174 | 63 | |||
1175 | 64 | test_server_.reset( | ||
1176 | 65 | new unity::storage::provider::testing::TestServer(move(provider), account, | ||
1177 | 66 | *service_connection_, BUS_PATH.toStdString())); | ||
1178 | 67 | } | ||
1179 | 68 | |||
1180 | 69 | void ProviderFixture::wait_for(QDBusPendingCall const& call) | ||
1181 | 70 | { | ||
1182 | 71 | QDBusPendingCallWatcher watcher(call); | ||
1183 | 72 | QSignalSpy spy(&watcher, &QDBusPendingCallWatcher::finished); | ||
1184 | 73 | ASSERT_TRUE(spy.wait()); | ||
1185 | 74 | } | ||
1186 | 75 | |||
1187 | 76 | QString ProviderFixture::bus_path() const | ||
1188 | 77 | { | ||
1189 | 78 | return BUS_PATH; | ||
1190 | 79 | } | ||
1191 | 0 | 80 | ||
1192 | === added file 'tests/utils/ProviderFixture.h' | |||
1193 | --- tests/utils/ProviderFixture.h 1970-01-01 00:00:00 +0000 | |||
1194 | +++ tests/utils/ProviderFixture.h 2016-08-23 01:48:44 +0000 | |||
1195 | @@ -0,0 +1,49 @@ | |||
1196 | 1 | /* | ||
1197 | 2 | * Copyright (C) 2016 Canonical Ltd | ||
1198 | 3 | * | ||
1199 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1200 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
1201 | 6 | * published by the Free Software Foundation. | ||
1202 | 7 | * | ||
1203 | 8 | * This program is distributed in the hope that it will be useful, | ||
1204 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1205 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1206 | 11 | * GNU Lesser General Public License for more details. | ||
1207 | 12 | * | ||
1208 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1209 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1210 | 15 | * | ||
1211 | 16 | * Authors: James Henstridge <james.henstridge@canonical.com> | ||
1212 | 17 | */ | ||
1213 | 18 | |||
1214 | 19 | #pragma once | ||
1215 | 20 | |||
1216 | 21 | #include <unity/storage/provider/ProviderBase.h> | ||
1217 | 22 | #include <unity/storage/provider/testing/TestServer.h> | ||
1218 | 23 | #include <utils/DBusEnvironment.h> | ||
1219 | 24 | #include <utils/ProviderClient.h> | ||
1220 | 25 | |||
1221 | 26 | #include <gtest/gtest.h> | ||
1222 | 27 | #include <OnlineAccounts/Account> | ||
1223 | 28 | #include <OnlineAccounts/Manager> | ||
1224 | 29 | #include <QDBusConnection> | ||
1225 | 30 | |||
1226 | 31 | #include <memory> | ||
1227 | 32 | |||
1228 | 33 | class ProviderFixture : public ::testing::Test | ||
1229 | 34 | { | ||
1230 | 35 | public: | ||
1231 | 36 | ProviderFixture(); | ||
1232 | 37 | virtual ~ProviderFixture(); | ||
1233 | 38 | |||
1234 | 39 | QDBusConnection const& connection() const; | ||
1235 | 40 | void set_provider(std::unique_ptr<unity::storage::provider::ProviderBase>&& provider); | ||
1236 | 41 | void wait_for(QDBusPendingCall const& call); | ||
1237 | 42 | QString bus_path() const; | ||
1238 | 43 | |||
1239 | 44 | protected: | ||
1240 | 45 | std::unique_ptr<DBusEnvironment> dbus_; | ||
1241 | 46 | std::unique_ptr<QDBusConnection> service_connection_; | ||
1242 | 47 | std::unique_ptr<OnlineAccounts::Manager> account_manager_; | ||
1243 | 48 | std::unique_ptr<unity::storage::provider::testing::TestServer> test_server_; | ||
1244 | 49 | }; |
FAILED: Continuous integration, rev:57 /jenkins. canonical. com/unity- api-1/job/ lp-storage- framework- ci/81/ /jenkins. canonical. com/unity- api-1/job/ build/425/ console /jenkins. canonical. com/unity- api-1/job/ build-0- fetch/431 /jenkins. canonical. com/unity- api-1/job/ build-1- sourcepkg/ release= vivid+overlay/ 338 /jenkins. canonical. com/unity- api-1/job/ build-1- sourcepkg/ release= xenial+ overlay/ 338 /jenkins. canonical. com/unity- api-1/job/ build-1- sourcepkg/ release= yakkety/ 338 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= vivid+overlay/ 268 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= vivid+overlay/ 268/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= xenial+ overlay/ 268 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= xenial+ overlay/ 268/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= yakkety/ 268/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= vivid+overlay/ 268 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= vivid+overlay/ 268/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= xenial+ overlay/ 268 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= xenial+ overlay/ 268/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= yakkety/ 268 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= yakkety/ 268/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= vivid+overlay/ 268 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= vivid+overlay/ 268/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 268 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 268/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= yakkety/ 268 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= yakkety/ 268/artifact/ output/ *zip*/output. zip
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild: /jenkins. canonical. com/unity- api-1/job/ lp-storage- framework- ci/81/rebuild
https:/