Merge lp:~michihenning/storage-framework/use-qiodevice into lp:storage-framework/devel
- use-qiodevice
- Merge into devel
Status: | Merged |
---|---|
Approved by: | James Henstridge |
Approved revision: | 96 |
Merged at revision: | 90 |
Proposed branch: | lp:~michihenning/storage-framework/use-qiodevice |
Merge into: | lp:storage-framework/devel |
Prerequisite: | lp:~michihenning/storage-framework/metadata-keys |
Diff against target: |
2011 lines (+568/-498) 16 files modified
include/unity/storage/qt/Downloader.h (+14/-5) include/unity/storage/qt/Uploader.h (+15/-4) include/unity/storage/qt/client/internal/remote_client/HandlerBase.h (+1/-0) include/unity/storage/qt/internal/DownloaderImpl.h (+12/-1) include/unity/storage/qt/internal/Handler.h (+6/-0) include/unity/storage/qt/internal/HandlerBase.h (+0/-2) include/unity/storage/qt/internal/ListJobImplBase.h (+1/-0) include/unity/storage/qt/internal/UploaderImpl.h (+18/-1) include/unity/storage/qt/internal/VoidJobImpl.h (+1/-0) src/qt/Downloader.cpp (+48/-5) src/qt/Uploader.cpp (+48/-5) src/qt/internal/DownloaderImpl.cpp (+97/-41) src/qt/internal/HandlerBase.cpp (+1/-0) src/qt/internal/UploaderImpl.cpp (+171/-59) tests/remote-client/MockProvider.cpp (+4/-10) tests/remote-client/remote-client_test.cpp (+131/-365) |
To merge this branch: | bzr merge lp:~michihenning/storage-framework/use-qiodevice |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Henstridge | Approve | ||
unity-api-1-bot | continuous-integration | Approve | |
Review via email:
|
Commit message
Changed Uploader and Downloader to derive from QIODevice.
Description of the change
Changed Uploader and Downloader to derive from QIODevice.
![](/+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:89
https:/
Executed test runs:
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:/
- 90. By Michi Henning
-
Merged dependent branch.
- 91. By Michi Henning
-
Merged dependent branch.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:90
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: 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)
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:91
https:/
Executed test runs:
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 small issues via inline comments
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Michi Henning (michihenning) wrote : | # |
I removed the stale file from the merge conflict and got rid of the redundant Q_INVOKABLE, thanks!
For the uploader, my thinking was that the caller should not write to the uploader until it enters the Ready state.
I need to check what happens if a write is done before then. I would expect the write to return an error seeing that underlying socket isn't connected at that point. (If that isn't the case, we can easily arrange for the write to return -1.)
I think forcing the caller to wait until the socket is ready is better than buffering the data. After all, the socket may not ever become ready due to an error (such as the server side going belly-up for some reason) and, if the client is allowed to write regardless, all the data just ends up piling up in memory.
- 92. By Michi Henning
-
Got rid of merge conflict file and redundant Q_INVOKABLEs.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:92
https:/
Executed test runs:
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:/
- 93. By Michi Henning
-
Merged devel.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
James Henstridge (jamesh) wrote : | # |
The Uploader QIODevice is in its open state.
The expected semantics are that you can write to the device and those writes will be buffered, with the bytesWritten signal being used to notify when the write has completed.
While it is possible to signal an error, it seems that this is generally used for hard errors rather than simple "can't complete the write right now" errors. So if we throw away the early writes, we're effectively breaking the contract.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:93
https:/
Executed test runs:
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:/
- 94. By Michi Henning
-
Added code to deal with synchronous wait on uploader.
Not tested yet, because we need to make changes to the mock provider harness for this.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:94
https:/
Executed test runs:
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 : | # |
This looks very close to ready. I've left a few inline comments. Some are just stylistic so could be ignored, so some could be left as is.
- 95. By Michi Henning
-
Review comments from James.
- 96. By Michi Henning
-
Renamed finishUpload() and finishDownload() to close().
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:96
https:/
Executed test runs:
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 'include/unity/storage/qt/Downloader.h' | |||
2 | --- include/unity/storage/qt/Downloader.h 2016-10-31 02:01:05 +0000 | |||
3 | +++ include/unity/storage/qt/Downloader.h 2016-11-04 07:34:14 +0000 | |||
4 | @@ -36,7 +36,7 @@ | |||
5 | 36 | 36 | ||
6 | 37 | } // namespace internal | 37 | } // namespace internal |
7 | 38 | 38 | ||
9 | 39 | class Q_DECL_EXPORT Downloader final : public QLocalSocket | 39 | class Q_DECL_EXPORT Downloader final : public QIODevice |
10 | 40 | { | 40 | { |
11 | 41 | Q_OBJECT | 41 | Q_OBJECT |
12 | 42 | Q_PROPERTY(bool isValid READ isValid NOTIFY statusChanged FINAL) | 42 | Q_PROPERTY(bool isValid READ isValid NOTIFY statusChanged FINAL) |
13 | @@ -51,15 +51,21 @@ | |||
14 | 51 | Downloader(); | 51 | Downloader(); |
15 | 52 | virtual ~Downloader(); | 52 | virtual ~Downloader(); |
16 | 53 | 53 | ||
18 | 54 | bool isValid() const; // Not nice, hides QLocalSocket::isValid() | 54 | bool isValid() const; |
19 | 55 | Status status() const; | 55 | Status status() const; |
21 | 56 | StorageError error() const; // Not nice, hides QLocalSocket::error() | 56 | StorageError error() const; |
22 | 57 | Item item() const; | 57 | Item item() const; |
23 | 58 | 58 | ||
24 | 59 | Q_INVOKABLE void finishDownload(); | ||
25 | 60 | Q_INVOKABLE void cancel(); | 59 | Q_INVOKABLE void cancel(); |
26 | 61 | 60 | ||
28 | 62 | // TODO: will probably need QML invokable methods for reading and writing to/from QIODevice | 61 | // From QLocalSocket interface. |
29 | 62 | Q_INVOKABLE void close(); | ||
30 | 63 | Q_INVOKABLE qint64 bytesAvailable() const override; | ||
31 | 64 | Q_INVOKABLE qint64 bytesToWrite() const override; | ||
32 | 65 | Q_INVOKABLE bool canReadLine() const override; | ||
33 | 66 | Q_INVOKABLE bool isSequential() const override; | ||
34 | 67 | Q_INVOKABLE bool waitForBytesWritten(int msecs = 30000) override; | ||
35 | 68 | Q_INVOKABLE bool waitForReadyRead(int msecs = 30000) override; | ||
36 | 63 | 69 | ||
37 | 64 | Q_SIGNALS: | 70 | Q_SIGNALS: |
38 | 65 | void statusChanged(unity::storage::qt::Downloader::Status status) const; | 71 | void statusChanged(unity::storage::qt::Downloader::Status status) const; |
39 | @@ -67,6 +73,9 @@ | |||
40 | 67 | private: | 73 | private: |
41 | 68 | Downloader(std::unique_ptr<internal::DownloaderImpl> p); | 74 | Downloader(std::unique_ptr<internal::DownloaderImpl> p); |
42 | 69 | 75 | ||
43 | 76 | qint64 readData(char* data, qint64 c); | ||
44 | 77 | qint64 writeData(char const* data, qint64 c); | ||
45 | 78 | |||
46 | 70 | std::unique_ptr<internal::DownloaderImpl> p_; | 79 | std::unique_ptr<internal::DownloaderImpl> p_; |
47 | 71 | 80 | ||
48 | 72 | friend class internal::DownloaderImpl; | 81 | friend class internal::DownloaderImpl; |
49 | 73 | 82 | ||
50 | === modified file 'include/unity/storage/qt/Uploader.h' | |||
51 | --- include/unity/storage/qt/Uploader.h 2016-10-12 05:25:20 +0000 | |||
52 | +++ include/unity/storage/qt/Uploader.h 2016-11-04 07:34:14 +0000 | |||
53 | @@ -39,7 +39,7 @@ | |||
54 | 39 | class Item; | 39 | class Item; |
55 | 40 | class StorageError; | 40 | class StorageError; |
56 | 41 | 41 | ||
58 | 42 | class Q_DECL_EXPORT Uploader final : public QLocalSocket | 42 | class Q_DECL_EXPORT Uploader final : public QIODevice |
59 | 43 | { | 43 | { |
60 | 44 | Q_OBJECT | 44 | Q_OBJECT |
61 | 45 | Q_PROPERTY(bool isValid READ isValid NOTIFY statusChanged FINAL) | 45 | Q_PROPERTY(bool isValid READ isValid NOTIFY statusChanged FINAL) |
62 | @@ -56,22 +56,33 @@ | |||
63 | 56 | Uploader(); | 56 | Uploader(); |
64 | 57 | virtual ~Uploader(); | 57 | virtual ~Uploader(); |
65 | 58 | 58 | ||
67 | 59 | bool isValid() const; // Not nice, hides QLocalSocket::isValid() | 59 | bool isValid() const; |
68 | 60 | Status status() const; | 60 | Status status() const; |
70 | 61 | StorageError error() const; // Not nice, hides QLocalSocket::error() | 61 | StorageError error() const; |
71 | 62 | Item::ConflictPolicy policy() const; | 62 | Item::ConflictPolicy policy() const; |
72 | 63 | qint64 sizeInBytes() const; | 63 | qint64 sizeInBytes() const; |
73 | 64 | Item item() const; | 64 | Item item() const; |
74 | 65 | 65 | ||
75 | 66 | Q_INVOKABLE void finishUpload(); | ||
76 | 67 | Q_INVOKABLE void cancel(); | 66 | Q_INVOKABLE void cancel(); |
77 | 68 | 67 | ||
78 | 68 | // From QLocalSocket interface. | ||
79 | 69 | Q_INVOKABLE void close() override; | ||
80 | 70 | Q_INVOKABLE qint64 bytesAvailable() const override; | ||
81 | 71 | Q_INVOKABLE qint64 bytesToWrite() const override; | ||
82 | 72 | Q_INVOKABLE bool canReadLine() const override; | ||
83 | 73 | Q_INVOKABLE bool isSequential() const override; | ||
84 | 74 | Q_INVOKABLE bool waitForBytesWritten(int msecs = 30000) override; | ||
85 | 75 | Q_INVOKABLE bool waitForReadyRead(int msecs = 30000) override; | ||
86 | 76 | |||
87 | 69 | Q_SIGNALS: | 77 | Q_SIGNALS: |
88 | 70 | void statusChanged(unity::storage::qt::Uploader::Status status) const; | 78 | void statusChanged(unity::storage::qt::Uploader::Status status) const; |
89 | 71 | 79 | ||
90 | 72 | private: | 80 | private: |
91 | 73 | Uploader(std::unique_ptr<internal::UploaderImpl> p); | 81 | Uploader(std::unique_ptr<internal::UploaderImpl> p); |
92 | 74 | 82 | ||
93 | 83 | qint64 readData(char* data, qint64 c); | ||
94 | 84 | qint64 writeData(char const* data, qint64 c); | ||
95 | 85 | |||
96 | 75 | std::unique_ptr<internal::UploaderImpl> p_; | 86 | std::unique_ptr<internal::UploaderImpl> p_; |
97 | 76 | 87 | ||
98 | 77 | friend class internal::UploaderImpl; | 88 | friend class internal::UploaderImpl; |
99 | 78 | 89 | ||
100 | === modified file 'include/unity/storage/qt/client/internal/remote_client/HandlerBase.h' | |||
101 | --- include/unity/storage/qt/client/internal/remote_client/HandlerBase.h 2016-07-13 05:12:47 +0000 | |||
102 | +++ include/unity/storage/qt/client/internal/remote_client/HandlerBase.h 2016-11-04 07:34:14 +0000 | |||
103 | @@ -19,6 +19,7 @@ | |||
104 | 19 | #pragma once | 19 | #pragma once |
105 | 20 | 20 | ||
106 | 21 | #pragma GCC diagnostic push | 21 | #pragma GCC diagnostic push |
107 | 22 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
108 | 22 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | 23 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" |
109 | 23 | #pragma GCC diagnostic ignored "-Wswitch-default" | 24 | #pragma GCC diagnostic ignored "-Wswitch-default" |
110 | 24 | #include <QDBusPendingCallWatcher> | 25 | #include <QDBusPendingCallWatcher> |
111 | 25 | 26 | ||
112 | === modified file 'include/unity/storage/qt/internal/DownloaderImpl.h' | |||
113 | --- include/unity/storage/qt/internal/DownloaderImpl.h 2016-10-12 07:23:15 +0000 | |||
114 | +++ include/unity/storage/qt/internal/DownloaderImpl.h 2016-11-04 07:34:14 +0000 | |||
115 | @@ -47,9 +47,19 @@ | |||
116 | 47 | StorageError error() const; | 47 | StorageError error() const; |
117 | 48 | Item item() const; | 48 | Item item() const; |
118 | 49 | 49 | ||
119 | 50 | void finishDownload(); | ||
120 | 51 | void cancel(); | 50 | void cancel(); |
121 | 52 | 51 | ||
122 | 52 | // From QLocalSocket interface. | ||
123 | 53 | void close(); | ||
124 | 54 | qint64 bytesAvailable() const; | ||
125 | 55 | qint64 bytesToWrite() const; | ||
126 | 56 | bool canReadLine() const; | ||
127 | 57 | bool isSequential() const; | ||
128 | 58 | bool waitForBytesWritten(int msecs); | ||
129 | 59 | bool waitForReadyRead(int msecs); | ||
130 | 60 | qint64 readData(char* data, qint64 c); | ||
131 | 61 | qint64 writeData(char const* data, qint64 c); | ||
132 | 62 | |||
133 | 53 | static Downloader* make_job(std::shared_ptr<ItemImpl> const& item_impl, | 63 | static Downloader* make_job(std::shared_ptr<ItemImpl> const& item_impl, |
134 | 54 | QString const& method, | 64 | QString const& method, |
135 | 55 | QDBusPendingReply<QString, QDBusUnixFileDescriptor>& reply); | 65 | QDBusPendingReply<QString, QDBusUnixFileDescriptor>& reply); |
136 | @@ -62,6 +72,7 @@ | |||
137 | 62 | std::shared_ptr<ItemImpl> item_impl_; | 72 | std::shared_ptr<ItemImpl> item_impl_; |
138 | 63 | QString download_id_; | 73 | QString download_id_; |
139 | 64 | QDBusUnixFileDescriptor fd_; | 74 | QDBusUnixFileDescriptor fd_; |
140 | 75 | QLocalSocket socket_; | ||
141 | 65 | bool finalizing_ = false; | 76 | bool finalizing_ = false; |
142 | 66 | }; | 77 | }; |
143 | 67 | 78 | ||
144 | 68 | 79 | ||
145 | === modified file 'include/unity/storage/qt/internal/Handler.h' | |||
146 | --- include/unity/storage/qt/internal/Handler.h 2016-10-12 07:23:15 +0000 | |||
147 | +++ include/unity/storage/qt/internal/Handler.h 2016-11-04 07:34:14 +0000 | |||
148 | @@ -102,6 +102,12 @@ | |||
149 | 102 | }) | 102 | }) |
150 | 103 | { | 103 | { |
151 | 104 | } | 104 | } |
152 | 105 | |||
153 | 106 | void wait_and_process_now() | ||
154 | 107 | { | ||
155 | 108 | watcher_.waitForFinished(); | ||
156 | 109 | finished(&watcher_); | ||
157 | 110 | } | ||
158 | 105 | }; | 111 | }; |
159 | 106 | 112 | ||
160 | 107 | } // namespace internal | 113 | } // namespace internal |
161 | 108 | 114 | ||
162 | === modified file 'include/unity/storage/qt/internal/HandlerBase.h' | |||
163 | --- include/unity/storage/qt/internal/HandlerBase.h 2016-09-21 00:29:49 +0000 | |||
164 | +++ include/unity/storage/qt/internal/HandlerBase.h 2016-11-04 07:34:14 +0000 | |||
165 | @@ -53,8 +53,6 @@ | |||
166 | 53 | 53 | ||
167 | 54 | protected: | 54 | protected: |
168 | 55 | QDBusPendingCallWatcher watcher_; | 55 | QDBusPendingCallWatcher watcher_; |
169 | 56 | |||
170 | 57 | private: | ||
171 | 58 | std::function<void(QDBusPendingCallWatcher&)> closure_; | 56 | std::function<void(QDBusPendingCallWatcher&)> closure_; |
172 | 59 | }; | 57 | }; |
173 | 60 | 58 | ||
174 | 61 | 59 | ||
175 | === modified file 'include/unity/storage/qt/internal/ListJobImplBase.h' | |||
176 | --- include/unity/storage/qt/internal/ListJobImplBase.h 2016-10-12 05:25:20 +0000 | |||
177 | +++ include/unity/storage/qt/internal/ListJobImplBase.h 2016-11-04 07:34:14 +0000 | |||
178 | @@ -22,6 +22,7 @@ | |||
179 | 22 | #include <unity/storage/qt/StorageError.h> | 22 | #include <unity/storage/qt/StorageError.h> |
180 | 23 | 23 | ||
181 | 24 | #pragma GCC diagnostic push | 24 | #pragma GCC diagnostic push |
182 | 25 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
183 | 25 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | 26 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" |
184 | 26 | #include <QDBusPendingReply> | 27 | #include <QDBusPendingReply> |
185 | 27 | #pragma GCC diagnostic pop | 28 | #pragma GCC diagnostic pop |
186 | 28 | 29 | ||
187 | === modified file 'include/unity/storage/qt/internal/UploaderImpl.h' | |||
188 | --- include/unity/storage/qt/internal/UploaderImpl.h 2016-11-03 03:41:24 +0000 | |||
189 | +++ include/unity/storage/qt/internal/UploaderImpl.h 2016-11-04 07:34:14 +0000 | |||
190 | @@ -18,10 +18,12 @@ | |||
191 | 18 | 18 | ||
192 | 19 | #pragma once | 19 | #pragma once |
193 | 20 | 20 | ||
194 | 21 | #include <unity/storage/qt/internal/Handler.h> | ||
195 | 21 | #include <unity/storage/qt/Uploader.h> | 22 | #include <unity/storage/qt/Uploader.h> |
196 | 22 | 23 | ||
197 | 23 | #include <QDBusPendingReply> | 24 | #include <QDBusPendingReply> |
198 | 24 | #include <QDBusUnixFileDescriptor> | 25 | #include <QDBusUnixFileDescriptor> |
199 | 26 | #include <QPointer> | ||
200 | 25 | 27 | ||
201 | 26 | namespace unity | 28 | namespace unity |
202 | 27 | { | 29 | { |
203 | @@ -59,9 +61,19 @@ | |||
204 | 59 | qint64 sizeInBytes() const; | 61 | qint64 sizeInBytes() const; |
205 | 60 | Item item() const; | 62 | Item item() const; |
206 | 61 | 63 | ||
207 | 62 | void finishUpload(); | ||
208 | 63 | void cancel(); | 64 | void cancel(); |
209 | 64 | 65 | ||
210 | 66 | // From QLocalSocket interface. | ||
211 | 67 | void close(); | ||
212 | 68 | qint64 bytesAvailable() const; | ||
213 | 69 | qint64 bytesToWrite() const; | ||
214 | 70 | bool canReadLine() const; | ||
215 | 71 | bool isSequential() const; | ||
216 | 72 | bool waitForBytesWritten(int msecs); | ||
217 | 73 | bool waitForReadyRead(int msecs); | ||
218 | 74 | qint64 readData(char* data, qint64 c); | ||
219 | 75 | qint64 writeData(char const* data, qint64 c); | ||
220 | 76 | |||
221 | 65 | static Uploader* make_job(std::shared_ptr<ItemImpl> const& item_impl, | 77 | static Uploader* make_job(std::shared_ptr<ItemImpl> const& item_impl, |
222 | 66 | QString const& method, | 78 | QString const& method, |
223 | 67 | QDBusPendingReply<QString, QDBusUnixFileDescriptor>& reply, | 79 | QDBusPendingReply<QString, QDBusUnixFileDescriptor>& reply, |
224 | @@ -70,6 +82,8 @@ | |||
225 | 70 | qint64 size_in_bytes); | 82 | qint64 size_in_bytes); |
226 | 71 | static Uploader* make_job(StorageError const& e); | 83 | static Uploader* make_job(StorageError const& e); |
227 | 72 | 84 | ||
228 | 85 | qint64 flush_buffer(); | ||
229 | 86 | |||
230 | 73 | private: | 87 | private: |
231 | 74 | Uploader* public_instance_; | 88 | Uploader* public_instance_; |
232 | 75 | Uploader::Status status_; | 89 | Uploader::Status status_; |
233 | @@ -79,8 +93,11 @@ | |||
234 | 79 | std::function<void(storage::internal::ItemMetadata const&)> validate_; | 93 | std::function<void(storage::internal::ItemMetadata const&)> validate_; |
235 | 80 | Item::ConflictPolicy policy_ = Item::ConflictPolicy::IgnoreConflict; | 94 | Item::ConflictPolicy policy_ = Item::ConflictPolicy::IgnoreConflict; |
236 | 81 | qint64 size_in_bytes_ = 0; | 95 | qint64 size_in_bytes_ = 0; |
237 | 96 | QPointer<Handler<QDBusPendingReply<QString, QDBusUnixFileDescriptor>>> handler_; | ||
238 | 82 | QString upload_id_; | 97 | QString upload_id_; |
239 | 83 | QDBusUnixFileDescriptor fd_; | 98 | QDBusUnixFileDescriptor fd_; |
240 | 99 | QLocalSocket socket_; | ||
241 | 100 | QByteArray buffer_; | ||
242 | 84 | bool finalizing_ = false; | 101 | bool finalizing_ = false; |
243 | 85 | }; | 102 | }; |
244 | 86 | 103 | ||
245 | 87 | 104 | ||
246 | === modified file 'include/unity/storage/qt/internal/VoidJobImpl.h' | |||
247 | --- include/unity/storage/qt/internal/VoidJobImpl.h 2016-10-12 08:08:48 +0000 | |||
248 | +++ include/unity/storage/qt/internal/VoidJobImpl.h 2016-11-04 07:34:14 +0000 | |||
249 | @@ -23,6 +23,7 @@ | |||
250 | 23 | #include <unity/storage/qt/StorageError.h> | 23 | #include <unity/storage/qt/StorageError.h> |
251 | 24 | 24 | ||
252 | 25 | #pragma GCC diagnostic push | 25 | #pragma GCC diagnostic push |
253 | 26 | #pragma GCC diagnostic ignored "-Wcast-align" | ||
254 | 26 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" | 27 | #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" |
255 | 27 | #include <QDBusPendingReply> | 28 | #include <QDBusPendingReply> |
256 | 28 | #pragma GCC diagnostic pop | 29 | #pragma GCC diagnostic pop |
257 | 29 | 30 | ||
258 | === modified file 'src/qt/Downloader.cpp' | |||
259 | --- src/qt/Downloader.cpp 2016-10-11 08:12:32 +0000 | |||
260 | +++ src/qt/Downloader.cpp 2016-11-04 07:34:14 +0000 | |||
261 | @@ -61,16 +61,59 @@ | |||
262 | 61 | return p_->item(); | 61 | return p_->item(); |
263 | 62 | } | 62 | } |
264 | 63 | 63 | ||
265 | 64 | void Downloader::finishDownload() | ||
266 | 65 | { | ||
267 | 66 | p_->finishDownload(); | ||
268 | 67 | } | ||
269 | 68 | |||
270 | 69 | void Downloader::cancel() | 64 | void Downloader::cancel() |
271 | 70 | { | 65 | { |
272 | 71 | p_->cancel(); | 66 | p_->cancel(); |
273 | 72 | } | 67 | } |
274 | 73 | 68 | ||
275 | 69 | void Downloader::close() | ||
276 | 70 | { | ||
277 | 71 | p_->close(); | ||
278 | 72 | } | ||
279 | 73 | |||
280 | 74 | qint64 Downloader::bytesAvailable() const | ||
281 | 75 | { | ||
282 | 76 | return p_->bytesAvailable(); | ||
283 | 77 | } | ||
284 | 78 | |||
285 | 79 | qint64 Downloader::bytesToWrite() const | ||
286 | 80 | { | ||
287 | 81 | return p_->bytesToWrite(); | ||
288 | 82 | } | ||
289 | 83 | |||
290 | 84 | bool Downloader::canReadLine() const | ||
291 | 85 | { | ||
292 | 86 | return p_->canReadLine(); | ||
293 | 87 | } | ||
294 | 88 | |||
295 | 89 | bool Downloader::isSequential() const | ||
296 | 90 | { | ||
297 | 91 | return p_->isSequential(); | ||
298 | 92 | } | ||
299 | 93 | |||
300 | 94 | bool Downloader::waitForBytesWritten(int msecs) | ||
301 | 95 | { | ||
302 | 96 | return p_->waitForBytesWritten(msecs); | ||
303 | 97 | } | ||
304 | 98 | |||
305 | 99 | bool Downloader::waitForReadyRead(int msecs) | ||
306 | 100 | { | ||
307 | 101 | return p_->waitForReadyRead(msecs); | ||
308 | 102 | } | ||
309 | 103 | |||
310 | 104 | qint64 Downloader::readData(char* data, qint64 c) | ||
311 | 105 | { | ||
312 | 106 | return p_->readData(data, c); | ||
313 | 107 | } | ||
314 | 108 | |||
315 | 109 | // LCOV_EXCL_START | ||
316 | 110 | // Never called by QIODevice because device is opened read-only. | ||
317 | 111 | qint64 Downloader::writeData(char const* data, qint64 c) | ||
318 | 112 | { | ||
319 | 113 | return p_->writeData(data, c); | ||
320 | 114 | } | ||
321 | 115 | // LCOV_EXCL_STOP | ||
322 | 116 | |||
323 | 74 | } // namespace qt | 117 | } // namespace qt |
324 | 75 | } // namespace storage | 118 | } // namespace storage |
325 | 76 | } // namespace unity | 119 | } // namespace unity |
326 | 77 | 120 | ||
327 | === modified file 'src/qt/Uploader.cpp' | |||
328 | --- src/qt/Uploader.cpp 2016-10-12 05:25:20 +0000 | |||
329 | +++ src/qt/Uploader.cpp 2016-11-04 07:34:14 +0000 | |||
330 | @@ -71,16 +71,59 @@ | |||
331 | 71 | return p_->item(); | 71 | return p_->item(); |
332 | 72 | } | 72 | } |
333 | 73 | 73 | ||
334 | 74 | void Uploader::finishUpload() | ||
335 | 75 | { | ||
336 | 76 | p_->finishUpload(); | ||
337 | 77 | } | ||
338 | 78 | |||
339 | 79 | void Uploader::cancel() | 74 | void Uploader::cancel() |
340 | 80 | { | 75 | { |
341 | 81 | p_->cancel(); | 76 | p_->cancel(); |
342 | 82 | } | 77 | } |
343 | 83 | 78 | ||
344 | 79 | void Uploader::close() | ||
345 | 80 | { | ||
346 | 81 | p_->close(); | ||
347 | 82 | } | ||
348 | 83 | |||
349 | 84 | qint64 Uploader::bytesAvailable() const | ||
350 | 85 | { | ||
351 | 86 | return p_->bytesAvailable(); | ||
352 | 87 | } | ||
353 | 88 | |||
354 | 89 | qint64 Uploader::bytesToWrite() const | ||
355 | 90 | { | ||
356 | 91 | return p_->bytesToWrite(); | ||
357 | 92 | } | ||
358 | 93 | |||
359 | 94 | bool Uploader::canReadLine() const | ||
360 | 95 | { | ||
361 | 96 | return p_->canReadLine(); | ||
362 | 97 | } | ||
363 | 98 | |||
364 | 99 | bool Uploader::isSequential() const | ||
365 | 100 | { | ||
366 | 101 | return p_->isSequential(); | ||
367 | 102 | } | ||
368 | 103 | |||
369 | 104 | bool Uploader::waitForBytesWritten(int msecs) | ||
370 | 105 | { | ||
371 | 106 | return p_->waitForBytesWritten(msecs); | ||
372 | 107 | } | ||
373 | 108 | |||
374 | 109 | bool Uploader::waitForReadyRead(int msecs) | ||
375 | 110 | { | ||
376 | 111 | return p_->waitForReadyRead(msecs); | ||
377 | 112 | } | ||
378 | 113 | |||
379 | 114 | // LCOV_EXCL_START | ||
380 | 115 | // Never called by QIODevice because device is opened write-only. | ||
381 | 116 | qint64 Uploader::readData(char* data, qint64 c) | ||
382 | 117 | { | ||
383 | 118 | return p_->readData(data, c); | ||
384 | 119 | } | ||
385 | 120 | // LCOV_EXCL_STOP | ||
386 | 121 | |||
387 | 122 | qint64 Uploader::writeData(char const* data, qint64 c) | ||
388 | 123 | { | ||
389 | 124 | return p_->writeData(data, c); | ||
390 | 125 | } | ||
391 | 126 | |||
392 | 84 | } // namespace qt | 127 | } // namespace qt |
393 | 85 | } // namespace storage | 128 | } // namespace storage |
394 | 86 | } // namespace unity | 129 | } // namespace unity |
395 | 87 | 130 | ||
396 | === modified file 'src/qt/internal/DownloaderImpl.cpp' | |||
397 | --- src/qt/internal/DownloaderImpl.cpp 2016-10-13 06:48:11 +0000 | |||
398 | +++ src/qt/internal/DownloaderImpl.cpp 2016-11-04 07:34:14 +0000 | |||
399 | @@ -58,7 +58,7 @@ | |||
400 | 58 | { | 58 | { |
401 | 59 | QString msg = method + ": Runtime was destroyed previously"; | 59 | QString msg = method + ": Runtime was destroyed previously"; |
402 | 60 | error_ = StorageErrorImpl::runtime_destroyed_error(msg); | 60 | error_ = StorageErrorImpl::runtime_destroyed_error(msg); |
404 | 61 | public_instance_->abort(); | 61 | socket_.abort(); |
405 | 62 | public_instance_->setErrorString(msg); | 62 | public_instance_->setErrorString(msg); |
406 | 63 | status_ = Downloader::Status::Error; | 63 | status_ = Downloader::Status::Error; |
407 | 64 | Q_EMIT public_instance_->statusChanged(status_); | 64 | Q_EMIT public_instance_->statusChanged(status_); |
408 | @@ -73,7 +73,7 @@ | |||
409 | 73 | QString msg = method + ": invalid file descriptor returned by provider"; | 73 | QString msg = method + ": invalid file descriptor returned by provider"; |
410 | 74 | qCritical().noquote() << msg; | 74 | qCritical().noquote() << msg; |
411 | 75 | error_ = StorageErrorImpl::local_comms_error(msg); | 75 | error_ = StorageErrorImpl::local_comms_error(msg); |
413 | 76 | public_instance_->abort(); | 76 | socket_.abort(); |
414 | 77 | public_instance_->setErrorString(msg); | 77 | public_instance_->setErrorString(msg); |
415 | 78 | status_ = Downloader::Status::Error; | 78 | status_ = Downloader::Status::Error; |
416 | 79 | Q_EMIT public_instance_->statusChanged(status_); | 79 | Q_EMIT public_instance_->statusChanged(status_); |
417 | @@ -81,7 +81,18 @@ | |||
418 | 81 | // LCOV_EXCL_STOP | 81 | // LCOV_EXCL_STOP |
419 | 82 | } | 82 | } |
420 | 83 | 83 | ||
422 | 84 | public_instance_->setSocketDescriptor(fd_.fileDescriptor(), QLocalSocket::ConnectedState, QIODevice::ReadOnly); | 84 | // We forward any QIODevice signals emitted by the socket to the public instance. |
423 | 85 | connect(&socket_, &QIODevice::aboutToClose, public_instance_, &QIODevice::aboutToClose); | ||
424 | 86 | connect(&socket_, &QIODevice::bytesWritten, public_instance_, &QIODevice::bytesWritten); | ||
425 | 87 | connect(&socket_, &QIODevice::readChannelFinished, public_instance_, &QIODevice::readChannelFinished); | ||
426 | 88 | connect(&socket_, &QIODevice::readyRead, public_instance_, &QIODevice::readyRead); | ||
427 | 89 | |||
428 | 90 | #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) | ||
429 | 91 | connect(&socket_, &QIODevice::channelBytesWritten, public_instance_, &QIODevice::channelBytesWritten); | ||
430 | 92 | connect(&socket_, &QIODevice::channelReadyRead, public_instance_, &QIODevice::channelReadyRead); | ||
431 | 93 | #endif | ||
432 | 94 | |||
433 | 95 | socket_.setSocketDescriptor(fd_.fileDescriptor(), QLocalSocket::ConnectedState, QIODevice::ReadOnly); | ||
434 | 85 | status_ = Downloader::Status::Ready; | 96 | status_ = Downloader::Status::Ready; |
435 | 86 | Q_EMIT public_instance_->statusChanged(status_); | 97 | Q_EMIT public_instance_->statusChanged(status_); |
436 | 87 | }; | 98 | }; |
437 | @@ -91,12 +102,12 @@ | |||
438 | 91 | // TODO: This does not set the method | 102 | // TODO: This does not set the method |
439 | 92 | error_ = error; | 103 | error_ = error; |
440 | 93 | status_ = Downloader::Status::Error; | 104 | status_ = Downloader::Status::Error; |
442 | 94 | public_instance_->abort(); | 105 | socket_.abort(); |
443 | 95 | public_instance_->setErrorString(error.errorString()); | 106 | public_instance_->setErrorString(error.errorString()); |
444 | 96 | Q_EMIT public_instance_->statusChanged(status_); | 107 | Q_EMIT public_instance_->statusChanged(status_); |
445 | 97 | }; | 108 | }; |
446 | 98 | 109 | ||
448 | 99 | new Handler<storage::internal::ItemMetadata>(this, reply, process_reply, process_error); | 110 | new Handler<QDBusPendingReply<QString, QDBusUnixFileDescriptor>>(this, reply, process_reply, process_error); |
449 | 100 | } | 111 | } |
450 | 101 | 112 | ||
451 | 102 | DownloaderImpl::DownloaderImpl(StorageError const& e) | 113 | DownloaderImpl::DownloaderImpl(StorageError const& e) |
452 | @@ -146,11 +157,40 @@ | |||
453 | 146 | return Item(item_impl_); | 157 | return Item(item_impl_); |
454 | 147 | } | 158 | } |
455 | 148 | 159 | ||
461 | 149 | void DownloaderImpl::finishDownload() | 160 | void DownloaderImpl::cancel() |
462 | 150 | { | 161 | { |
463 | 151 | static QString const method = "Downloader::finishDownload()"; | 162 | static QString const method = "Downloader::cancel()"; |
464 | 152 | 163 | ||
465 | 153 | // If we encountered an error earlier or were cancelled, or if finishDownload() was | 164 | // If we are in a final state already, ignore the call. |
466 | 165 | if ( status_ == Downloader::Status::Error | ||
467 | 166 | || status_ == Downloader::Status::Finished | ||
468 | 167 | || status_ == Downloader::Status::Cancelled) | ||
469 | 168 | { | ||
470 | 169 | return; | ||
471 | 170 | } | ||
472 | 171 | auto runtime = item_impl_->runtime_impl(); | ||
473 | 172 | if (!runtime || !runtime->isValid()) | ||
474 | 173 | { | ||
475 | 174 | QString msg = method + ": Runtime was destroyed previously"; | ||
476 | 175 | error_ = StorageErrorImpl::runtime_destroyed_error(msg); | ||
477 | 176 | status_ = Downloader::Status::Error; | ||
478 | 177 | Q_EMIT public_instance_->statusChanged(status_); | ||
479 | 178 | return; | ||
480 | 179 | } | ||
481 | 180 | |||
482 | 181 | QString msg = method + ": download was cancelled"; | ||
483 | 182 | error_ = StorageErrorImpl::cancelled_error(msg); | ||
484 | 183 | socket_.abort(); | ||
485 | 184 | public_instance_->setErrorString(msg); | ||
486 | 185 | status_ = Downloader::Status::Cancelled; | ||
487 | 186 | Q_EMIT public_instance_->statusChanged(status_); | ||
488 | 187 | } | ||
489 | 188 | |||
490 | 189 | void DownloaderImpl::close() | ||
491 | 190 | { | ||
492 | 191 | static QString const method = "Downloader::close()"; | ||
493 | 192 | |||
494 | 193 | // If we encountered an error earlier or were cancelled, or if close() was | ||
495 | 154 | // called already, we ignore the call. | 194 | // called already, we ignore the call. |
496 | 155 | if (status_ == Downloader::Status::Error || status_ == Downloader::Status::Cancelled || finalizing_) | 195 | if (status_ == Downloader::Status::Error || status_ == Downloader::Status::Cancelled || finalizing_) |
497 | 156 | { | 196 | { |
498 | @@ -162,7 +202,7 @@ | |||
499 | 162 | { | 202 | { |
500 | 163 | QString msg = method + ": cannot finalize while Downloader is not in the Ready state"; | 203 | QString msg = method + ": cannot finalize while Downloader is not in the Ready state"; |
501 | 164 | error_ = StorageErrorImpl::logic_error(msg); | 204 | error_ = StorageErrorImpl::logic_error(msg); |
503 | 165 | public_instance_->abort(); | 205 | socket_.abort(); |
504 | 166 | public_instance_->setErrorString(msg); | 206 | public_instance_->setErrorString(msg); |
505 | 167 | status_ = Downloader::Status::Error; | 207 | status_ = Downloader::Status::Error; |
506 | 168 | Q_EMIT public_instance_->statusChanged(status_); | 208 | Q_EMIT public_instance_->statusChanged(status_); |
507 | @@ -194,7 +234,7 @@ | |||
508 | 194 | { | 234 | { |
509 | 195 | QString msg = method + ": Runtime was destroyed previously"; | 235 | QString msg = method + ": Runtime was destroyed previously"; |
510 | 196 | error_ = StorageErrorImpl::runtime_destroyed_error(msg); | 236 | error_ = StorageErrorImpl::runtime_destroyed_error(msg); |
512 | 197 | public_instance_->abort(); | 237 | socket_.abort(); |
513 | 198 | public_instance_->setErrorString(msg); | 238 | public_instance_->setErrorString(msg); |
514 | 199 | status_ = Downloader::Status::Error; | 239 | status_ = Downloader::Status::Error; |
515 | 200 | Q_EMIT public_instance_->statusChanged(status_); | 240 | Q_EMIT public_instance_->statusChanged(status_); |
516 | @@ -214,7 +254,7 @@ | |||
517 | 214 | 254 | ||
518 | 215 | // TODO: this doesn't set the method | 255 | // TODO: this doesn't set the method |
519 | 216 | error_ = error; | 256 | error_ = error; |
521 | 217 | public_instance_->abort(); | 257 | socket_.abort(); |
522 | 218 | public_instance_->setErrorString(error.errorString()); | 258 | public_instance_->setErrorString(error.errorString()); |
523 | 219 | status_ = Downloader::Status::Error; | 259 | status_ = Downloader::Status::Error; |
524 | 220 | Q_EMIT public_instance_->statusChanged(status_); | 260 | Q_EMIT public_instance_->statusChanged(status_); |
525 | @@ -223,34 +263,48 @@ | |||
526 | 223 | new Handler<void>(this, reply, process_reply, process_error); | 263 | new Handler<void>(this, reply, process_reply, process_error); |
527 | 224 | } | 264 | } |
528 | 225 | 265 | ||
557 | 226 | void DownloaderImpl::cancel() | 266 | qint64 DownloaderImpl::bytesAvailable() const |
558 | 227 | { | 267 | { |
559 | 228 | static QString const method = "Downloader::cancel()"; | 268 | return socket_.bytesAvailable(); |
560 | 229 | 269 | } | |
561 | 230 | // If we are in a final state already, ignore the call. | 270 | |
562 | 231 | if ( status_ == Downloader::Status::Error | 271 | qint64 DownloaderImpl::bytesToWrite() const |
563 | 232 | || status_ == Downloader::Status::Finished | 272 | { |
564 | 233 | || status_ == Downloader::Status::Cancelled) | 273 | return socket_.bytesToWrite(); |
565 | 234 | { | 274 | } |
566 | 235 | return; | 275 | |
567 | 236 | } | 276 | bool DownloaderImpl::canReadLine() const |
568 | 237 | auto runtime = item_impl_->runtime_impl(); | 277 | { |
569 | 238 | if (!runtime || !runtime->isValid()) | 278 | return socket_.canReadLine(); |
570 | 239 | { | 279 | } |
571 | 240 | QString msg = method + ": Runtime was destroyed previously"; | 280 | |
572 | 241 | error_ = StorageErrorImpl::runtime_destroyed_error(msg); | 281 | bool DownloaderImpl::isSequential() const |
573 | 242 | status_ = Downloader::Status::Error; | 282 | { |
574 | 243 | Q_EMIT public_instance_->statusChanged(status_); | 283 | return socket_.isSequential(); |
575 | 244 | return; | 284 | } |
576 | 245 | } | 285 | |
577 | 246 | 286 | bool DownloaderImpl::waitForBytesWritten(int msecs) | |
578 | 247 | QString msg = method + ": download was cancelled"; | 287 | { |
579 | 248 | error_ = StorageErrorImpl::cancelled_error(msg); | 288 | return socket_.waitForBytesWritten(msecs); |
580 | 249 | public_instance_->abort(); | 289 | } |
581 | 250 | public_instance_->setErrorString(msg); | 290 | |
582 | 251 | status_ = Downloader::Status::Cancelled; | 291 | bool DownloaderImpl::waitForReadyRead(int msecs) |
583 | 252 | Q_EMIT public_instance_->statusChanged(status_); | 292 | { |
584 | 253 | } | 293 | return socket_.waitForReadyRead(msecs); |
585 | 294 | } | ||
586 | 295 | |||
587 | 296 | qint64 DownloaderImpl::readData(char* data, qint64 c) | ||
588 | 297 | { | ||
589 | 298 | return socket_.read(data, c); | ||
590 | 299 | } | ||
591 | 300 | |||
592 | 301 | // LCOV_EXCL_START | ||
593 | 302 | // Never called by QIODevice because device is opened read-only. | ||
594 | 303 | qint64 DownloaderImpl::writeData(char const* data, qint64 c) | ||
595 | 304 | { | ||
596 | 305 | return socket_.write(data, c); | ||
597 | 306 | } | ||
598 | 307 | // LCOV_EXCL_STOP | ||
599 | 254 | 308 | ||
600 | 255 | Downloader* DownloaderImpl::make_job(shared_ptr<ItemImpl> const& item_impl, | 309 | Downloader* DownloaderImpl::make_job(shared_ptr<ItemImpl> const& item_impl, |
601 | 256 | QString const& method, | 310 | QString const& method, |
602 | @@ -258,6 +312,7 @@ | |||
603 | 258 | { | 312 | { |
604 | 259 | unique_ptr<DownloaderImpl> impl(new DownloaderImpl(item_impl, method, reply)); | 313 | unique_ptr<DownloaderImpl> impl(new DownloaderImpl(item_impl, method, reply)); |
605 | 260 | auto downloader = new Downloader(move(impl)); | 314 | auto downloader = new Downloader(move(impl)); |
606 | 315 | downloader->open(QIODevice::ReadOnly); | ||
607 | 261 | downloader->p_->public_instance_ = downloader; | 316 | downloader->p_->public_instance_ = downloader; |
608 | 262 | return downloader; | 317 | return downloader; |
609 | 263 | } | 318 | } |
610 | @@ -266,6 +321,7 @@ | |||
611 | 266 | { | 321 | { |
612 | 267 | unique_ptr<DownloaderImpl> impl(new DownloaderImpl(e)); | 322 | unique_ptr<DownloaderImpl> impl(new DownloaderImpl(e)); |
613 | 268 | auto downloader = new Downloader(move(impl)); | 323 | auto downloader = new Downloader(move(impl)); |
614 | 324 | downloader->open(QIODevice::ReadOnly); | ||
615 | 269 | downloader->p_->public_instance_ = downloader; | 325 | downloader->p_->public_instance_ = downloader; |
616 | 270 | QMetaObject::invokeMethod(downloader, | 326 | QMetaObject::invokeMethod(downloader, |
617 | 271 | "statusChanged", | 327 | "statusChanged", |
618 | 272 | 328 | ||
619 | === modified file 'src/qt/internal/HandlerBase.cpp' | |||
620 | --- src/qt/internal/HandlerBase.cpp 2016-09-20 04:53:49 +0000 | |||
621 | +++ src/qt/internal/HandlerBase.cpp 2016-11-04 07:34:14 +0000 | |||
622 | @@ -50,6 +50,7 @@ | |||
623 | 50 | void HandlerBase::finished(QDBusPendingCallWatcher* call) | 50 | void HandlerBase::finished(QDBusPendingCallWatcher* call) |
624 | 51 | { | 51 | { |
625 | 52 | deleteLater(); | 52 | deleteLater(); |
626 | 53 | disconnect(&watcher_, &QDBusPendingCallWatcher::finished, this, &HandlerBase::finished); | ||
627 | 53 | closure_(*call); | 54 | closure_(*call); |
628 | 54 | } | 55 | } |
629 | 55 | 56 | ||
630 | 56 | 57 | ||
631 | === modified file 'src/qt/internal/UploaderImpl.cpp' | |||
632 | --- src/qt/internal/UploaderImpl.cpp 2016-10-13 07:59:12 +0000 | |||
633 | +++ src/qt/internal/UploaderImpl.cpp 2016-11-04 07:34:14 +0000 | |||
634 | @@ -19,7 +19,7 @@ | |||
635 | 19 | #include <unity/storage/qt/internal/UploaderImpl.h> | 19 | #include <unity/storage/qt/internal/UploaderImpl.h> |
636 | 20 | 20 | ||
637 | 21 | #include "ProviderInterface.h" | 21 | #include "ProviderInterface.h" |
639 | 22 | #include <unity/storage/qt/internal/Handler.h> | 22 | //#include <unity/storage/qt/internal/Handler.h> |
640 | 23 | #include <unity/storage/qt/internal/ItemImpl.h> | 23 | #include <unity/storage/qt/internal/ItemImpl.h> |
641 | 24 | #include <unity/storage/qt/internal/VoidJobImpl.h> | 24 | #include <unity/storage/qt/internal/VoidJobImpl.h> |
642 | 25 | #include <unity/storage/qt/ItemJob.h> | 25 | #include <unity/storage/qt/ItemJob.h> |
643 | @@ -55,7 +55,7 @@ | |||
644 | 55 | assert(!method.isEmpty()); | 55 | assert(!method.isEmpty()); |
645 | 56 | assert(size_in_bytes >= 0); | 56 | assert(size_in_bytes >= 0); |
646 | 57 | 57 | ||
648 | 58 | auto process_reply = [this, method](decltype(reply)& r) | 58 | auto process_reply = [this, method](QDBusPendingReply<QString, QDBusUnixFileDescriptor>& r) |
649 | 59 | { | 59 | { |
650 | 60 | if (status_ != Uploader::Status::Loading) | 60 | if (status_ != Uploader::Status::Loading) |
651 | 61 | { | 61 | { |
652 | @@ -67,7 +67,7 @@ | |||
653 | 67 | { | 67 | { |
654 | 68 | QString msg = method + ": Runtime was destroyed previously"; | 68 | QString msg = method + ": Runtime was destroyed previously"; |
655 | 69 | error_ = StorageErrorImpl::runtime_destroyed_error(msg); | 69 | error_ = StorageErrorImpl::runtime_destroyed_error(msg); |
657 | 70 | public_instance_->abort(); | 70 | socket_.abort(); |
658 | 71 | public_instance_->setErrorString(msg); | 71 | public_instance_->setErrorString(msg); |
659 | 72 | status_ = Uploader::Status::Error; | 72 | status_ = Uploader::Status::Error; |
660 | 73 | Q_EMIT public_instance_->statusChanged(status_); | 73 | Q_EMIT public_instance_->statusChanged(status_); |
661 | @@ -82,7 +82,7 @@ | |||
662 | 82 | QString msg = method + ": invalid file descriptor returned by provider"; | 82 | QString msg = method + ": invalid file descriptor returned by provider"; |
663 | 83 | qCritical().noquote() << msg; | 83 | qCritical().noquote() << msg; |
664 | 84 | error_ = StorageErrorImpl::local_comms_error(msg); | 84 | error_ = StorageErrorImpl::local_comms_error(msg); |
666 | 85 | public_instance_->abort(); | 85 | socket_.abort(); |
667 | 86 | public_instance_->setErrorString(msg); | 86 | public_instance_->setErrorString(msg); |
668 | 87 | status_ = Uploader::Status::Error; | 87 | status_ = Uploader::Status::Error; |
669 | 88 | Q_EMIT public_instance_->statusChanged(status_); | 88 | Q_EMIT public_instance_->statusChanged(status_); |
670 | @@ -90,7 +90,19 @@ | |||
671 | 90 | // LCOV_EXCL_STOP | 90 | // LCOV_EXCL_STOP |
672 | 91 | } | 91 | } |
673 | 92 | 92 | ||
675 | 93 | public_instance_->setSocketDescriptor(fd_.fileDescriptor(), QLocalSocket::ConnectedState, QIODevice::WriteOnly); | 93 | // We forward any QIODevice signals emitted by the socket to the public instance. |
676 | 94 | connect(&socket_, &QIODevice::aboutToClose, public_instance_, &QIODevice::aboutToClose); | ||
677 | 95 | connect(&socket_, &QIODevice::bytesWritten, public_instance_, &QIODevice::bytesWritten); | ||
678 | 96 | connect(&socket_, &QIODevice::readChannelFinished, public_instance_, &QIODevice::readChannelFinished); | ||
679 | 97 | connect(&socket_, &QIODevice::readyRead, public_instance_, &QIODevice::readyRead); | ||
680 | 98 | |||
681 | 99 | #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) | ||
682 | 100 | connect(&socket_, &QIODevice::channelBytesWritten, public_instance_, &QIODevice::channelBytesWritten); | ||
683 | 101 | connect(&socket_, &QIODevice::channelReadyRead, public_instance_, &QIODevice::channelReadyRead); | ||
684 | 102 | #endif | ||
685 | 103 | |||
686 | 104 | socket_.setSocketDescriptor(fd_.fileDescriptor(), QLocalSocket::ConnectedState, QIODevice::WriteOnly); | ||
687 | 105 | flush_buffer(); | ||
688 | 94 | status_ = Uploader::Status::Ready; | 106 | status_ = Uploader::Status::Ready; |
689 | 95 | Q_EMIT public_instance_->statusChanged(status_); | 107 | Q_EMIT public_instance_->statusChanged(status_); |
690 | 96 | }; | 108 | }; |
691 | @@ -100,12 +112,12 @@ | |||
692 | 100 | // TODO: This does not set the method | 112 | // TODO: This does not set the method |
693 | 101 | error_ = error; | 113 | error_ = error; |
694 | 102 | status_ = Uploader::Status::Error; | 114 | status_ = Uploader::Status::Error; |
696 | 103 | public_instance_->abort(); | 115 | socket_.abort(); |
697 | 104 | public_instance_->setErrorString(error.errorString()); | 116 | public_instance_->setErrorString(error.errorString()); |
698 | 105 | Q_EMIT public_instance_->statusChanged(status_); | 117 | Q_EMIT public_instance_->statusChanged(status_); |
699 | 106 | }; | 118 | }; |
700 | 107 | 119 | ||
702 | 108 | new Handler<storage::internal::ItemMetadata>(this, reply, process_reply, process_error); | 120 | handler_ = new Handler<QDBusPendingReply<QString, QDBusUnixFileDescriptor>>(this, reply, process_reply, process_error); |
703 | 109 | } | 121 | } |
704 | 110 | 122 | ||
705 | 111 | UploaderImpl::UploaderImpl(StorageError const& e) | 123 | UploaderImpl::UploaderImpl(StorageError const& e) |
706 | @@ -165,11 +177,56 @@ | |||
707 | 165 | return Item(item_impl_); | 177 | return Item(item_impl_); |
708 | 166 | } | 178 | } |
709 | 167 | 179 | ||
715 | 168 | void UploaderImpl::finishUpload() | 180 | void UploaderImpl::cancel() |
716 | 169 | { | 181 | { |
717 | 170 | static QString const method = "Uploader::finishUpload()"; | 182 | static QString const method = "Uploader::cancel()"; |
718 | 171 | 183 | ||
719 | 172 | // If we encountered an error earlier or were cancelled, or if finishUpload() was | 184 | // If we are in a final state already, ignore the call. |
720 | 185 | if ( status_ == Uploader::Status::Error | ||
721 | 186 | || status_ == Uploader::Status::Finished | ||
722 | 187 | || status_ == Uploader::Status::Cancelled) | ||
723 | 188 | { | ||
724 | 189 | return; | ||
725 | 190 | } | ||
726 | 191 | auto runtime = item_impl_->runtime_impl(); | ||
727 | 192 | if (!runtime || !runtime->isValid()) | ||
728 | 193 | { | ||
729 | 194 | QString msg = method + ": Runtime was destroyed previously"; | ||
730 | 195 | error_ = StorageErrorImpl::runtime_destroyed_error(msg); | ||
731 | 196 | status_ = Uploader::Status::Error; | ||
732 | 197 | Q_EMIT public_instance_->statusChanged(status_); | ||
733 | 198 | return; | ||
734 | 199 | } | ||
735 | 200 | |||
736 | 201 | if (!upload_id_.isEmpty()) | ||
737 | 202 | { | ||
738 | 203 | // We just send the cancel and ignore any reply because it is best-effort only. | ||
739 | 204 | auto reply = item_impl_->account_impl()->provider()->CancelUpload(upload_id_); | ||
740 | 205 | |||
741 | 206 | auto process_reply = [](decltype(reply)&) | ||
742 | 207 | { | ||
743 | 208 | }; | ||
744 | 209 | |||
745 | 210 | auto process_error = [](StorageError const&) | ||
746 | 211 | { | ||
747 | 212 | }; | ||
748 | 213 | |||
749 | 214 | new Handler<void>(this, reply, process_reply, process_error); | ||
750 | 215 | } | ||
751 | 216 | |||
752 | 217 | QString msg = method + ": upload was cancelled"; | ||
753 | 218 | error_ = StorageErrorImpl::cancelled_error(msg); | ||
754 | 219 | socket_.abort(); | ||
755 | 220 | public_instance_->setErrorString(msg); | ||
756 | 221 | status_ = Uploader::Status::Cancelled; | ||
757 | 222 | Q_EMIT public_instance_->statusChanged(status_); | ||
758 | 223 | } | ||
759 | 224 | |||
760 | 225 | void UploaderImpl::close() | ||
761 | 226 | { | ||
762 | 227 | static QString const method = "Uploader::close()"; | ||
763 | 228 | |||
764 | 229 | // If we encountered an error earlier or were cancelled, or if close() was | ||
765 | 173 | // called already, we ignore the call. | 230 | // called already, we ignore the call. |
766 | 174 | if (status_ == Uploader::Status::Error || status_ == Uploader::Status::Cancelled || finalizing_) | 231 | if (status_ == Uploader::Status::Error || status_ == Uploader::Status::Cancelled || finalizing_) |
767 | 175 | { | 232 | { |
768 | @@ -181,7 +238,7 @@ | |||
769 | 181 | { | 238 | { |
770 | 182 | QString msg = method + ": cannot finalize while Uploader is not in the Ready state"; | 239 | QString msg = method + ": cannot finalize while Uploader is not in the Ready state"; |
771 | 183 | error_ = StorageErrorImpl::logic_error(msg); | 240 | error_ = StorageErrorImpl::logic_error(msg); |
773 | 184 | public_instance_->abort(); | 241 | socket_.abort(); |
774 | 185 | public_instance_->setErrorString(msg); | 242 | public_instance_->setErrorString(msg); |
775 | 186 | status_ = Uploader::Status::Error; | 243 | status_ = Uploader::Status::Error; |
776 | 187 | Q_EMIT public_instance_->statusChanged(status_); | 244 | Q_EMIT public_instance_->statusChanged(status_); |
777 | @@ -199,7 +256,8 @@ | |||
778 | 199 | } | 256 | } |
779 | 200 | 257 | ||
780 | 201 | finalizing_ = true; | 258 | finalizing_ = true; |
782 | 202 | public_instance_->disconnectFromServer(); | 259 | flush_buffer(); |
783 | 260 | socket_.disconnectFromServer(); | ||
784 | 203 | auto reply = item_impl_->account_impl()->provider()->FinishUpload(upload_id_); | 261 | auto reply = item_impl_->account_impl()->provider()->FinishUpload(upload_id_); |
785 | 204 | 262 | ||
786 | 205 | auto process_reply = [this](decltype(reply)& r) | 263 | auto process_reply = [this](decltype(reply)& r) |
787 | @@ -214,7 +272,7 @@ | |||
788 | 214 | { | 272 | { |
789 | 215 | QString msg = method + ": Runtime was destroyed previously"; | 273 | QString msg = method + ": Runtime was destroyed previously"; |
790 | 216 | error_ = StorageErrorImpl::runtime_destroyed_error(msg); | 274 | error_ = StorageErrorImpl::runtime_destroyed_error(msg); |
792 | 217 | public_instance_->abort(); | 275 | socket_.abort(); |
793 | 218 | public_instance_->setErrorString(msg); | 276 | public_instance_->setErrorString(msg); |
794 | 219 | status_ = Uploader::Status::Error; | 277 | status_ = Uploader::Status::Error; |
795 | 220 | Q_EMIT public_instance_->statusChanged(status_); | 278 | Q_EMIT public_instance_->statusChanged(status_); |
796 | @@ -247,7 +305,7 @@ | |||
797 | 247 | 305 | ||
798 | 248 | // TODO: this doesn't set the method | 306 | // TODO: this doesn't set the method |
799 | 249 | error_ = error; | 307 | error_ = error; |
801 | 250 | public_instance_->abort(); | 308 | socket_.abort(); |
802 | 251 | public_instance_->setErrorString(error.errorString()); | 309 | public_instance_->setErrorString(error.errorString()); |
803 | 252 | status_ = Uploader::Status::Error; | 310 | status_ = Uploader::Status::Error; |
804 | 253 | Q_EMIT public_instance_->statusChanged(status_); | 311 | Q_EMIT public_instance_->statusChanged(status_); |
805 | @@ -256,49 +314,85 @@ | |||
806 | 256 | new Handler<void>(this, reply, process_reply, process_error); | 314 | new Handler<void>(this, reply, process_reply, process_error); |
807 | 257 | } | 315 | } |
808 | 258 | 316 | ||
852 | 259 | void UploaderImpl::cancel() | 317 | qint64 UploaderImpl::bytesAvailable() const |
853 | 260 | { | 318 | { |
854 | 261 | static QString const method = "Uploader::cancel()"; | 319 | return socket_.bytesAvailable(); |
855 | 262 | 320 | } | |
856 | 263 | // If we are in a final state already, ignore the call. | 321 | |
857 | 264 | if ( status_ == Uploader::Status::Error | 322 | qint64 UploaderImpl::bytesToWrite() const |
858 | 265 | || status_ == Uploader::Status::Finished | 323 | { |
859 | 266 | || status_ == Uploader::Status::Cancelled) | 324 | return socket_.bytesToWrite(); |
860 | 267 | { | 325 | } |
861 | 268 | return; | 326 | |
862 | 269 | } | 327 | bool UploaderImpl::canReadLine() const |
863 | 270 | auto runtime = item_impl_->runtime_impl(); | 328 | { |
864 | 271 | if (!runtime || !runtime->isValid()) | 329 | return socket_.canReadLine(); |
865 | 272 | { | 330 | } |
866 | 273 | QString msg = method + ": Runtime was destroyed previously"; | 331 | |
867 | 274 | error_ = StorageErrorImpl::runtime_destroyed_error(msg); | 332 | bool UploaderImpl::isSequential() const |
868 | 275 | status_ = Uploader::Status::Error; | 333 | { |
869 | 276 | Q_EMIT public_instance_->statusChanged(status_); | 334 | return socket_.isSequential(); |
870 | 277 | return; | 335 | } |
871 | 278 | } | 336 | |
872 | 279 | 337 | bool UploaderImpl::waitForBytesWritten(int msecs) | |
873 | 280 | if (!upload_id_.isEmpty()) | 338 | { |
874 | 281 | { | 339 | if (status_ == Uploader::Status::Loading) |
875 | 282 | // We just send the cancel and ignore any reply because it is best-effort only. | 340 | { |
876 | 283 | auto reply = item_impl_->account_impl()->provider()->CancelUpload(upload_id_); | 341 | // Unfortunately, QDBusPendingReply::waitForFinished() does not accept a timeout. |
877 | 284 | 342 | // The next-best thing we can do is to simply wait without a timeout. The DBus | |
878 | 285 | auto process_reply = [](decltype(reply)&) | 343 | // method will finish eventually, even though it might take a lot longer than msecs. |
879 | 286 | { | 344 | handler_->wait_and_process_now(); |
880 | 287 | }; | 345 | } |
881 | 288 | 346 | if (flush_buffer() == -1) | |
882 | 289 | auto process_error = [](StorageError const&) | 347 | { |
883 | 290 | { | 348 | return false; |
884 | 291 | }; | 349 | } |
885 | 292 | 350 | return socket_.waitForBytesWritten(msecs); | |
886 | 293 | new Handler<void>(this, reply, process_reply, process_error); | 351 | } |
887 | 294 | } | 352 | |
888 | 295 | 353 | bool UploaderImpl::waitForReadyRead(int msecs) | |
889 | 296 | QString msg = method + ": upload was cancelled"; | 354 | { |
890 | 297 | error_ = StorageErrorImpl::cancelled_error(msg); | 355 | return socket_.waitForReadyRead(msecs); |
891 | 298 | public_instance_->abort(); | 356 | } |
892 | 299 | public_instance_->setErrorString(msg); | 357 | |
893 | 300 | status_ = Uploader::Status::Cancelled; | 358 | // LCOV_EXCL_START |
894 | 301 | Q_EMIT public_instance_->statusChanged(status_); | 359 | // Never called by QIODevice because device is opened write-only. |
895 | 360 | qint64 UploaderImpl::readData(char* data, qint64 c) | ||
896 | 361 | { | ||
897 | 362 | return socket_.read(data, c); | ||
898 | 363 | } | ||
899 | 364 | // LCOV_EXCL_STOP | ||
900 | 365 | |||
901 | 366 | qint64 UploaderImpl::writeData(char const* data, qint64 c) | ||
902 | 367 | { | ||
903 | 368 | switch (status_) | ||
904 | 369 | { | ||
905 | 370 | case Uploader::Status::Loading: | ||
906 | 371 | { | ||
907 | 372 | // Client is writing before we have received the file descriptor from the provider. | ||
908 | 373 | buffer_.append(data, c); | ||
909 | 374 | return c; | ||
910 | 375 | } | ||
911 | 376 | case Uploader::Status::Ready: | ||
912 | 377 | { | ||
913 | 378 | if (flush_buffer() == -1) | ||
914 | 379 | { | ||
915 | 380 | return -1; | ||
916 | 381 | } | ||
917 | 382 | return socket_.write(data, c); | ||
918 | 383 | } | ||
919 | 384 | case Uploader::Status::Cancelled: | ||
920 | 385 | case Uploader::Status::Finished: | ||
921 | 386 | case Uploader::Status::Error: | ||
922 | 387 | { | ||
923 | 388 | return -1; // Can't write to an already-finalized uploader. | ||
924 | 389 | } | ||
925 | 390 | default: | ||
926 | 391 | { | ||
927 | 392 | abort(); // Impossible // LCOV_EXCL_LINE | ||
928 | 393 | } | ||
929 | 394 | } | ||
930 | 395 | // NOTREACHED | ||
931 | 302 | } | 396 | } |
932 | 303 | 397 | ||
933 | 304 | Uploader* UploaderImpl::make_job(shared_ptr<ItemImpl> const& item_impl, | 398 | Uploader* UploaderImpl::make_job(shared_ptr<ItemImpl> const& item_impl, |
934 | @@ -310,6 +404,7 @@ | |||
935 | 310 | { | 404 | { |
936 | 311 | unique_ptr<UploaderImpl> impl(new UploaderImpl(item_impl, method, reply, validate, policy, size_in_bytes)); | 405 | unique_ptr<UploaderImpl> impl(new UploaderImpl(item_impl, method, reply, validate, policy, size_in_bytes)); |
937 | 312 | auto uploader = new Uploader(move(impl)); | 406 | auto uploader = new Uploader(move(impl)); |
938 | 407 | uploader->open(QIODevice::WriteOnly); | ||
939 | 313 | uploader->p_->public_instance_ = uploader; | 408 | uploader->p_->public_instance_ = uploader; |
940 | 314 | return uploader; | 409 | return uploader; |
941 | 315 | } | 410 | } |
942 | @@ -318,6 +413,7 @@ | |||
943 | 318 | { | 413 | { |
944 | 319 | unique_ptr<UploaderImpl> impl(new UploaderImpl(e)); | 414 | unique_ptr<UploaderImpl> impl(new UploaderImpl(e)); |
945 | 320 | auto uploader = new Uploader(move(impl)); | 415 | auto uploader = new Uploader(move(impl)); |
946 | 416 | uploader->open(QIODevice::WriteOnly); | ||
947 | 321 | uploader->p_->public_instance_ = uploader; | 417 | uploader->p_->public_instance_ = uploader; |
948 | 322 | QMetaObject::invokeMethod(uploader, | 418 | QMetaObject::invokeMethod(uploader, |
949 | 323 | "statusChanged", | 419 | "statusChanged", |
950 | @@ -326,6 +422,22 @@ | |||
951 | 326 | return uploader; | 422 | return uploader; |
952 | 327 | } | 423 | } |
953 | 328 | 424 | ||
954 | 425 | qint64 UploaderImpl::flush_buffer() | ||
955 | 426 | { | ||
956 | 427 | qint64 bytes_written = 0; | ||
957 | 428 | auto bytes_to_write = buffer_.size(); | ||
958 | 429 | if (bytes_to_write > 0) | ||
959 | 430 | { | ||
960 | 431 | auto bytes_written = socket_.write(buffer_.data(), bytes_to_write); | ||
961 | 432 | if (bytes_written != bytes_to_write) | ||
962 | 433 | { | ||
963 | 434 | return -1; // Not exactly detailed, but that's the best we can do. // LCOV_EXCL_LINE | ||
964 | 435 | } | ||
965 | 436 | buffer_.resize(0); | ||
966 | 437 | } | ||
967 | 438 | return bytes_written; | ||
968 | 439 | } | ||
969 | 440 | |||
970 | 329 | } // namespace internal | 441 | } // namespace internal |
971 | 330 | } // namespace qt | 442 | } // namespace qt |
972 | 331 | } // namespace storage | 443 | } // namespace storage |
973 | 332 | 444 | ||
974 | === modified file 'tests/remote-client/MockProvider.cpp' | |||
975 | --- tests/remote-client/MockProvider.cpp 2016-11-03 03:41:24 +0000 | |||
976 | +++ tests/remote-client/MockProvider.cpp 2016-11-04 07:34:14 +0000 | |||
977 | @@ -194,9 +194,9 @@ | |||
978 | 194 | ++num_calls; | 194 | ++num_calls; |
979 | 195 | switch (num_calls) | 195 | switch (num_calls) |
980 | 196 | { | 196 | { |
981 | 197 | case 2: | ||
982 | 198 | return make_exceptional_future<Item>(ResourceException("metadata(): weird error", 42)); | ||
983 | 197 | case 3: | 199 | case 3: |
984 | 198 | return make_exceptional_future<Item>(ResourceException("metadata(): weird error", 42)); | ||
985 | 199 | case 4: | ||
986 | 200 | num_calls = 0; | 200 | num_calls = 0; |
987 | 201 | return make_exceptional_future<Item>(RemoteCommsException("metadata(): HTTP broken")); | 201 | return make_exceptional_future<Item>(RemoteCommsException("metadata(): HTTP broken")); |
988 | 202 | default: | 202 | default: |
989 | @@ -207,14 +207,8 @@ | |||
990 | 207 | { | 207 | { |
991 | 208 | if (cmd_ == "bad_parent_metadata_from_child") | 208 | if (cmd_ == "bad_parent_metadata_from_child") |
992 | 209 | { | 209 | { |
1001 | 210 | ++num_calls; | 210 | Item metadata{"root_id", {}, "Root", "etag", ItemType::file, {}}; |
1002 | 211 | if (num_calls == 2) | 211 | return make_ready_future<Item>(metadata); |
995 | 212 | { | ||
996 | 213 | num_calls = 0; | ||
997 | 214 | // On second call, we return type file for the root. | ||
998 | 215 | Item metadata{"root_id", {}, "Root", "etag", ItemType::file, {}}; | ||
999 | 216 | return make_ready_future<Item>(metadata); | ||
1000 | 217 | } | ||
1003 | 218 | } | 212 | } |
1004 | 219 | if (cmd_ == "root_with_parent") | 213 | if (cmd_ == "root_with_parent") |
1005 | 220 | { | 214 | { |
1006 | 221 | 215 | ||
1007 | === modified file 'tests/remote-client/remote-client_test.cpp' | |||
1008 | --- tests/remote-client/remote-client_test.cpp 2016-11-03 07:33:40 +0000 | |||
1009 | +++ tests/remote-client/remote-client_test.cpp 2016-11-04 07:34:14 +0000 | |||
1010 | @@ -1310,14 +1310,6 @@ | |||
1011 | 1310 | { | 1310 | { |
1012 | 1311 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("two_parents"))); | 1311 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("two_parents"))); |
1013 | 1312 | 1312 | ||
1014 | 1313 | Item root; | ||
1015 | 1314 | { | ||
1016 | 1315 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1017 | 1316 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1018 | 1317 | spy.wait(SIGNAL_WAIT_TIME); | ||
1019 | 1318 | root = j->item(); | ||
1020 | 1319 | } | ||
1021 | 1320 | |||
1022 | 1321 | Item child; | 1313 | Item child; |
1023 | 1322 | { | 1314 | { |
1024 | 1323 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 1315 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1025 | @@ -1364,14 +1356,6 @@ | |||
1026 | 1364 | { | 1356 | { |
1027 | 1365 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("two_parents_throw"))); | 1357 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("two_parents_throw"))); |
1028 | 1366 | 1358 | ||
1029 | 1367 | Item root; | ||
1030 | 1368 | { | ||
1031 | 1369 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1032 | 1370 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1033 | 1371 | spy.wait(SIGNAL_WAIT_TIME); | ||
1034 | 1372 | root = j->item(); | ||
1035 | 1373 | } | ||
1036 | 1374 | |||
1037 | 1375 | Item child; | 1359 | Item child; |
1038 | 1376 | { | 1360 | { |
1039 | 1377 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 1361 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1040 | @@ -1455,14 +1439,6 @@ | |||
1041 | 1455 | { | 1439 | { |
1042 | 1456 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("slow_metadata"))); | 1440 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("slow_metadata"))); |
1043 | 1457 | 1441 | ||
1044 | 1458 | Item root; | ||
1045 | 1459 | { | ||
1046 | 1460 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1047 | 1461 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1048 | 1462 | spy.wait(SIGNAL_WAIT_TIME); | ||
1049 | 1463 | root = j->item(); | ||
1050 | 1464 | } | ||
1051 | 1465 | |||
1052 | 1466 | Item child; | 1442 | Item child; |
1053 | 1467 | { | 1443 | { |
1054 | 1468 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 1444 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1055 | @@ -1489,14 +1465,6 @@ | |||
1056 | 1489 | { | 1465 | { |
1057 | 1490 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("bad_parent_metadata_from_child"))); | 1466 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("bad_parent_metadata_from_child"))); |
1058 | 1491 | 1467 | ||
1059 | 1492 | Item root; | ||
1060 | 1493 | { | ||
1061 | 1494 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1062 | 1495 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1063 | 1496 | spy.wait(SIGNAL_WAIT_TIME); | ||
1064 | 1497 | root = j->item(); | ||
1065 | 1498 | } | ||
1066 | 1499 | |||
1067 | 1500 | Item child; | 1468 | Item child; |
1068 | 1501 | { | 1469 | { |
1069 | 1502 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 1470 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1070 | @@ -1600,14 +1568,6 @@ | |||
1071 | 1600 | { | 1568 | { |
1072 | 1601 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 1569 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1073 | 1602 | 1570 | ||
1074 | 1603 | Item root; | ||
1075 | 1604 | { | ||
1076 | 1605 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1077 | 1606 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1078 | 1607 | spy.wait(SIGNAL_WAIT_TIME); | ||
1079 | 1608 | root = j->item(); | ||
1080 | 1609 | } | ||
1081 | 1610 | |||
1082 | 1611 | Item child; | 1571 | Item child; |
1083 | 1612 | { | 1572 | { |
1084 | 1613 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 1573 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1085 | @@ -1731,14 +1691,6 @@ | |||
1086 | 1731 | { | 1691 | { |
1087 | 1732 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 1692 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1088 | 1733 | 1693 | ||
1089 | 1734 | Item root; | ||
1090 | 1735 | { | ||
1091 | 1736 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1092 | 1737 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1093 | 1738 | spy.wait(SIGNAL_WAIT_TIME); | ||
1094 | 1739 | root = j->item(); | ||
1095 | 1740 | } | ||
1096 | 1741 | |||
1097 | 1742 | Item child; | 1694 | Item child; |
1098 | 1743 | { | 1695 | { |
1099 | 1744 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 1696 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1100 | @@ -2014,14 +1966,6 @@ | |||
1101 | 2014 | { | 1966 | { |
1102 | 2015 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 1967 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1103 | 2016 | 1968 | ||
1104 | 2017 | Item root; | ||
1105 | 2018 | { | ||
1106 | 2019 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1107 | 2020 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1108 | 2021 | spy.wait(SIGNAL_WAIT_TIME); | ||
1109 | 2022 | root = j->item(); | ||
1110 | 2023 | } | ||
1111 | 2024 | |||
1112 | 2025 | Item child; | 1969 | Item child; |
1113 | 2026 | { | 1970 | { |
1114 | 2027 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 1971 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1115 | @@ -2102,14 +2046,6 @@ | |||
1116 | 2102 | { | 2046 | { |
1117 | 2103 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 2047 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1118 | 2104 | 2048 | ||
1119 | 2105 | Item root; | ||
1120 | 2106 | { | ||
1121 | 2107 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1122 | 2108 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1123 | 2109 | spy.wait(SIGNAL_WAIT_TIME); | ||
1124 | 2110 | root = j->item(); | ||
1125 | 2111 | } | ||
1126 | 2112 | |||
1127 | 2113 | Item child; | 2049 | Item child; |
1128 | 2114 | { | 2050 | { |
1129 | 2115 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2051 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1130 | @@ -2320,14 +2256,6 @@ | |||
1131 | 2320 | { | 2256 | { |
1132 | 2321 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 2257 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1133 | 2322 | 2258 | ||
1134 | 2323 | Item root; | ||
1135 | 2324 | { | ||
1136 | 2325 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1137 | 2326 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1138 | 2327 | spy.wait(SIGNAL_WAIT_TIME); | ||
1139 | 2328 | root = j->item(); | ||
1140 | 2329 | } | ||
1141 | 2330 | |||
1142 | 2331 | Item child; | 2259 | Item child; |
1143 | 2332 | { | 2260 | { |
1144 | 2333 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2261 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1145 | @@ -2434,14 +2362,6 @@ | |||
1146 | 2434 | { | 2362 | { |
1147 | 2435 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 2363 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1148 | 2436 | 2364 | ||
1149 | 2437 | Item root; | ||
1150 | 2438 | { | ||
1151 | 2439 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1152 | 2440 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1153 | 2441 | spy.wait(SIGNAL_WAIT_TIME); | ||
1154 | 2442 | root = j->item(); | ||
1155 | 2443 | } | ||
1156 | 2444 | |||
1157 | 2445 | Item child; | 2365 | Item child; |
1158 | 2446 | { | 2366 | { |
1159 | 2447 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2367 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1160 | @@ -2468,10 +2388,17 @@ | |||
1161 | 2468 | read_spy.wait(SIGNAL_WAIT_TIME); | 2388 | read_spy.wait(SIGNAL_WAIT_TIME); |
1162 | 2469 | } | 2389 | } |
1163 | 2470 | } | 2390 | } |
1164 | 2391 | |||
1165 | 2392 | EXPECT_EQ(11, downloader->bytesAvailable()); | ||
1166 | 2393 | EXPECT_EQ(0, downloader->bytesToWrite()); | ||
1167 | 2394 | EXPECT_EQ(-1, downloader->write("a", 1)); | ||
1168 | 2395 | EXPECT_FALSE(downloader->waitForBytesWritten(1)); | ||
1169 | 2396 | EXPECT_FALSE(downloader->waitForReadyRead(1)); | ||
1170 | 2397 | |||
1171 | 2471 | auto data = downloader->readAll(); | 2398 | auto data = downloader->readAll(); |
1172 | 2472 | EXPECT_EQ(QByteArray("Hello world", -1), data); | 2399 | EXPECT_EQ(QByteArray("Hello world", -1), data); |
1173 | 2473 | 2400 | ||
1175 | 2474 | downloader->finishDownload(); | 2401 | downloader->close(); |
1176 | 2475 | ASSERT_TRUE(status_spy.wait(SIGNAL_WAIT_TIME)); | 2402 | ASSERT_TRUE(status_spy.wait(SIGNAL_WAIT_TIME)); |
1177 | 2476 | auto arg = status_spy.takeFirst(); | 2403 | auto arg = status_spy.takeFirst(); |
1178 | 2477 | EXPECT_EQ(Downloader::Status::Finished, qvariant_cast<Downloader::Status>(arg.at(0))); | 2404 | EXPECT_EQ(Downloader::Status::Finished, qvariant_cast<Downloader::Status>(arg.at(0))); |
1179 | @@ -2496,14 +2423,6 @@ | |||
1180 | 2496 | { | 2423 | { |
1181 | 2497 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 2424 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1182 | 2498 | 2425 | ||
1183 | 2499 | Item root; | ||
1184 | 2500 | { | ||
1185 | 2501 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1186 | 2502 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1187 | 2503 | spy.wait(SIGNAL_WAIT_TIME); | ||
1188 | 2504 | root = j->item(); | ||
1189 | 2505 | } | ||
1190 | 2506 | |||
1191 | 2507 | Item child; | 2426 | Item child; |
1192 | 2508 | { | 2427 | { |
1193 | 2509 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2428 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1194 | @@ -2521,20 +2440,14 @@ | |||
1195 | 2521 | auto arg = spy.takeFirst(); | 2440 | auto arg = spy.takeFirst(); |
1196 | 2522 | EXPECT_EQ(Downloader::Status::Ready, qvariant_cast<Downloader::Status>(arg.at(0))); | 2441 | EXPECT_EQ(Downloader::Status::Ready, qvariant_cast<Downloader::Status>(arg.at(0))); |
1197 | 2523 | } | 2442 | } |
1198 | 2443 | |||
1199 | 2444 | EXPECT_TRUE(downloader->waitForReadyRead(SIGNAL_WAIT_TIME)); | ||
1200 | 2524 | } | 2445 | } |
1201 | 2525 | 2446 | ||
1202 | 2526 | TEST_F(DownloadTest, runtime_destroyed) | 2447 | TEST_F(DownloadTest, runtime_destroyed) |
1203 | 2527 | { | 2448 | { |
1204 | 2528 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 2449 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1205 | 2529 | 2450 | ||
1206 | 2530 | Item root; | ||
1207 | 2531 | { | ||
1208 | 2532 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1209 | 2533 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1210 | 2534 | spy.wait(SIGNAL_WAIT_TIME); | ||
1211 | 2535 | root = j->item(); | ||
1212 | 2536 | } | ||
1213 | 2537 | |||
1214 | 2538 | Item child; | 2451 | Item child; |
1215 | 2539 | { | 2452 | { |
1216 | 2540 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2453 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1217 | @@ -2566,14 +2479,6 @@ | |||
1218 | 2566 | { | 2479 | { |
1219 | 2567 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("download_slow"))); | 2480 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("download_slow"))); |
1220 | 2568 | 2481 | ||
1221 | 2569 | Item root; | ||
1222 | 2570 | { | ||
1223 | 2571 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1224 | 2572 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1225 | 2573 | spy.wait(SIGNAL_WAIT_TIME); | ||
1226 | 2574 | root = j->item(); | ||
1227 | 2575 | } | ||
1228 | 2576 | |||
1229 | 2577 | Item child; | 2482 | Item child; |
1230 | 2578 | { | 2483 | { |
1231 | 2579 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2484 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1232 | @@ -2607,14 +2512,6 @@ | |||
1233 | 2607 | { | 2512 | { |
1234 | 2608 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("download_error"))); | 2513 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("download_error"))); |
1235 | 2609 | 2514 | ||
1236 | 2610 | Item root; | ||
1237 | 2611 | { | ||
1238 | 2612 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1239 | 2613 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1240 | 2614 | spy.wait(SIGNAL_WAIT_TIME); | ||
1241 | 2615 | root = j->item(); | ||
1242 | 2616 | } | ||
1243 | 2617 | |||
1244 | 2618 | Item child; | 2515 | Item child; |
1245 | 2619 | { | 2516 | { |
1246 | 2620 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2517 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1247 | @@ -2641,10 +2538,10 @@ | |||
1248 | 2641 | EXPECT_EQ(42, downloader->error().errorCode()); | 2538 | EXPECT_EQ(42, downloader->error().errorCode()); |
1249 | 2642 | EXPECT_EQ(Item(), downloader->item()); | 2539 | EXPECT_EQ(Item(), downloader->item()); |
1250 | 2643 | 2540 | ||
1252 | 2644 | // For coverage: call finishDownload() while in the Error state. | 2541 | // For coverage: call close() while in the Error state. |
1253 | 2645 | { | 2542 | { |
1254 | 2646 | QSignalSpy spy(downloader.get(), &Downloader::statusChanged); | 2543 | QSignalSpy spy(downloader.get(), &Downloader::statusChanged); |
1256 | 2647 | downloader->finishDownload(); | 2544 | downloader->close(); |
1257 | 2648 | EXPECT_FALSE(spy.wait(1000)); | 2545 | EXPECT_FALSE(spy.wait(1000)); |
1258 | 2649 | } | 2546 | } |
1259 | 2650 | } | 2547 | } |
1260 | @@ -2653,14 +2550,6 @@ | |||
1261 | 2653 | { | 2550 | { |
1262 | 2654 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 2551 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1263 | 2655 | 2552 | ||
1264 | 2656 | Item root; | ||
1265 | 2657 | { | ||
1266 | 2658 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1267 | 2659 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1268 | 2660 | spy.wait(SIGNAL_WAIT_TIME); | ||
1269 | 2661 | root = j->item(); | ||
1270 | 2662 | } | ||
1271 | 2663 | |||
1272 | 2664 | Item child; | 2553 | Item child; |
1273 | 2665 | { | 2554 | { |
1274 | 2666 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2555 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1275 | @@ -2674,7 +2563,7 @@ | |||
1276 | 2674 | 2563 | ||
1277 | 2675 | QSignalSpy spy(downloader.get(), &Downloader::statusChanged); | 2564 | QSignalSpy spy(downloader.get(), &Downloader::statusChanged); |
1278 | 2676 | 2565 | ||
1280 | 2677 | downloader->finishDownload(); | 2566 | downloader->close(); |
1281 | 2678 | 2567 | ||
1282 | 2679 | ASSERT_EQ(1, spy.count()); | 2568 | ASSERT_EQ(1, spy.count()); |
1283 | 2680 | auto arg = spy.takeFirst(); | 2569 | auto arg = spy.takeFirst(); |
1284 | @@ -2683,7 +2572,7 @@ | |||
1285 | 2683 | EXPECT_FALSE(downloader->isValid()); | 2572 | EXPECT_FALSE(downloader->isValid()); |
1286 | 2684 | EXPECT_EQ(Downloader::Status::Error, downloader->status()); | 2573 | EXPECT_EQ(Downloader::Status::Error, downloader->status()); |
1287 | 2685 | EXPECT_EQ(StorageError::LogicError, downloader->error().type()); | 2574 | EXPECT_EQ(StorageError::LogicError, downloader->error().type()); |
1289 | 2686 | EXPECT_EQ("LogicError: Downloader::finishDownload(): cannot finalize while Downloader is not in the Ready state", | 2575 | EXPECT_EQ("LogicError: Downloader::close(): cannot finalize while Downloader is not in the Ready state", |
1290 | 2687 | downloader->error().errorString()); | 2576 | downloader->error().errorString()); |
1291 | 2688 | } | 2577 | } |
1292 | 2689 | 2578 | ||
1293 | @@ -2691,14 +2580,6 @@ | |||
1294 | 2691 | { | 2580 | { |
1295 | 2692 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 2581 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1296 | 2693 | 2582 | ||
1297 | 2694 | Item root; | ||
1298 | 2695 | { | ||
1299 | 2696 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1300 | 2697 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1301 | 2698 | spy.wait(SIGNAL_WAIT_TIME); | ||
1302 | 2699 | root = j->item(); | ||
1303 | 2700 | } | ||
1304 | 2701 | |||
1305 | 2702 | Item child; | 2583 | Item child; |
1306 | 2703 | { | 2584 | { |
1307 | 2704 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2585 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1308 | @@ -2721,7 +2602,7 @@ | |||
1309 | 2721 | 2602 | ||
1310 | 2722 | EXPECT_EQ(StorageError::Type::NoError, runtime_->shutdown().type()); // Destroy runtime | 2603 | EXPECT_EQ(StorageError::Type::NoError, runtime_->shutdown().type()); // Destroy runtime |
1311 | 2723 | 2604 | ||
1313 | 2724 | downloader->finishDownload(); | 2605 | downloader->close(); |
1314 | 2725 | 2606 | ||
1315 | 2726 | ASSERT_EQ(1, spy.count()); | 2607 | ASSERT_EQ(1, spy.count()); |
1316 | 2727 | auto arg = spy.takeFirst(); | 2608 | auto arg = spy.takeFirst(); |
1317 | @@ -2730,21 +2611,13 @@ | |||
1318 | 2730 | EXPECT_FALSE(downloader->isValid()); | 2611 | EXPECT_FALSE(downloader->isValid()); |
1319 | 2731 | EXPECT_EQ(Downloader::Status::Error, downloader->status()); | 2612 | EXPECT_EQ(Downloader::Status::Error, downloader->status()); |
1320 | 2732 | EXPECT_EQ(StorageError::RuntimeDestroyed, downloader->error().type()); | 2613 | EXPECT_EQ(StorageError::RuntimeDestroyed, downloader->error().type()); |
1322 | 2733 | EXPECT_EQ("Downloader::finishDownload(): Runtime was destroyed previously", downloader->error().message()); | 2614 | EXPECT_EQ("Downloader::close(): Runtime was destroyed previously", downloader->error().message()); |
1323 | 2734 | } | 2615 | } |
1324 | 2735 | 2616 | ||
1325 | 2736 | TEST_F(DownloadTest, finish_runtime_destroyed_while_reply_outstanding) | 2617 | TEST_F(DownloadTest, finish_runtime_destroyed_while_reply_outstanding) |
1326 | 2737 | { | 2618 | { |
1327 | 2738 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_download_slow"))); | 2619 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_download_slow"))); |
1328 | 2739 | 2620 | ||
1329 | 2740 | Item root; | ||
1330 | 2741 | { | ||
1331 | 2742 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1332 | 2743 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1333 | 2744 | spy.wait(SIGNAL_WAIT_TIME); | ||
1334 | 2745 | root = j->item(); | ||
1335 | 2746 | } | ||
1336 | 2747 | |||
1337 | 2748 | Item child; | 2621 | Item child; |
1338 | 2749 | { | 2622 | { |
1339 | 2750 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2623 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1340 | @@ -2765,7 +2638,7 @@ | |||
1341 | 2765 | 2638 | ||
1342 | 2766 | QSignalSpy spy(downloader.get(), &Downloader::statusChanged); | 2639 | QSignalSpy spy(downloader.get(), &Downloader::statusChanged); |
1343 | 2767 | 2640 | ||
1345 | 2768 | downloader->finishDownload(); | 2641 | downloader->close(); |
1346 | 2769 | 2642 | ||
1347 | 2770 | EXPECT_EQ(StorageError::Type::NoError, runtime_->shutdown().type()); // Destroy runtime, provider still sleeping | 2643 | EXPECT_EQ(StorageError::Type::NoError, runtime_->shutdown().type()); // Destroy runtime, provider still sleeping |
1348 | 2771 | 2644 | ||
1349 | @@ -2776,21 +2649,13 @@ | |||
1350 | 2776 | EXPECT_FALSE(downloader->isValid()); | 2649 | EXPECT_FALSE(downloader->isValid()); |
1351 | 2777 | EXPECT_EQ(Downloader::Status::Error, downloader->status()); | 2650 | EXPECT_EQ(Downloader::Status::Error, downloader->status()); |
1352 | 2778 | EXPECT_EQ(StorageError::RuntimeDestroyed, downloader->error().type()); | 2651 | EXPECT_EQ(StorageError::RuntimeDestroyed, downloader->error().type()); |
1354 | 2779 | EXPECT_EQ("Downloader::finishDownload(): Runtime was destroyed previously", downloader->error().message()); | 2652 | EXPECT_EQ("Downloader::close(): Runtime was destroyed previously", downloader->error().message()); |
1355 | 2780 | } | 2653 | } |
1356 | 2781 | 2654 | ||
1357 | 2782 | TEST_F(DownloadTest, finish_twice) | 2655 | TEST_F(DownloadTest, finish_twice) |
1358 | 2783 | { | 2656 | { |
1359 | 2784 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 2657 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1360 | 2785 | 2658 | ||
1361 | 2786 | Item root; | ||
1362 | 2787 | { | ||
1363 | 2788 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1364 | 2789 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1365 | 2790 | spy.wait(SIGNAL_WAIT_TIME); | ||
1366 | 2791 | root = j->item(); | ||
1367 | 2792 | } | ||
1368 | 2793 | |||
1369 | 2794 | Item child; | 2659 | Item child; |
1370 | 2795 | { | 2660 | { |
1371 | 2796 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2661 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1372 | @@ -2811,8 +2676,8 @@ | |||
1373 | 2811 | 2676 | ||
1374 | 2812 | QSignalSpy spy(downloader.get(), &Downloader::statusChanged); | 2677 | QSignalSpy spy(downloader.get(), &Downloader::statusChanged); |
1375 | 2813 | 2678 | ||
1378 | 2814 | downloader->finishDownload(); | 2679 | downloader->close(); |
1379 | 2815 | downloader->finishDownload(); | 2680 | downloader->close(); |
1380 | 2816 | 2681 | ||
1381 | 2817 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | 2682 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); |
1382 | 2818 | auto arg = spy.takeFirst(); | 2683 | auto arg = spy.takeFirst(); |
1383 | @@ -2825,14 +2690,6 @@ | |||
1384 | 2825 | { | 2690 | { |
1385 | 2826 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_download_error"))); | 2691 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_download_error"))); |
1386 | 2827 | 2692 | ||
1387 | 2828 | Item root; | ||
1388 | 2829 | { | ||
1389 | 2830 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1390 | 2831 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1391 | 2832 | spy.wait(SIGNAL_WAIT_TIME); | ||
1392 | 2833 | root = j->item(); | ||
1393 | 2834 | } | ||
1394 | 2835 | |||
1395 | 2836 | Item child; | 2693 | Item child; |
1396 | 2837 | { | 2694 | { |
1397 | 2838 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2695 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1398 | @@ -2853,7 +2710,7 @@ | |||
1399 | 2853 | 2710 | ||
1400 | 2854 | QSignalSpy spy(downloader.get(), &Downloader::statusChanged); | 2711 | QSignalSpy spy(downloader.get(), &Downloader::statusChanged); |
1401 | 2855 | 2712 | ||
1403 | 2856 | downloader->finishDownload(); | 2713 | downloader->close(); |
1404 | 2857 | 2714 | ||
1405 | 2858 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | 2715 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); |
1406 | 2859 | auto arg = spy.takeFirst(); | 2716 | auto arg = spy.takeFirst(); |
1407 | @@ -2925,14 +2782,6 @@ | |||
1408 | 2925 | { | 2782 | { |
1409 | 2926 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_download_slow_error"))); | 2783 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_download_slow_error"))); |
1410 | 2927 | 2784 | ||
1411 | 2928 | Item root; | ||
1412 | 2929 | { | ||
1413 | 2930 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1414 | 2931 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1415 | 2932 | spy.wait(SIGNAL_WAIT_TIME); | ||
1416 | 2933 | root = j->item(); | ||
1417 | 2934 | } | ||
1418 | 2935 | |||
1419 | 2936 | Item child; | 2785 | Item child; |
1420 | 2937 | { | 2786 | { |
1421 | 2938 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2787 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1422 | @@ -2953,12 +2802,12 @@ | |||
1423 | 2953 | 2802 | ||
1424 | 2954 | QSignalSpy spy(downloader.get(), &Downloader::statusChanged); | 2803 | QSignalSpy spy(downloader.get(), &Downloader::statusChanged); |
1425 | 2955 | 2804 | ||
1427 | 2956 | downloader->finishDownload(); | 2805 | downloader->close(); |
1428 | 2957 | 2806 | ||
1429 | 2958 | downloader->cancel(); | 2807 | downloader->cancel(); |
1430 | 2959 | downloader->cancel(); // Second time for coverage | 2808 | downloader->cancel(); // Second time for coverage |
1431 | 2960 | 2809 | ||
1433 | 2961 | downloader->finishDownload(); // Second time for coverage | 2810 | downloader->close(); // Second time for coverage |
1434 | 2962 | 2811 | ||
1435 | 2963 | EXPECT_EQ(1, spy.count()); | 2812 | EXPECT_EQ(1, spy.count()); |
1436 | 2964 | auto arg = spy.takeFirst(); | 2813 | auto arg = spy.takeFirst(); |
1437 | @@ -2968,7 +2817,7 @@ | |||
1438 | 2968 | EXPECT_EQ(StorageError::Type::Cancelled, downloader->error().type()); | 2817 | EXPECT_EQ(StorageError::Type::Cancelled, downloader->error().type()); |
1439 | 2969 | EXPECT_EQ("Downloader::cancel(): download was cancelled", downloader->error().message()); | 2818 | EXPECT_EQ("Downloader::cancel(): download was cancelled", downloader->error().message()); |
1440 | 2970 | 2819 | ||
1442 | 2971 | // We wait here to get coverage for when the reply to a finishDownload() call | 2820 | // We wait here to get coverage for when the reply to a FinishDownload() call |
1443 | 2972 | // finds the downloader in a final state. | 2821 | // finds the downloader in a final state. |
1444 | 2973 | EXPECT_FALSE(spy.wait(2000)); | 2822 | EXPECT_FALSE(spy.wait(2000)); |
1445 | 2974 | } | 2823 | } |
1446 | @@ -2977,14 +2826,6 @@ | |||
1447 | 2977 | { | 2826 | { |
1448 | 2978 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_download_slow_error"))); | 2827 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_download_slow_error"))); |
1449 | 2979 | 2828 | ||
1450 | 2980 | Item root; | ||
1451 | 2981 | { | ||
1452 | 2982 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1453 | 2983 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1454 | 2984 | spy.wait(SIGNAL_WAIT_TIME); | ||
1455 | 2985 | root = j->item(); | ||
1456 | 2986 | } | ||
1457 | 2987 | |||
1458 | 2988 | Item child; | 2829 | Item child; |
1459 | 2989 | { | 2830 | { |
1460 | 2990 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2831 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1461 | @@ -3025,14 +2866,6 @@ | |||
1462 | 3025 | { | 2866 | { |
1463 | 3026 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 2867 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1464 | 3027 | 2868 | ||
1465 | 3028 | Item root; | ||
1466 | 3029 | { | ||
1467 | 3030 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1468 | 3031 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1469 | 3032 | spy.wait(SIGNAL_WAIT_TIME); | ||
1470 | 3033 | root = j->item(); | ||
1471 | 3034 | } | ||
1472 | 3035 | |||
1473 | 3036 | Item child; | 2869 | Item child; |
1474 | 3037 | { | 2870 | { |
1475 | 3038 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2871 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1476 | @@ -3057,10 +2890,92 @@ | |||
1477 | 3057 | EXPECT_EQ(Uploader::Status::Ready, qvariant_cast<Uploader::Status>(arg.at(0))); | 2890 | EXPECT_EQ(Uploader::Status::Ready, qvariant_cast<Uploader::Status>(arg.at(0))); |
1478 | 3058 | } | 2891 | } |
1479 | 3059 | 2892 | ||
1484 | 3060 | EXPECT_EQ(contents.size(), uploader->write(contents)); | 2893 | EXPECT_EQ(0, uploader->bytesAvailable()); |
1485 | 3061 | 2894 | EXPECT_EQ(0, uploader->bytesToWrite()); | |
1486 | 3062 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | 2895 | char buf; |
1487 | 3063 | uploader->finishUpload(); | 2896 | EXPECT_EQ(-1, uploader->read(&buf, 1)); |
1488 | 2897 | EXPECT_FALSE(uploader->waitForReadyRead(1)); | ||
1489 | 2898 | |||
1490 | 2899 | EXPECT_EQ(contents.size(), uploader->write(contents)); | ||
1491 | 2900 | EXPECT_TRUE(uploader->waitForBytesWritten(contents.size())); | ||
1492 | 2901 | |||
1493 | 2902 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | ||
1494 | 2903 | uploader->close(); | ||
1495 | 2904 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | ||
1496 | 2905 | auto arg = spy.takeFirst(); | ||
1497 | 2906 | EXPECT_EQ(Uploader::Status::Finished, qvariant_cast<Uploader::Status>(arg.at(0))); | ||
1498 | 2907 | |||
1499 | 2908 | EXPECT_EQ(Uploader::Status::Finished, uploader->status()); | ||
1500 | 2909 | EXPECT_EQ(child, uploader->item()); | ||
1501 | 2910 | } | ||
1502 | 2911 | |||
1503 | 2912 | #if 0 | ||
1504 | 2913 | // TODO: This test is currently disabled because a synchronous wait in the client | ||
1505 | 2914 | // blocks the single event loop that is shared by the client and the mock provider. | ||
1506 | 2915 | // We need to change the test harness to run a separate event loop for the provider. | ||
1507 | 2916 | // | ||
1508 | 2917 | TEST_F(UploadTest, write_before_ready_and_wait) | ||
1509 | 2918 | { | ||
1510 | 2919 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("upload_slow"))); | ||
1511 | 2920 | |||
1512 | 2921 | Item child; | ||
1513 | 2922 | { | ||
1514 | 2923 | unique_ptr<ItemJob> j(acc_.get("child_id")); | ||
1515 | 2924 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1516 | 2925 | spy.wait(SIGNAL_WAIT_TIME); | ||
1517 | 2926 | child = j->item(); | ||
1518 | 2927 | } | ||
1519 | 2928 | |||
1520 | 2929 | QByteArray contents("Hello world", -1); | ||
1521 | 2930 | unique_ptr<Uploader> uploader(child.createUploader(Item::ConflictPolicy::IgnoreConflict, contents.size())); | ||
1522 | 2931 | EXPECT_TRUE(uploader->isValid()); | ||
1523 | 2932 | |||
1524 | 2933 | // Don't wait for ready state. | ||
1525 | 2934 | |||
1526 | 2935 | EXPECT_EQ(contents.size(), uploader->write(contents)); | ||
1527 | 2936 | EXPECT_TRUE(uploader->waitForBytesWritten(1000)); | ||
1528 | 2937 | |||
1529 | 2938 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | ||
1530 | 2939 | uploader->close(); | ||
1531 | 2940 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | ||
1532 | 2941 | auto arg = spy.takeFirst(); | ||
1533 | 2942 | EXPECT_EQ(Uploader::Status::Finished, qvariant_cast<Uploader::Status>(arg.at(0))); | ||
1534 | 2943 | |||
1535 | 2944 | EXPECT_EQ(Uploader::Status::Finished, uploader->status()); | ||
1536 | 2945 | EXPECT_EQ(child, uploader->item()); | ||
1537 | 2946 | } | ||
1538 | 2947 | #endif | ||
1539 | 2948 | |||
1540 | 2949 | TEST_F(UploadTest, write_before_ready) | ||
1541 | 2950 | { | ||
1542 | 2951 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("upload_slow"))); | ||
1543 | 2952 | |||
1544 | 2953 | Item child; | ||
1545 | 2954 | { | ||
1546 | 2955 | unique_ptr<ItemJob> j(acc_.get("child_id")); | ||
1547 | 2956 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1548 | 2957 | spy.wait(SIGNAL_WAIT_TIME); | ||
1549 | 2958 | child = j->item(); | ||
1550 | 2959 | } | ||
1551 | 2960 | |||
1552 | 2961 | QByteArray contents("Hello world", -1); | ||
1553 | 2962 | unique_ptr<Uploader> uploader(child.createUploader(Item::ConflictPolicy::IgnoreConflict, contents.size())); | ||
1554 | 2963 | EXPECT_TRUE(uploader->isValid()); | ||
1555 | 2964 | |||
1556 | 2965 | // Don't wait for ready state. | ||
1557 | 2966 | |||
1558 | 2967 | EXPECT_EQ(contents.size(), uploader->write(contents)); | ||
1559 | 2968 | |||
1560 | 2969 | // Wait until we get confirmation that the contents were written. | ||
1561 | 2970 | { | ||
1562 | 2971 | QSignalSpy spy(uploader.get(), &Uploader::bytesWritten); | ||
1563 | 2972 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | ||
1564 | 2973 | auto arg = spy.takeFirst(); | ||
1565 | 2974 | EXPECT_TRUE(qvariant_cast<bool>(arg.at(0))); | ||
1566 | 2975 | } | ||
1567 | 2976 | |||
1568 | 2977 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | ||
1569 | 2978 | uploader->close(); | ||
1570 | 3064 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | 2979 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); |
1571 | 3065 | auto arg = spy.takeFirst(); | 2980 | auto arg = spy.takeFirst(); |
1572 | 3066 | EXPECT_EQ(Uploader::Status::Finished, qvariant_cast<Uploader::Status>(arg.at(0))); | 2981 | EXPECT_EQ(Uploader::Status::Finished, qvariant_cast<Uploader::Status>(arg.at(0))); |
1573 | @@ -3073,14 +2988,6 @@ | |||
1574 | 3073 | { | 2988 | { |
1575 | 3074 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 2989 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1576 | 3075 | 2990 | ||
1577 | 3076 | Item root; | ||
1578 | 3077 | { | ||
1579 | 3078 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1580 | 3079 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1581 | 3080 | spy.wait(SIGNAL_WAIT_TIME); | ||
1582 | 3081 | root = j->item(); | ||
1583 | 3082 | } | ||
1584 | 3083 | |||
1585 | 3084 | Item child; | 2991 | Item child; |
1586 | 3085 | { | 2992 | { |
1587 | 3086 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 2993 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1588 | @@ -3098,20 +3005,15 @@ | |||
1589 | 3098 | auto arg = spy.takeFirst(); | 3005 | auto arg = spy.takeFirst(); |
1590 | 3099 | EXPECT_EQ(Uploader::Status::Ready, qvariant_cast<Uploader::Status>(arg.at(0))); | 3006 | EXPECT_EQ(Uploader::Status::Ready, qvariant_cast<Uploader::Status>(arg.at(0))); |
1591 | 3100 | } | 3007 | } |
1592 | 3008 | |||
1593 | 3009 | EXPECT_EQ(1, uploader->write("a", 1)); | ||
1594 | 3010 | EXPECT_TRUE(uploader->waitForBytesWritten(SIGNAL_WAIT_TIME)); | ||
1595 | 3101 | } | 3011 | } |
1596 | 3102 | 3012 | ||
1597 | 3103 | TEST_F(UploadTest, runtime_destroyed) | 3013 | TEST_F(UploadTest, runtime_destroyed) |
1598 | 3104 | { | 3014 | { |
1599 | 3105 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 3015 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1600 | 3106 | 3016 | ||
1601 | 3107 | Item root; | ||
1602 | 3108 | { | ||
1603 | 3109 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1604 | 3110 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1605 | 3111 | spy.wait(SIGNAL_WAIT_TIME); | ||
1606 | 3112 | root = j->item(); | ||
1607 | 3113 | } | ||
1608 | 3114 | |||
1609 | 3115 | Item child; | 3017 | Item child; |
1610 | 3116 | { | 3018 | { |
1611 | 3117 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3019 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1612 | @@ -3143,14 +3045,6 @@ | |||
1613 | 3143 | { | 3045 | { |
1614 | 3144 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("upload_slow"))); | 3046 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("upload_slow"))); |
1615 | 3145 | 3047 | ||
1616 | 3146 | Item root; | ||
1617 | 3147 | { | ||
1618 | 3148 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1619 | 3149 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1620 | 3150 | spy.wait(SIGNAL_WAIT_TIME); | ||
1621 | 3151 | root = j->item(); | ||
1622 | 3152 | } | ||
1623 | 3153 | |||
1624 | 3154 | Item child; | 3048 | Item child; |
1625 | 3155 | { | 3049 | { |
1626 | 3156 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3050 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1627 | @@ -3184,14 +3078,6 @@ | |||
1628 | 3184 | { | 3078 | { |
1629 | 3185 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("upload_error"))); | 3079 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("upload_error"))); |
1630 | 3186 | 3080 | ||
1631 | 3187 | Item root; | ||
1632 | 3188 | { | ||
1633 | 3189 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1634 | 3190 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1635 | 3191 | spy.wait(SIGNAL_WAIT_TIME); | ||
1636 | 3192 | root = j->item(); | ||
1637 | 3193 | } | ||
1638 | 3194 | |||
1639 | 3195 | Item child; | 3081 | Item child; |
1640 | 3196 | { | 3082 | { |
1641 | 3197 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3083 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1642 | @@ -3217,10 +3103,10 @@ | |||
1643 | 3217 | EXPECT_EQ("Conflict: version mismatch", uploader->error().errorString()); | 3103 | EXPECT_EQ("Conflict: version mismatch", uploader->error().errorString()); |
1644 | 3218 | EXPECT_EQ(Item(), uploader->item()); | 3104 | EXPECT_EQ(Item(), uploader->item()); |
1645 | 3219 | 3105 | ||
1647 | 3220 | // For coverage: call finishUpload() while in the Error state. | 3106 | // For coverage: call close() while in the Error state. |
1648 | 3221 | { | 3107 | { |
1649 | 3222 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | 3108 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); |
1651 | 3223 | uploader->finishUpload(); | 3109 | uploader->close(); |
1652 | 3224 | EXPECT_FALSE(spy.wait(1000)); | 3110 | EXPECT_FALSE(spy.wait(1000)); |
1653 | 3225 | } | 3111 | } |
1654 | 3226 | } | 3112 | } |
1655 | @@ -3229,14 +3115,6 @@ | |||
1656 | 3229 | { | 3115 | { |
1657 | 3230 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 3116 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1658 | 3231 | 3117 | ||
1659 | 3232 | Item root; | ||
1660 | 3233 | { | ||
1661 | 3234 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1662 | 3235 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1663 | 3236 | spy.wait(SIGNAL_WAIT_TIME); | ||
1664 | 3237 | root = j->item(); | ||
1665 | 3238 | } | ||
1666 | 3239 | |||
1667 | 3240 | Item child; | 3118 | Item child; |
1668 | 3241 | { | 3119 | { |
1669 | 3242 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3120 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1670 | @@ -3250,7 +3128,7 @@ | |||
1671 | 3250 | 3128 | ||
1672 | 3251 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | 3129 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); |
1673 | 3252 | 3130 | ||
1675 | 3253 | uploader->finishUpload(); | 3131 | uploader->close(); |
1676 | 3254 | 3132 | ||
1677 | 3255 | ASSERT_EQ(1, spy.count()); | 3133 | ASSERT_EQ(1, spy.count()); |
1678 | 3256 | auto arg = spy.takeFirst(); | 3134 | auto arg = spy.takeFirst(); |
1679 | @@ -3259,7 +3137,7 @@ | |||
1680 | 3259 | EXPECT_FALSE(uploader->isValid()); | 3137 | EXPECT_FALSE(uploader->isValid()); |
1681 | 3260 | EXPECT_EQ(Uploader::Status::Error, uploader->status()); | 3138 | EXPECT_EQ(Uploader::Status::Error, uploader->status()); |
1682 | 3261 | EXPECT_EQ(StorageError::LogicError, uploader->error().type()); | 3139 | EXPECT_EQ(StorageError::LogicError, uploader->error().type()); |
1684 | 3262 | EXPECT_EQ("LogicError: Uploader::finishUpload(): cannot finalize while Uploader is not in the Ready state", | 3140 | EXPECT_EQ("LogicError: Uploader::close(): cannot finalize while Uploader is not in the Ready state", |
1685 | 3263 | uploader->error().errorString()); | 3141 | uploader->error().errorString()); |
1686 | 3264 | } | 3142 | } |
1687 | 3265 | 3143 | ||
1688 | @@ -3267,14 +3145,6 @@ | |||
1689 | 3267 | { | 3145 | { |
1690 | 3268 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 3146 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1691 | 3269 | 3147 | ||
1692 | 3270 | Item root; | ||
1693 | 3271 | { | ||
1694 | 3272 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1695 | 3273 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1696 | 3274 | spy.wait(SIGNAL_WAIT_TIME); | ||
1697 | 3275 | root = j->item(); | ||
1698 | 3276 | } | ||
1699 | 3277 | |||
1700 | 3278 | Item child; | 3148 | Item child; |
1701 | 3279 | { | 3149 | { |
1702 | 3280 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3150 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1703 | @@ -3297,7 +3167,7 @@ | |||
1704 | 3297 | 3167 | ||
1705 | 3298 | EXPECT_EQ(StorageError::Type::NoError, runtime_->shutdown().type()); // Destroy runtime | 3168 | EXPECT_EQ(StorageError::Type::NoError, runtime_->shutdown().type()); // Destroy runtime |
1706 | 3299 | 3169 | ||
1708 | 3300 | uploader->finishUpload(); | 3170 | uploader->close(); |
1709 | 3301 | 3171 | ||
1710 | 3302 | ASSERT_EQ(1, spy.count()); | 3172 | ASSERT_EQ(1, spy.count()); |
1711 | 3303 | auto arg = spy.takeFirst(); | 3173 | auto arg = spy.takeFirst(); |
1712 | @@ -3306,21 +3176,13 @@ | |||
1713 | 3306 | EXPECT_FALSE(uploader->isValid()); | 3176 | EXPECT_FALSE(uploader->isValid()); |
1714 | 3307 | EXPECT_EQ(Uploader::Status::Error, uploader->status()); | 3177 | EXPECT_EQ(Uploader::Status::Error, uploader->status()); |
1715 | 3308 | EXPECT_EQ(StorageError::RuntimeDestroyed, uploader->error().type()); | 3178 | EXPECT_EQ(StorageError::RuntimeDestroyed, uploader->error().type()); |
1717 | 3309 | EXPECT_EQ("Uploader::finishUpload(): Runtime was destroyed previously", uploader->error().message()); | 3179 | EXPECT_EQ("Uploader::close(): Runtime was destroyed previously", uploader->error().message()); |
1718 | 3310 | } | 3180 | } |
1719 | 3311 | 3181 | ||
1720 | 3312 | TEST_F(UploadTest, finish_runtime_destroyed_while_reply_outstanding) | 3182 | TEST_F(UploadTest, finish_runtime_destroyed_while_reply_outstanding) |
1721 | 3313 | { | 3183 | { |
1722 | 3314 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_upload_slow"))); | 3184 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_upload_slow"))); |
1723 | 3315 | 3185 | ||
1724 | 3316 | Item root; | ||
1725 | 3317 | { | ||
1726 | 3318 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1727 | 3319 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1728 | 3320 | spy.wait(SIGNAL_WAIT_TIME); | ||
1729 | 3321 | root = j->item(); | ||
1730 | 3322 | } | ||
1731 | 3323 | |||
1732 | 3324 | Item child; | 3186 | Item child; |
1733 | 3325 | { | 3187 | { |
1734 | 3326 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3188 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1735 | @@ -3341,7 +3203,7 @@ | |||
1736 | 3341 | 3203 | ||
1737 | 3342 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | 3204 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); |
1738 | 3343 | 3205 | ||
1740 | 3344 | uploader->finishUpload(); | 3206 | uploader->close(); |
1741 | 3345 | 3207 | ||
1742 | 3346 | EXPECT_EQ(StorageError::Type::NoError, runtime_->shutdown().type()); // Destroy runtime, provider still sleeping | 3208 | EXPECT_EQ(StorageError::Type::NoError, runtime_->shutdown().type()); // Destroy runtime, provider still sleeping |
1743 | 3347 | 3209 | ||
1744 | @@ -3352,21 +3214,13 @@ | |||
1745 | 3352 | EXPECT_FALSE(uploader->isValid()); | 3214 | EXPECT_FALSE(uploader->isValid()); |
1746 | 3353 | EXPECT_EQ(Uploader::Status::Error, uploader->status()); | 3215 | EXPECT_EQ(Uploader::Status::Error, uploader->status()); |
1747 | 3354 | EXPECT_EQ(StorageError::RuntimeDestroyed, uploader->error().type()); | 3216 | EXPECT_EQ(StorageError::RuntimeDestroyed, uploader->error().type()); |
1749 | 3355 | EXPECT_EQ("Uploader::finishUpload(): Runtime was destroyed previously", uploader->error().message()); | 3217 | EXPECT_EQ("Uploader::close(): Runtime was destroyed previously", uploader->error().message()); |
1750 | 3356 | } | 3218 | } |
1751 | 3357 | 3219 | ||
1752 | 3358 | TEST_F(UploadTest, finish_twice) | 3220 | TEST_F(UploadTest, finish_twice) |
1753 | 3359 | { | 3221 | { |
1754 | 3360 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 3222 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1755 | 3361 | 3223 | ||
1756 | 3362 | Item root; | ||
1757 | 3363 | { | ||
1758 | 3364 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1759 | 3365 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1760 | 3366 | spy.wait(SIGNAL_WAIT_TIME); | ||
1761 | 3367 | root = j->item(); | ||
1762 | 3368 | } | ||
1763 | 3369 | |||
1764 | 3370 | Item child; | 3224 | Item child; |
1765 | 3371 | { | 3225 | { |
1766 | 3372 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3226 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1767 | @@ -3387,8 +3241,8 @@ | |||
1768 | 3387 | 3241 | ||
1769 | 3388 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | 3242 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); |
1770 | 3389 | 3243 | ||
1773 | 3390 | uploader->finishUpload(); | 3244 | uploader->close(); |
1774 | 3391 | uploader->finishUpload(); | 3245 | uploader->close(); |
1775 | 3392 | 3246 | ||
1776 | 3393 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | 3247 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); |
1777 | 3394 | auto arg = spy.takeFirst(); | 3248 | auto arg = spy.takeFirst(); |
1778 | @@ -3401,14 +3255,6 @@ | |||
1779 | 3401 | { | 3255 | { |
1780 | 3402 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_upload_error"))); | 3256 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_upload_error"))); |
1781 | 3403 | 3257 | ||
1782 | 3404 | Item root; | ||
1783 | 3405 | { | ||
1784 | 3406 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1785 | 3407 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1786 | 3408 | spy.wait(SIGNAL_WAIT_TIME); | ||
1787 | 3409 | root = j->item(); | ||
1788 | 3410 | } | ||
1789 | 3411 | |||
1790 | 3412 | Item child; | 3258 | Item child; |
1791 | 3413 | { | 3259 | { |
1792 | 3414 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3260 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1793 | @@ -3429,7 +3275,7 @@ | |||
1794 | 3429 | 3275 | ||
1795 | 3430 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | 3276 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); |
1796 | 3431 | 3277 | ||
1798 | 3432 | uploader->finishUpload(); | 3278 | uploader->close(); |
1799 | 3433 | 3279 | ||
1800 | 3434 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | 3280 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); |
1801 | 3435 | auto arg = spy.takeFirst(); | 3281 | auto arg = spy.takeFirst(); |
1802 | @@ -3472,14 +3318,6 @@ | |||
1803 | 3472 | { | 3318 | { |
1804 | 3473 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 3319 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1805 | 3474 | 3320 | ||
1806 | 3475 | Item root; | ||
1807 | 3476 | { | ||
1808 | 3477 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1809 | 3478 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1810 | 3479 | spy.wait(SIGNAL_WAIT_TIME); | ||
1811 | 3480 | root = j->item(); | ||
1812 | 3481 | } | ||
1813 | 3482 | |||
1814 | 3483 | Item child; | 3321 | Item child; |
1815 | 3484 | { | 3322 | { |
1816 | 3485 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3323 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1817 | @@ -3506,14 +3344,6 @@ | |||
1818 | 3506 | { | 3344 | { |
1819 | 3507 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("upload_returns_dir"))); | 3345 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("upload_returns_dir"))); |
1820 | 3508 | 3346 | ||
1821 | 3509 | Item root; | ||
1822 | 3510 | { | ||
1823 | 3511 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1824 | 3512 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1825 | 3513 | spy.wait(SIGNAL_WAIT_TIME); | ||
1826 | 3514 | root = j->item(); | ||
1827 | 3515 | } | ||
1828 | 3516 | |||
1829 | 3517 | Item child; | 3347 | Item child; |
1830 | 3518 | { | 3348 | { |
1831 | 3519 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3349 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1832 | @@ -3533,7 +3363,7 @@ | |||
1833 | 3533 | } | 3363 | } |
1834 | 3534 | 3364 | ||
1835 | 3535 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | 3365 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); |
1837 | 3536 | uploader->finishUpload(); | 3366 | uploader->close(); |
1838 | 3537 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | 3367 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); |
1839 | 3538 | auto arg = spy.takeFirst(); | 3368 | auto arg = spy.takeFirst(); |
1840 | 3539 | EXPECT_EQ(Uploader::Status::Error, qvariant_cast<Uploader::Status>(arg.at(0))); | 3369 | EXPECT_EQ(Uploader::Status::Error, qvariant_cast<Uploader::Status>(arg.at(0))); |
1841 | @@ -3547,14 +3377,6 @@ | |||
1842 | 3547 | { | 3377 | { |
1843 | 3548 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 3378 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1844 | 3549 | 3379 | ||
1845 | 3550 | Item root; | ||
1846 | 3551 | { | ||
1847 | 3552 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1848 | 3553 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1849 | 3554 | spy.wait(SIGNAL_WAIT_TIME); | ||
1850 | 3555 | root = j->item(); | ||
1851 | 3556 | } | ||
1852 | 3557 | |||
1853 | 3558 | Item child; | 3380 | Item child; |
1854 | 3559 | { | 3381 | { |
1855 | 3560 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3382 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1856 | @@ -3592,14 +3414,6 @@ | |||
1857 | 3592 | { | 3414 | { |
1858 | 3593 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_upload_slow_error"))); | 3415 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_upload_slow_error"))); |
1859 | 3594 | 3416 | ||
1860 | 3595 | Item root; | ||
1861 | 3596 | { | ||
1862 | 3597 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1863 | 3598 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1864 | 3599 | spy.wait(SIGNAL_WAIT_TIME); | ||
1865 | 3600 | root = j->item(); | ||
1866 | 3601 | } | ||
1867 | 3602 | |||
1868 | 3603 | Item child; | 3417 | Item child; |
1869 | 3604 | { | 3418 | { |
1870 | 3605 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3419 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1871 | @@ -3620,12 +3434,12 @@ | |||
1872 | 3620 | 3434 | ||
1873 | 3621 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | 3435 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); |
1874 | 3622 | 3436 | ||
1876 | 3623 | uploader->finishUpload(); | 3437 | uploader->close(); |
1877 | 3624 | 3438 | ||
1878 | 3625 | uploader->cancel(); | 3439 | uploader->cancel(); |
1879 | 3626 | uploader->cancel(); // Second time for coverage | 3440 | uploader->cancel(); // Second time for coverage |
1880 | 3627 | 3441 | ||
1882 | 3628 | uploader->finishUpload(); // Second time for coverage | 3442 | uploader->close(); // Second time for coverage |
1883 | 3629 | 3443 | ||
1884 | 3630 | EXPECT_EQ(1, spy.count()); | 3444 | EXPECT_EQ(1, spy.count()); |
1885 | 3631 | auto arg = spy.takeFirst(); | 3445 | auto arg = spy.takeFirst(); |
1886 | @@ -3635,7 +3449,7 @@ | |||
1887 | 3635 | EXPECT_EQ(StorageError::Type::Cancelled, uploader->error().type()); | 3449 | EXPECT_EQ(StorageError::Type::Cancelled, uploader->error().type()); |
1888 | 3636 | EXPECT_EQ("Uploader::cancel(): upload was cancelled", uploader->error().message()); | 3450 | EXPECT_EQ("Uploader::cancel(): upload was cancelled", uploader->error().message()); |
1889 | 3637 | 3451 | ||
1891 | 3638 | // We wait here to get coverage for when the reply to a finishUpload() call | 3452 | // We wait here to get coverage for when the reply to a FinishUpload() call |
1892 | 3639 | // finds the uploader in a final state. | 3453 | // finds the uploader in a final state. |
1893 | 3640 | EXPECT_FALSE(spy.wait(2000)); | 3454 | EXPECT_FALSE(spy.wait(2000)); |
1894 | 3641 | } | 3455 | } |
1895 | @@ -3644,14 +3458,6 @@ | |||
1896 | 3644 | { | 3458 | { |
1897 | 3645 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_upload_slow_error"))); | 3459 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("finish_upload_slow_error"))); |
1898 | 3646 | 3460 | ||
1899 | 3647 | Item root; | ||
1900 | 3648 | { | ||
1901 | 3649 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1902 | 3650 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1903 | 3651 | spy.wait(SIGNAL_WAIT_TIME); | ||
1904 | 3652 | root = j->item(); | ||
1905 | 3653 | } | ||
1906 | 3654 | |||
1907 | 3655 | Item child; | 3461 | Item child; |
1908 | 3656 | { | 3462 | { |
1909 | 3657 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3463 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1910 | @@ -3730,7 +3536,7 @@ | |||
1911 | 3730 | EXPECT_EQ(contents.size(), uploader->write(contents)); | 3536 | EXPECT_EQ(contents.size(), uploader->write(contents)); |
1912 | 3731 | 3537 | ||
1913 | 3732 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | 3538 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); |
1915 | 3733 | uploader->finishUpload(); | 3539 | uploader->close(); |
1916 | 3734 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | 3540 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); |
1917 | 3735 | auto arg = spy.takeFirst(); | 3541 | auto arg = spy.takeFirst(); |
1918 | 3736 | EXPECT_EQ(Uploader::Status::Finished, qvariant_cast<Uploader::Status>(arg.at(0))); | 3542 | EXPECT_EQ(Uploader::Status::Finished, qvariant_cast<Uploader::Status>(arg.at(0))); |
1919 | @@ -3751,14 +3557,6 @@ | |||
1920 | 3751 | root = j->item(); | 3557 | root = j->item(); |
1921 | 3752 | } | 3558 | } |
1922 | 3753 | 3559 | ||
1923 | 3754 | Item child; | ||
1924 | 3755 | { | ||
1925 | 3756 | unique_ptr<ItemJob> j(acc_.get("child_id")); | ||
1926 | 3757 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1927 | 3758 | spy.wait(SIGNAL_WAIT_TIME); | ||
1928 | 3759 | child = j->item(); | ||
1929 | 3760 | } | ||
1930 | 3761 | |||
1931 | 3762 | EXPECT_EQ(StorageError::Type::NoError, runtime_->shutdown().type()); // Destroy runtime | 3560 | EXPECT_EQ(StorageError::Type::NoError, runtime_->shutdown().type()); // Destroy runtime |
1932 | 3763 | 3561 | ||
1933 | 3764 | QByteArray contents("Hello world", -1); | 3562 | QByteArray contents("Hello world", -1); |
1934 | @@ -3783,14 +3581,6 @@ | |||
1935 | 3783 | { | 3581 | { |
1936 | 3784 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); | 3582 | set_provider(unique_ptr<provider::ProviderBase>(new MockProvider())); |
1937 | 3785 | 3583 | ||
1938 | 3786 | Item root; | ||
1939 | 3787 | { | ||
1940 | 3788 | unique_ptr<ItemJob> j(acc_.get("root_id")); | ||
1941 | 3789 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1942 | 3790 | spy.wait(SIGNAL_WAIT_TIME); | ||
1943 | 3791 | root = j->item(); | ||
1944 | 3792 | } | ||
1945 | 3793 | |||
1946 | 3794 | Item child; | 3584 | Item child; |
1947 | 3795 | { | 3585 | { |
1948 | 3796 | unique_ptr<ItemJob> j(acc_.get("child_id")); | 3586 | unique_ptr<ItemJob> j(acc_.get("child_id")); |
1949 | @@ -3829,14 +3619,6 @@ | |||
1950 | 3829 | root = j->item(); | 3619 | root = j->item(); |
1951 | 3830 | } | 3620 | } |
1952 | 3831 | 3621 | ||
1953 | 3832 | Item child; | ||
1954 | 3833 | { | ||
1955 | 3834 | unique_ptr<ItemJob> j(acc_.get("child_id")); | ||
1956 | 3835 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1957 | 3836 | spy.wait(SIGNAL_WAIT_TIME); | ||
1958 | 3837 | child = j->item(); | ||
1959 | 3838 | } | ||
1960 | 3839 | |||
1961 | 3840 | QByteArray contents("Hello world", -1); | 3622 | QByteArray contents("Hello world", -1); |
1962 | 3841 | unique_ptr<Uploader> uploader(root.createFile("", | 3623 | unique_ptr<Uploader> uploader(root.createFile("", |
1963 | 3842 | Item::ConflictPolicy::IgnoreConflict, | 3624 | Item::ConflictPolicy::IgnoreConflict, |
1964 | @@ -3867,14 +3649,6 @@ | |||
1965 | 3867 | root = j->item(); | 3649 | root = j->item(); |
1966 | 3868 | } | 3650 | } |
1967 | 3869 | 3651 | ||
1968 | 3870 | Item child; | ||
1969 | 3871 | { | ||
1970 | 3872 | unique_ptr<ItemJob> j(acc_.get("child_id")); | ||
1971 | 3873 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1972 | 3874 | spy.wait(SIGNAL_WAIT_TIME); | ||
1973 | 3875 | child = j->item(); | ||
1974 | 3876 | } | ||
1975 | 3877 | |||
1976 | 3878 | QByteArray contents("Hello world", -1); | 3652 | QByteArray contents("Hello world", -1); |
1977 | 3879 | unique_ptr<Uploader> uploader(root.createFile("some_file", | 3653 | unique_ptr<Uploader> uploader(root.createFile("some_file", |
1978 | 3880 | Item::ConflictPolicy::IgnoreConflict, | 3654 | Item::ConflictPolicy::IgnoreConflict, |
1979 | @@ -3905,14 +3679,6 @@ | |||
1980 | 3905 | root = j->item(); | 3679 | root = j->item(); |
1981 | 3906 | } | 3680 | } |
1982 | 3907 | 3681 | ||
1983 | 3908 | Item child; | ||
1984 | 3909 | { | ||
1985 | 3910 | unique_ptr<ItemJob> j(acc_.get("child_id")); | ||
1986 | 3911 | QSignalSpy spy(j.get(), &ItemJob::statusChanged); | ||
1987 | 3912 | spy.wait(SIGNAL_WAIT_TIME); | ||
1988 | 3913 | child = j->item(); | ||
1989 | 3914 | } | ||
1990 | 3915 | |||
1991 | 3916 | QByteArray contents("Hello world", -1); | 3682 | QByteArray contents("Hello world", -1); |
1992 | 3917 | unique_ptr<Uploader> uploader(root.createFile("some_file", | 3683 | unique_ptr<Uploader> uploader(root.createFile("some_file", |
1993 | 3918 | Item::ConflictPolicy::IgnoreConflict, | 3684 | Item::ConflictPolicy::IgnoreConflict, |
1994 | @@ -3930,7 +3696,7 @@ | |||
1995 | 3930 | EXPECT_EQ(contents.size(), uploader->write(contents)); | 3696 | EXPECT_EQ(contents.size(), uploader->write(contents)); |
1996 | 3931 | 3697 | ||
1997 | 3932 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | 3698 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); |
1999 | 3933 | uploader->finishUpload(); | 3699 | uploader->close(); |
2000 | 3934 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | 3700 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); |
2001 | 3935 | auto arg = spy.takeFirst(); | 3701 | auto arg = spy.takeFirst(); |
2002 | 3936 | EXPECT_EQ(Uploader::Status::Error, qvariant_cast<Uploader::Status>(arg.at(0))); | 3702 | EXPECT_EQ(Uploader::Status::Error, qvariant_cast<Uploader::Status>(arg.at(0))); |
2003 | @@ -3968,7 +3734,7 @@ | |||
2004 | 3968 | EXPECT_EQ(contents.size(), uploader->write(contents)); | 3734 | EXPECT_EQ(contents.size(), uploader->write(contents)); |
2005 | 3969 | 3735 | ||
2006 | 3970 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); | 3736 | QSignalSpy spy(uploader.get(), &Uploader::statusChanged); |
2008 | 3971 | uploader->finishUpload(); | 3737 | uploader->close(); |
2009 | 3972 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); | 3738 | ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME)); |
2010 | 3973 | auto arg = spy.takeFirst(); | 3739 | auto arg = spy.takeFirst(); |
2011 | 3974 | EXPECT_EQ(Uploader::Status::Error, qvariant_cast<Uploader::Status>(arg.at(0))); | 3740 | EXPECT_EQ(Uploader::Status::Error, qvariant_cast<Uploader::Status>(arg.at(0))); |
PASSED: Continuous integration, rev:88 /jenkins. canonical. com/unity- api-1/job/ lp-storage- framework- ci/162/ /jenkins. canonical. com/unity- api-1/job/ build/928 /jenkins. canonical. com/unity- api-1/job/ build-0- fetch/935 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= vivid+overlay/ 738 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= vivid+overlay/ 738/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= xenial+ overlay/ 738 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= xenial+ overlay/ 738/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= yakkety/ 738 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= yakkety/ 738/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= vivid+overlay/ 738 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= vivid+overlay/ 738/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= xenial+ overlay/ 738 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= xenial+ overlay/ 738/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= yakkety/ 738 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= yakkety/ 738/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= vivid+overlay/ 738 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= vivid+overlay/ 738/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 738 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 738/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= yakkety/ 738 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= yakkety/ 738/artifact/ output/ *zip*/output. zip
https:/
Executed test runs:
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: /jenkins. canonical. com/unity- api-1/job/ lp-storage- framework- ci/162/ rebuild
https:/