Merge lp:~michihenning/storage-framework/remote-client-coverage into lp:storage-framework/devel

Proposed by Michi Henning
Status: Merged
Approved by: James Henstridge
Approved revision: 60
Merged at revision: 57
Proposed branch: lp:~michihenning/storage-framework/remote-client-coverage
Merge into: lp:storage-framework/devel
Diff against target: 1244 lines (+766/-105)
14 files modified
demo/provider_test/provider-test.cpp (+1/-1)
src/provider/internal/TestServerImpl.cpp (+1/-1)
src/provider/testing/TestServer.cpp (+0/-1)
src/qt/client/internal/remote_client/AccountImpl.cpp (+2/-6)
src/qt/client/internal/remote_client/RuntimeImpl.cpp (+8/-2)
tests/provider-ProviderInterface/CMakeLists.txt (+0/-14)
tests/provider-ProviderInterface/ProviderInterface_test.cpp (+21/-66)
tests/remote-client/CMakeLists.txt (+3/-2)
tests/remote-client/MockProvider.cpp (+236/-0)
tests/remote-client/MockProvider.h (+96/-0)
tests/remote-client/remote-client_test.cpp (+254/-10)
tests/utils/CMakeLists.txt (+16/-2)
tests/utils/ProviderFixture.cpp (+79/-0)
tests/utils/ProviderFixture.h (+49/-0)
To merge this branch: bzr merge lp:~michihenning/storage-framework/remote-client-coverage
Reviewer Review Type Date Requested Status
James Henstridge Approve
unity-api-1-bot continuous-integration Approve
Review via email: mp+303368@code.launchpad.net

Commit message

Increased remote client coverage.

Description of the change

Refactored the fake provider from the provider test into test/utils.
Added mock provider for remote client test. (This is currently mostly
a copy of the original; I'll pare that down to something simpler as I flesh out coverage some more.)

This is incomplete, but I don't want the MR to get any larger, so I'll push this in stages.

Added coverage tests to make sure that we are handling a destroyed runtime correctly if the runtime is destroyed while the reply to a dbus request is outstanding.

To post a comment you must log in.
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:57
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/81/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/425/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/431
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=vivid+overlay/338
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=xenial+overlay/338
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=yakkety/338
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/268
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/268/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/268
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/268/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/268/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/268
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/268/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/268
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/268/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/268
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/268/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/268
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/268/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/268
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/268/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/268
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/268/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/81/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:57
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/82/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/438
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/444
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=vivid+overlay/350
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=xenial+overlay/350
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=yakkety/350
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/280
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/280/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/280
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/280/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/280
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/280/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/280
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/280/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/280
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/280/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/280
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/280/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/280
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/280/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/280
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/280/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/280
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/280/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/82/rebuild

review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) wrote :

I've noted a few things that need attention as inline comments

review: Needs Fixing
58. By Michi Henning

Review comments from James.

Revision history for this message
Michi Henning (michihenning) wrote :

Thanks for that!

I've renamed the test class to ProviderFixture and addressed the other issues.

59. By Michi Henning

Oops, missed change in MockProvider.cpp.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:58
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/84/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/440/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/446
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=vivid+overlay/352
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=xenial+overlay/352
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=yakkety/352
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/282/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/282/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/282/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/282/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/282/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/282/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/282/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/282/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/282/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/84/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:59
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/85/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/441
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/447
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=vivid+overlay/353
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=xenial+overlay/353
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=yakkety/353
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/283
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/283/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/283
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/283/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/283
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/283/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/283
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/283/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/283
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/283/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/283
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/283/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/283
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/283/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/283
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/283/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/283
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/283/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/85/rebuild

review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) wrote :

The class still seems to be called FakeProvider?

60. By Michi Henning

Renamed FakeProvider -> ProviderFixture.

Revision history for this message
Michi Henning (michihenning) wrote :

Oh boy, I shouldn't be writing code when I'm sick :-(

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:60
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/86/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/446/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/452
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=vivid+overlay/357
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=xenial+overlay/357
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=yakkety/357
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/287
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/287/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/287
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/287/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/287/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/287
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/287/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/287
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/287/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/287
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/287/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/287
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/287/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/287
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/287/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/287/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/86/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:60
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/87/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/447
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/453
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=vivid+overlay/358
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=xenial+overlay/358
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-1-sourcepkg/release=yakkety/358
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/288
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/288/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/288
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/288/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/288
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/288/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/288
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/288/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/288
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/288/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/288
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/288/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/288
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/288/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/288
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/288/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/288
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/288/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/87/rebuild

review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'demo/provider_test/provider-test.cpp'
--- demo/provider_test/provider-test.cpp 2016-08-18 09:25:51 +0000
+++ demo/provider_test/provider-test.cpp 2016-08-23 01:48:44 +0000
@@ -161,7 +161,7 @@
161 if (page_token != "")161 if (page_token != "")
162 {162 {
163 string msg = string("Item::list(): invalid page token: \"") + page_token + "\"";163 string msg = string("Item::list(): invalid page token: \"") + page_token + "\"";
164 return make_exceptional_future<tuple<ItemList,string>>(msg);164 return make_exceptional_future<tuple<ItemList,string>>(LogicException(msg));
165 }165 }
166 ItemList children =166 ItemList children =
167 {167 {
168168
=== modified file 'src/provider/internal/TestServerImpl.cpp'
--- src/provider/internal/TestServerImpl.cpp 2016-08-12 01:34:34 +0000
+++ src/provider/internal/TestServerImpl.cpp 2016-08-23 01:48:44 +0000
@@ -56,7 +56,7 @@
56 new ProviderAdaptor(interface_.get());56 new ProviderAdaptor(interface_.get());
5757
58 if (!connection_.registerObject(QString::fromStdString(object_path_),58 if (!connection_.registerObject(QString::fromStdString(object_path_),
59 interface_.get()))59 interface_.get()))
60 {60 {
61 string msg = "Could not register provider on connection: " + connection_.lastError().message().toStdString();61 string msg = "Could not register provider on connection: " + connection_.lastError().message().toStdString();
62 throw ResourceException(msg, int(connection_.lastError().type()));62 throw ResourceException(msg, int(connection_.lastError().type()));
6363
=== modified file 'src/provider/testing/TestServer.cpp'
--- src/provider/testing/TestServer.cpp 2016-08-11 04:29:36 +0000
+++ src/provider/testing/TestServer.cpp 2016-08-23 01:48:44 +0000
@@ -22,7 +22,6 @@
2222
23#include <OnlineAccounts/Account>23#include <OnlineAccounts/Account>
2424
25
26using namespace std;25using namespace std;
2726
28namespace unity27namespace unity
2928
=== modified file 'src/qt/client/internal/remote_client/AccountImpl.cpp'
--- src/qt/client/internal/remote_client/AccountImpl.cpp 2016-08-11 07:34:49 +0000
+++ src/qt/client/internal/remote_client/AccountImpl.cpp 2016-08-23 01:48:44 +0000
@@ -55,10 +55,6 @@
55 auto rt_impl = dynamic_pointer_cast<RuntimeImpl>(runtime.lock()->p_);55 auto rt_impl = dynamic_pointer_cast<RuntimeImpl>(runtime.lock()->p_);
56 assert(rt_impl);56 assert(rt_impl);
57 provider_.reset(new ProviderInterface(bus_name, object_path, rt_impl->connection()));57 provider_.reset(new ProviderInterface(bus_name, object_path, rt_impl->connection()));
58 if (!provider_->isValid())
59 {
60 throw LocalCommsException("AccountImpl(): " + provider_->lastError().message());
61 }
62}58}
6359
64QString AccountImpl::owner() const60QString AccountImpl::owner() const
@@ -85,9 +81,9 @@
85 {81 {
86 runtime(); // Throws if runtime was destroyed.82 runtime(); // Throws if runtime was destroyed.
87 }83 }
88 catch (RuntimeDestroyedException const& e)84 catch (RuntimeDestroyedException const&)
89 {85 {
90 return make_exceptional_future<QVector<Root::SPtr>>(e);86 return make_exceptional_future<QVector<Root::SPtr>>(RuntimeDestroyedException("Account::roots()"));
91 }87 }
9288
93 auto reply = provider_->Roots();89 auto reply = provider_->Roots();
9490
=== modified file 'src/qt/client/internal/remote_client/RuntimeImpl.cpp'
--- src/qt/client/internal/remote_client/RuntimeImpl.cpp 2016-08-19 03:16:52 +0000
+++ src/qt/client/internal/remote_client/RuntimeImpl.cpp 2016-08-23 01:48:44 +0000
@@ -84,9 +84,9 @@
84 shutdown();84 shutdown();
85 }85 }
86 // LCOV_EXCL_START86 // LCOV_EXCL_START
87 catch (std::exception const&)87 catch (std::exception const& e)
88 {88 {
89 qCritical() << "shutdown error"; // TODO, log the error properly89 qCritical() << "shutdown error" << e.what();
90 }90 }
91 // LCOV_EXCL_STOP91 // LCOV_EXCL_STOP
92}92}
@@ -130,8 +130,10 @@
130{130{
131 if (destroyed_)131 if (destroyed_)
132 {132 {
133 // LCOV_EXCL_START
133 make_exceptional_future(qf_, RuntimeDestroyedException("Runtime::accounts()"));134 make_exceptional_future(qf_, RuntimeDestroyedException("Runtime::accounts()"));
134 return;135 return;
136 // LCOV_EXCL_STOP
135 }137 }
136138
137 timer_.stop();139 timer_.stop();
@@ -161,16 +163,20 @@
161 accounts_ = accounts;163 accounts_ = accounts;
162 make_ready_future(qf_, accounts);164 make_ready_future(qf_, accounts);
163 }165 }
166 // LCOV_EXCL_START
164 catch (StorageException const& e)167 catch (StorageException const& e)
165 {168 {
166 make_exceptional_future(qf_, e);169 make_exceptional_future(qf_, e);
167 }170 }
171 // LCOV_EXCL_STOP
168}172}
169173
174// LCOV_EXCL_START
170void RuntimeImpl::timeout()175void RuntimeImpl::timeout()
171{176{
172 make_exceptional_future(qf_, ResourceException("Runtime::accounts(): timeout retrieving Online accounts", 0));177 make_exceptional_future(qf_, ResourceException("Runtime::accounts(): timeout retrieving Online accounts", 0));
173}178}
179// LCOV_EXCL_STOP
174180
175shared_ptr<Account> RuntimeImpl::make_test_account(QString const& bus_name,181shared_ptr<Account> RuntimeImpl::make_test_account(QString const& bus_name,
176 QString const& object_path)182 QString const& object_path)
177183
=== modified file 'tests/provider-ProviderInterface/CMakeLists.txt'
--- tests/provider-ProviderInterface/CMakeLists.txt 2016-08-11 08:21:23 +0000
+++ tests/provider-ProviderInterface/CMakeLists.txt 2016-08-23 01:48:44 +0000
@@ -1,17 +1,3 @@
1
2
3set_source_files_properties(${CMAKE_SOURCE_DIR}/data/provider.xml PROPERTIES
4 CLASSNAME ProviderClient
5 INCLUDE unity/storage/internal/dbusmarshal.h
6)
7qt5_add_dbus_interface(generated_files
8 ${CMAKE_SOURCE_DIR}/data/provider.xml
9 ProviderClient
10)
11set_source_files_properties(${generated_files} PROPERTIES
12 GENERATED TRUE
13)
14
15add_executable(provider-ProviderInterface_test1add_executable(provider-ProviderInterface_test
16 ProviderInterface_test.cpp2 ProviderInterface_test.cpp
17 TestProvider.cpp3 TestProvider.cpp
184
=== modified file 'tests/provider-ProviderInterface/ProviderInterface_test.cpp'
--- tests/provider-ProviderInterface/ProviderInterface_test.cpp 2016-08-12 06:29:15 +0000
+++ tests/provider-ProviderInterface/ProviderInterface_test.cpp 2016-08-23 01:48:44 +0000
@@ -21,9 +21,8 @@
21#include <unity/storage/provider/testing/TestServer.h>21#include <unity/storage/provider/testing/TestServer.h>
2222
23#include "TestProvider.h"23#include "TestProvider.h"
24#include "ProviderClient.h"
2524
26#include <utils/DBusEnvironment.h>25#include <utils/ProviderFixture.h>
2726
28#include <gtest/gtest.h>27#include <gtest/gtest.h>
29#include <OnlineAccounts/Account>28#include <OnlineAccounts/Account>
@@ -55,69 +54,25 @@
5554
56}55}
5756
5857class ProviderInterfaceTest : public ProviderFixture
59class ProviderInterfaceTest : public ::testing::Test
60{58{
61public:
62 QDBusConnection const& connection()
63 {
64 return dbus_->connection();
65 }
66
67 void make_provider(unique_ptr<ProviderBase>&& provider)
68 {
69 account_manager_->waitForReady();
70 OnlineAccounts::Account* account = account_manager_->account(
71 2, "oauth2-service");
72 ASSERT_NE(nullptr, account);
73
74 test_server_.reset(
75 new TestServer(move(provider), account,
76 *service_connection_, BUS_PATH.toStdString()));
77
78 client_.reset(new ProviderClient(service_connection_->baseService(),
79 BUS_PATH,
80 connection()));
81 }
82
83 void wait_for(QDBusPendingCall const& call) {
84 QDBusPendingCallWatcher watcher(call);
85 QSignalSpy spy(&watcher, &QDBusPendingCallWatcher::finished);
86 ASSERT_TRUE(spy.wait());
87 }
88
89protected:59protected:
90 void SetUp() override60 void SetUp() override
91 {61 {
92 dbus_.reset(new DBusEnvironment);62 client_.reset(new ProviderClient(service_connection_->baseService(), BUS_PATH, connection()));
93 dbus_->start_services();
94 service_connection_.reset(
95 new QDBusConnection(QDBusConnection::connectToBus(
96 dbus_->busAddress(), SERVICE_CONNECTION_NAME)));
97 account_manager_.reset(new OnlineAccounts::Manager(
98 "", *service_connection_));
99 }63 }
10064
101 void TearDown() override65 void TearDown() override
102 {66 {
103 client_.reset();67 client_.reset();
104 test_server_.reset();
105 service_connection_.reset();
106 QDBusConnection::disconnectFromBus(SERVICE_CONNECTION_NAME);
107 dbus_.reset();
108 }68 }
10969
110 unique_ptr<DBusEnvironment> dbus_;70 std::unique_ptr<ProviderClient> client_;
111 unique_ptr<QDBusConnection> service_connection_;
112 unique_ptr<OnlineAccounts::Manager> account_manager_;
113 unique_ptr<TestServer> test_server_;
114 unique_ptr<ProviderClient> client_;
115};71};
11672
117
118TEST_F(ProviderInterfaceTest, roots)73TEST_F(ProviderInterfaceTest, roots)
119{74{
120 make_provider(unique_ptr<ProviderBase>(new TestProvider));75 set_provider(unique_ptr<ProviderBase>(new TestProvider));
12176
122 auto reply = client_->Roots();77 auto reply = client_->Roots();
123 wait_for(reply);78 wait_for(reply);
@@ -133,7 +88,7 @@
13388
134TEST_F(ProviderInterfaceTest, list)89TEST_F(ProviderInterfaceTest, list)
135{90{
136 make_provider(unique_ptr<ProviderBase>(new TestProvider));91 set_provider(unique_ptr<ProviderBase>(new TestProvider));
13792
138 auto reply = client_->List("root_id", "");93 auto reply = client_->List("root_id", "");
139 wait_for(reply);94 wait_for(reply);
@@ -171,7 +126,7 @@
171126
172TEST_F(ProviderInterfaceTest, lookup)127TEST_F(ProviderInterfaceTest, lookup)
173{128{
174 make_provider(unique_ptr<ProviderBase>(new TestProvider));129 set_provider(unique_ptr<ProviderBase>(new TestProvider));
175130
176 auto reply = client_->Lookup("root_id", "Filename");131 auto reply = client_->Lookup("root_id", "Filename");
177 wait_for(reply);132 wait_for(reply);
@@ -187,7 +142,7 @@
187142
188TEST_F(ProviderInterfaceTest, metadata)143TEST_F(ProviderInterfaceTest, metadata)
189{144{
190 make_provider(unique_ptr<ProviderBase>(new TestProvider));145 set_provider(unique_ptr<ProviderBase>(new TestProvider));
191146
192 auto reply = client_->Metadata("root_id");147 auto reply = client_->Metadata("root_id");
193 wait_for(reply);148 wait_for(reply);
@@ -201,7 +156,7 @@
201156
202TEST_F(ProviderInterfaceTest, create_folder)157TEST_F(ProviderInterfaceTest, create_folder)
203{158{
204 make_provider(unique_ptr<ProviderBase>(new TestProvider));159 set_provider(unique_ptr<ProviderBase>(new TestProvider));
205160
206 auto reply = client_->CreateFolder("root_id", "New Folder");161 auto reply = client_->CreateFolder("root_id", "New Folder");
207 wait_for(reply);162 wait_for(reply);
@@ -215,7 +170,7 @@
215170
216TEST_F(ProviderInterfaceTest, create_file)171TEST_F(ProviderInterfaceTest, create_file)
217{172{
218 make_provider(unique_ptr<ProviderBase>(new TestProvider));173 set_provider(unique_ptr<ProviderBase>(new TestProvider));
219174
220 const std::string file_contents = "Hello world!";175 const std::string file_contents = "Hello world!";
221 QString upload_id;176 QString upload_id;
@@ -263,7 +218,7 @@
263218
264TEST_F(ProviderInterfaceTest, update)219TEST_F(ProviderInterfaceTest, update)
265{220{
266 make_provider(unique_ptr<ProviderBase>(new TestProvider));221 set_provider(unique_ptr<ProviderBase>(new TestProvider));
267222
268 const std::string file_contents = "Hello world!";223 const std::string file_contents = "Hello world!";
269 QString upload_id;224 QString upload_id;
@@ -309,7 +264,7 @@
309264
310TEST_F(ProviderInterfaceTest, upload_short_write)265TEST_F(ProviderInterfaceTest, upload_short_write)
311{266{
312 make_provider(unique_ptr<ProviderBase>(new TestProvider));267 set_provider(unique_ptr<ProviderBase>(new TestProvider));
313268
314 QString upload_id;269 QString upload_id;
315 QDBusUnixFileDescriptor socket;270 QDBusUnixFileDescriptor socket;
@@ -329,7 +284,7 @@
329284
330TEST_F(ProviderInterfaceTest, upload_long_write)285TEST_F(ProviderInterfaceTest, upload_long_write)
331{286{
332 make_provider(unique_ptr<ProviderBase>(new TestProvider));287 set_provider(unique_ptr<ProviderBase>(new TestProvider));
333288
334 const std::string file_contents = "Hello world!";289 const std::string file_contents = "Hello world!";
335 QString upload_id;290 QString upload_id;
@@ -374,7 +329,7 @@
374329
375TEST_F(ProviderInterfaceTest, cancel_upload)330TEST_F(ProviderInterfaceTest, cancel_upload)
376{331{
377 make_provider(unique_ptr<ProviderBase>(new TestProvider));332 set_provider(unique_ptr<ProviderBase>(new TestProvider));
378333
379 QString upload_id;334 QString upload_id;
380 QDBusUnixFileDescriptor socket;335 QDBusUnixFileDescriptor socket;
@@ -392,7 +347,7 @@
392347
393TEST_F(ProviderInterfaceTest, finish_upload_unknown)348TEST_F(ProviderInterfaceTest, finish_upload_unknown)
394{349{
395 make_provider(unique_ptr<ProviderBase>(new TestProvider));350 set_provider(unique_ptr<ProviderBase>(new TestProvider));
396351
397 auto reply = client_->FinishUpload("no-such-upload");352 auto reply = client_->FinishUpload("no-such-upload");
398 wait_for(reply);353 wait_for(reply);
@@ -403,7 +358,7 @@
403358
404TEST_F(ProviderInterfaceTest, download)359TEST_F(ProviderInterfaceTest, download)
405{360{
406 make_provider(unique_ptr<ProviderBase>(new TestProvider));361 set_provider(unique_ptr<ProviderBase>(new TestProvider));
407362
408 QString download_id;363 QString download_id;
409 QDBusUnixFileDescriptor socket;364 QDBusUnixFileDescriptor socket;
@@ -446,7 +401,7 @@
446401
447TEST_F(ProviderInterfaceTest, download_short_read)402TEST_F(ProviderInterfaceTest, download_short_read)
448{403{
449 make_provider(unique_ptr<ProviderBase>(new TestProvider));404 set_provider(unique_ptr<ProviderBase>(new TestProvider));
450405
451 QString download_id;406 QString download_id;
452 QDBusUnixFileDescriptor socket;407 QDBusUnixFileDescriptor socket;
@@ -466,7 +421,7 @@
466421
467TEST_F(ProviderInterfaceTest, finish_download_unknown)422TEST_F(ProviderInterfaceTest, finish_download_unknown)
468{423{
469 make_provider(unique_ptr<ProviderBase>(new TestProvider));424 set_provider(unique_ptr<ProviderBase>(new TestProvider));
470425
471 auto reply = client_->FinishDownload("no-such-download");426 auto reply = client_->FinishDownload("no-such-download");
472 wait_for(reply);427 wait_for(reply);
@@ -477,7 +432,7 @@
477432
478TEST_F(ProviderInterfaceTest, delete_)433TEST_F(ProviderInterfaceTest, delete_)
479{434{
480 make_provider(unique_ptr<ProviderBase>(new TestProvider));435 set_provider(unique_ptr<ProviderBase>(new TestProvider));
481436
482 auto reply = client_->Delete("item_id");437 auto reply = client_->Delete("item_id");
483 wait_for(reply);438 wait_for(reply);
@@ -486,7 +441,7 @@
486441
487TEST_F(ProviderInterfaceTest, move)442TEST_F(ProviderInterfaceTest, move)
488{443{
489 make_provider(unique_ptr<ProviderBase>(new TestProvider));444 set_provider(unique_ptr<ProviderBase>(new TestProvider));
490445
491 auto reply = client_->Move("child_id", "new_parent_id", "New name");446 auto reply = client_->Move("child_id", "new_parent_id", "New name");
492 wait_for(reply);447 wait_for(reply);
@@ -500,7 +455,7 @@
500455
501TEST_F(ProviderInterfaceTest, copy)456TEST_F(ProviderInterfaceTest, copy)
502{457{
503 make_provider(unique_ptr<ProviderBase>(new TestProvider));458 set_provider(unique_ptr<ProviderBase>(new TestProvider));
504459
505 auto reply = client_->Copy("child_id", "new_parent_id", "New name");460 auto reply = client_->Copy("child_id", "new_parent_id", "New name");
506 wait_for(reply);461 wait_for(reply);
507462
=== modified file 'tests/remote-client/CMakeLists.txt'
--- tests/remote-client/CMakeLists.txt 2016-08-11 04:07:55 +0000
+++ tests/remote-client/CMakeLists.txt 2016-08-23 01:48:44 +0000
@@ -1,10 +1,11 @@
1add_executable(remote-client_test remote-client_test.cpp)1add_executable(remote-client_test remote-client_test.cpp MockProvider.cpp)
2set_target_properties(remote-client_test PROPERTIES AUTOMOC TRUE)2set_target_properties(remote-client_test PROPERTIES AUTOMOC TRUE)
33
4add_definitions(-DTEST_DIR="${CMAKE_CURRENT_BINARY_DIR}")4add_definitions(-DTEST_DIR="${CMAKE_CURRENT_BINARY_DIR}" -DBOOST_THREAD_VERSION=4)
5include_directories(${GLIB_DEPS_INCLUDE_DIRS})5include_directories(${GLIB_DEPS_INCLUDE_DIRS})
66
7target_link_libraries(remote-client_test7target_link_libraries(remote-client_test
8 storage-framework-provider
8 storage-framework-qt-client9 storage-framework-qt-client
9 Qt5::Network10 Qt5::Network
10 Qt5::Test11 Qt5::Test
1112
=== added file 'tests/remote-client/MockProvider.cpp'
--- tests/remote-client/MockProvider.cpp 1970-01-01 00:00:00 +0000
+++ tests/remote-client/MockProvider.cpp 2016-08-23 01:48:44 +0000
@@ -0,0 +1,236 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include "MockProvider.h"
20
21#include <unity/storage/provider/Exceptions.h>
22#include <unity/storage/provider/metadata_keys.h>
23
24#include <boost/thread.hpp>
25#include <boost/thread/future.hpp>
26
27#include <chrono>
28#include <thread>
29#include <inttypes.h>
30
31using namespace unity::storage;
32using namespace unity::storage::provider;
33using namespace std;
34
35using boost::make_exceptional_future;
36using boost::make_ready_future;
37
38MockProvider::MockProvider()
39{
40}
41
42MockProvider::MockProvider(string const& cmd)
43 : cmd_(cmd)
44{
45}
46
47boost::future<ItemList> MockProvider::roots(Context const&)
48{
49 ItemList roots =
50 {
51 {"root_id", {}, "Root", "etag", ItemType::root, {}}
52 };
53 return make_ready_future<ItemList>(roots);
54}
55
56boost::future<tuple<ItemList,string>> MockProvider::list(
57 string const& item_id, string const& page_token,
58 Context const&)
59{
60 if (item_id != "root_id")
61 {
62 string msg = string("Item::list(): no such item: \"") + item_id + "\"";
63 return make_exceptional_future<tuple<ItemList,string>>(NotExistsException(msg, item_id));
64 }
65 if (page_token != "")
66 {
67 string msg = string("Item::list(): invalid page token: \"") + page_token + "\"";
68 return make_exceptional_future<tuple<ItemList,string>>(LogicException("invalid page token"));
69 }
70 ItemList children =
71 {
72 {
73 "child_id", { "root_id" }, "Child", "etag", ItemType::file,
74 { { SIZE_IN_BYTES, 0 }, { LAST_MODIFIED_TIME, "2007-04-05T14:30Z" } }
75 }
76 };
77 boost::promise<tuple<ItemList,string>> p;
78 p.set_value(make_tuple(children, string()));
79 return p.get_future();
80}
81
82boost::future<ItemList> MockProvider::lookup(
83 string const& parent_id, string const& name, Context const&)
84{
85 if (parent_id != "root_id")
86 {
87 string msg = string("Folder::lookup(): no such item: \"") + parent_id + "\"";
88 return make_exceptional_future<ItemList>(NotExistsException(msg, parent_id));
89 }
90 if (name != "Child")
91 {
92 string msg = string("Folder::lookup(): no such item: \"") + name + "\"";
93 return make_exceptional_future<ItemList>(NotExistsException(msg, name));
94 }
95 ItemList children =
96 {
97 { "child_id", { "root_id" }, "Child", "etag", ItemType::file,
98 { { SIZE_IN_BYTES, 0 }, { LAST_MODIFIED_TIME, "2007-04-05T14:30Z" } } }
99 };
100 return make_ready_future<ItemList>(children);
101}
102
103boost::future<Item> MockProvider::metadata(string const& item_id, Context const&)
104{
105 if (item_id == "root_id")
106 {
107 Item metadata{"root_id", {}, "Root", "etag", ItemType::root, {}};
108 return make_ready_future<Item>(metadata);
109 }
110 else if (item_id == "child_id")
111 {
112 Item metadata
113 {
114 "child_id", { "root_id" }, "Child", "etag", ItemType::file,
115 { { SIZE_IN_BYTES, 0 }, { LAST_MODIFIED_TIME, "2007-04-05T14:30Z" } }
116 };
117 return make_ready_future<Item>(metadata);
118 }
119 else if (item_id == "child_folder_id")
120 {
121 Item metadata{"child_folder_id", { "root_id" }, "Child_Folder", "etag", ItemType::folder, {}};
122 return make_ready_future<Item>(metadata);
123 }
124 return make_exceptional_future<Item>(NotExistsException("metadata(): no such item: " + item_id, item_id));
125}
126
127boost::future<Item> MockProvider::create_folder(
128 string const& parent_id, string const& name,
129 Context const&)
130{
131 Item metadata{"new_folder_id", { parent_id }, name, "etag", ItemType::folder, {}};
132 return make_ready_future<Item>(metadata);
133}
134
135string make_job_id()
136{
137 static int last_job_id = 0;
138 return to_string(++last_job_id);
139}
140
141boost::future<unique_ptr<UploadJob>> MockProvider::create_file(
142 string const&, string const&,
143 int64_t, string const&, bool, Context const&)
144{
145 return make_ready_future<unique_ptr<UploadJob>>(new MockUploadJob(make_job_id()));
146}
147
148boost::future<unique_ptr<UploadJob>> MockProvider::update(
149 string const&, int64_t, string const&, Context const&)
150{
151 return make_ready_future<unique_ptr<UploadJob>>(new MockUploadJob(make_job_id()));
152}
153
154boost::future<unique_ptr<DownloadJob>> MockProvider::download(
155 string const&, Context const&)
156{
157 unique_ptr<DownloadJob> job(new MockDownloadJob(make_job_id()));
158 const char contents[] = "Hello world";
159 if (write(job->write_socket(), contents, sizeof(contents)) != sizeof(contents))
160 {
161 ResourceException e("download(): write failed", errno);
162 job->report_error(make_exception_ptr(e));
163 return make_exceptional_future<unique_ptr<DownloadJob>>(e);
164 }
165 job->report_complete();
166 return make_ready_future(std::move(job));
167}
168
169boost::future<void> MockProvider::delete_item(
170 string const&, Context const&)
171{
172 return make_ready_future();
173}
174
175boost::future<Item> MockProvider::move(
176 string const& item_id, string const& new_parent_id,
177 string const& new_name, Context const&)
178{
179 Item metadata{item_id, { new_parent_id }, new_name, "etag", ItemType::file, {}};
180 return make_ready_future(metadata);
181}
182
183boost::future<Item> MockProvider::copy(
184 string const&, string const& new_parent_id,
185 string const& new_name, Context const&)
186{
187 Item metadata{"new_item_id", { new_parent_id }, new_name, "etag", ItemType::file, {}};
188 return make_ready_future(metadata);
189}
190
191MockUploadJob::MockUploadJob()
192 : UploadJob("some_id")
193{
194}
195
196MockUploadJob::MockUploadJob(string const& cmd)
197 : UploadJob("some_id")
198 , cmd_(cmd)
199{
200}
201
202boost::future<void> MockUploadJob::cancel()
203{
204 return make_ready_future();
205}
206
207boost::future<Item> MockUploadJob::finish()
208{
209 Item metadata
210 {
211 "some_id", { "root_id" }, "some_upload", "etag", ItemType::file,
212 { { SIZE_IN_BYTES, 10 }, { LAST_MODIFIED_TIME, "2011-04-05T14:30:10.005Z" } }
213 };
214 return make_ready_future(metadata);
215}
216
217MockDownloadJob::MockDownloadJob()
218 : DownloadJob("some_id")
219{
220}
221
222MockDownloadJob::MockDownloadJob(string const& cmd)
223 : DownloadJob("some_id")
224 , cmd_(cmd)
225{
226}
227
228boost::future<void> MockDownloadJob::cancel()
229{
230 return make_ready_future();
231}
232
233boost::future<void> MockDownloadJob::finish()
234{
235 return make_ready_future();
236}
0237
=== added file 'tests/remote-client/MockProvider.h'
--- tests/remote-client/MockProvider.h 1970-01-01 00:00:00 +0000
+++ tests/remote-client/MockProvider.h 2016-08-23 01:48:44 +0000
@@ -0,0 +1,96 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/provider/DownloadJob.h>
22#include <unity/storage/provider/ProviderBase.h>
23#include <unity/storage/provider/UploadJob.h>
24
25class MockProvider : public unity::storage::provider::ProviderBase
26{
27public:
28 MockProvider();
29 MockProvider(std::string const& cmd);
30
31 boost::future<unity::storage::provider::ItemList> roots(unity::storage::provider::Context const& ctx) override;
32 boost::future<std::tuple<unity::storage::provider::ItemList, std::string>> list(
33 std::string const& item_id, std::string const& page_token,
34 unity::storage::provider::Context const& ctx) override;
35 boost::future<unity::storage::provider::ItemList> lookup(
36 std::string const& parent_id, std::string const& name,
37 unity::storage::provider::Context const& ctx) override;
38 boost::future<unity::storage::provider::Item> metadata(
39 std::string const& item_id, unity::storage::provider::Context const& ctx) override;
40 boost::future<unity::storage::provider::Item> create_folder(
41 std::string const& parent_id, std::string const& name,
42 unity::storage::provider::Context const& ctx) override;
43
44 boost::future<std::unique_ptr<unity::storage::provider::UploadJob>> create_file(
45 std::string const& parent_id, std::string const& name,
46 int64_t size, std::string const& content_type, bool allow_overwrite,
47 unity::storage::provider::Context const& ctx) override;
48 boost::future<std::unique_ptr<unity::storage::provider::UploadJob>> update(
49 std::string const& item_id, int64_t size, std::string const& old_etag,
50 unity::storage::provider::Context const& ctx) override;
51
52 boost::future<std::unique_ptr<unity::storage::provider::DownloadJob>> download(
53 std::string const& item_id, unity::storage::provider::Context const& ctx) override;
54
55 boost::future<void> delete_item(
56 std::string const& item_id, unity::storage::provider::Context const& ctx) override;
57 boost::future<unity::storage::provider::Item> move(
58 std::string const& item_id, std::string const& new_parent_id,
59 std::string const& new_name, unity::storage::provider::Context const& ctx) override;
60 boost::future<unity::storage::provider::Item> copy(
61 std::string const& item_id, std::string const& new_parent_id,
62 std::string const& new_name, unity::storage::provider::Context const& ctx) override;
63
64private:
65 std::string cmd_;
66};
67
68class MockUploadJob : public unity::storage::provider::UploadJob
69{
70public:
71 using UploadJob::UploadJob;
72
73 MockUploadJob();
74 MockUploadJob(std::string const& cmd);
75
76 boost::future<void> cancel() override;
77 boost::future<unity::storage::provider::Item> finish() override;
78
79private:
80 std::string cmd_;
81};
82
83class MockDownloadJob : public unity::storage::provider::DownloadJob
84{
85public:
86 using DownloadJob::DownloadJob;
87
88 MockDownloadJob();
89 MockDownloadJob(const std::string& cmd);
90
91 boost::future<void> cancel() override;
92 boost::future<void> finish() override;
93
94private:
95 std::string cmd_;
96};
097
=== modified file 'tests/remote-client/remote-client_test.cpp'
--- tests/remote-client/remote-client_test.cpp 2016-08-19 03:16:52 +0000
+++ tests/remote-client/remote-client_test.cpp 2016-08-23 01:48:44 +0000
@@ -19,6 +19,8 @@
19#include <unity/storage/qt/client/client-api.h>19#include <unity/storage/qt/client/client-api.h>
2020
21#include <utils/DBusEnvironment.h>21#include <utils/DBusEnvironment.h>
22#include <utils/ProviderFixture.h>
23#include <MockProvider.h>
2224
23#include <gtest/gtest.h>25#include <gtest/gtest.h>
24#include <QCoreApplication>26#include <QCoreApplication>
@@ -71,37 +73,64 @@
71class FileTest : public RemoteClientTest {};73class FileTest : public RemoteClientTest {};
72class ItemTest : public RemoteClientTest {};74class ItemTest : public RemoteClientTest {};
7375
76class DestroyedTest : public ProviderFixture
77{
78protected:
79 void SetUp() override
80 {
81 runtime_ = Runtime::create(connection());
82 acc_ = runtime_->make_test_account(service_connection_->baseService(), bus_path());
83 }
84
85 void TearDown() override
86 {
87 }
88
89 Runtime::SPtr runtime_;
90 Account::SPtr acc_;
91};
92
74// Bunch of helper functions to reduce the amount of noise in the tests.93// Bunch of helper functions to reduce the amount of noise in the tests.
7594
76template<typename T>95template<typename T>
77void wait(T fut)96bool wait(T fut)
78{97{
79 QFutureWatcher<decltype(fut.result())> w;98 QFutureWatcher<decltype(fut.result())> w;
80 QSignalSpy spy(&w, &decltype(w)::finished);99 QSignalSpy spy(&w, &decltype(w)::finished);
81 w.setFuture(fut);100 w.setFuture(fut);
82 ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));101 bool rc = spy.wait(SIGNAL_WAIT_TIME);
102 EXPECT_TRUE(rc);
103 return rc;
83}104}
84105
85template<>106template<>
86void wait(QFuture<void> fut)107bool wait(QFuture<void> fut)
87{108{
88 QFutureWatcher<void> w;109 QFutureWatcher<void> w;
89 QSignalSpy spy(&w, &decltype(w)::finished);110 QSignalSpy spy(&w, &decltype(w)::finished);
90 w.setFuture(fut);111 w.setFuture(fut);
91 ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));112 bool rc = spy.wait(SIGNAL_WAIT_TIME);
113 EXPECT_TRUE(rc);
114 return rc;
92}115}
93116
94template <typename T>117template <typename T>
95T call(QFuture<T> fut)118T call(QFuture<T> fut)
96{119{
97 wait(fut);120 if (!wait(fut))
121 {
122 throw runtime_error("call timed out");
123 }
98 return fut.result();124 return fut.result();
99}125}
100126
101template <>127template <>
102void call(QFuture<void> fut)128void call(QFuture<void> fut)
103{129{
104 wait(fut);130 if (!wait(fut))
131 {
132 throw runtime_error("call timed out");
133 }
105 fut.waitForFinished();134 fut.waitForFinished();
106}135}
107136
@@ -114,7 +143,14 @@
114 qCritical() << "Configure at least one online account for a provider in System Settings -> Online Accounts";143 qCritical() << "Configure at least one online account for a provider in System Settings -> Online Accounts";
115 return nullptr;144 return nullptr;
116 }145 }
117 return accounts[0];146 for (auto acc : accounts)
147 {
148 if (acc->owner_id() == "google-drive-scope")
149 {
150 return acc;
151 }
152 }
153 abort(); // Impossible
118}154}
119155
120Root::SPtr get_root(Runtime::SPtr const& runtime)156Root::SPtr get_root(Runtime::SPtr const& runtime)
@@ -139,7 +175,7 @@
139 assert(items.size() != 0); // TODO: temporary hack for use with demo provider175 assert(items.size() != 0); // TODO: temporary hack for use with demo provider
140 for (auto i : items)176 for (auto i : items)
141 {177 {
142 wait(i->delete_item());178 call(i->delete_item());
143 }179 }
144}180}
145181
@@ -282,7 +318,7 @@
282318
283TEST_F(RuntimeTest, runtime_destroyed_exceptions)319TEST_F(RuntimeTest, runtime_destroyed_exceptions)
284{320{
285 // Gettting an account after shutting down the runtime must fail.321 // Getting the runtime from an account after shutting down the runtime must fail.
286 {322 {
287 auto runtime = Runtime::create(connection());323 auto runtime = Runtime::create(connection());
288 auto acc = get_account(runtime);324 auto acc = get_account(runtime);
@@ -298,7 +334,7 @@
298 }334 }
299 }335 }
300336
301 // Getting an account after destroying the runtime must fail.337 // Getting the runtime from an account after destroying the runtime must fail.
302 {338 {
303 auto runtime = Runtime::create(connection());339 auto runtime = Runtime::create(connection());
304 auto acc = get_account(runtime);340 auto acc = get_account(runtime);
@@ -329,6 +365,22 @@
329 }365 }
330 }366 }
331367
368 // Getting roots from an account after shutting down the runtime must fail.
369 {
370 auto runtime = Runtime::create(connection());
371 auto acc = get_account(runtime);
372 runtime->shutdown();
373 try
374 {
375 call(acc->roots());
376 FAIL();
377 }
378 catch (RuntimeDestroyedException const& e)
379 {
380 EXPECT_EQ("Account::roots(): runtime was destroyed previously", e.error_message());
381 }
382 }
383
332 // Getting the account from a root with a destroyed runtime must fail.384 // Getting the account from a root with a destroyed runtime must fail.
333 {385 {
334 auto runtime = Runtime::create(connection());386 auto runtime = Runtime::create(connection());
@@ -888,6 +940,198 @@
888 }940 }
889}941}
890942
943TEST_F(DestroyedTest, roots_destroyed_while_reply_outstanding)
944{
945 set_provider(unique_ptr<provider::ProviderBase>(new MockProvider));
946
947 auto fut = acc_->roots();
948 runtime_->shutdown();
949 try
950 {
951 ASSERT_TRUE(wait(fut));
952 fut.result();
953 FAIL();
954 }
955 catch (RuntimeDestroyedException const& e)
956 {
957 EXPECT_EQ("Account::roots(): runtime was destroyed previously", e.error_message());
958 }
959}
960
961TEST_F(DestroyedTest, get_destroyed_while_reply_outstanding)
962{
963 set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("metadata slow")));
964
965 auto root = call(acc_->roots())[0];
966 auto fut = root->get("root_id");
967 runtime_->shutdown();
968 try
969 {
970 ASSERT_TRUE(wait(fut));
971 fut.result();
972 FAIL();
973 }
974 catch (RuntimeDestroyedException const& e)
975 {
976 EXPECT_EQ("Root::get(): runtime was destroyed previously", e.error_message());
977 }
978}
979
980TEST_F(DestroyedTest, copy_destroyed_while_reply_outstanding)
981{
982 set_provider(unique_ptr<provider::ProviderBase>(new MockProvider()));
983
984 auto root = call(acc_->roots())[0];
985 auto fut = root->copy(root, "new name");
986 runtime_->shutdown();
987 try
988 {
989 ASSERT_TRUE(wait(fut));
990 fut.result();
991 FAIL();
992 }
993 catch (RuntimeDestroyedException const& e)
994 {
995 EXPECT_EQ("Item::copy(): runtime was destroyed previously", e.error_message());
996 }
997}
998
999TEST_F(DestroyedTest, move_destroyed_while_reply_outstanding)
1000{
1001 set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("move slow")));
1002
1003 auto root = call(acc_->roots())[0];
1004 auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
1005 auto fut = file->move(root, "new name");
1006 runtime_->shutdown();
1007 try
1008 {
1009 ASSERT_TRUE(wait(fut));
1010 fut.result();
1011 FAIL();
1012 }
1013 catch (RuntimeDestroyedException const& e)
1014 {
1015 EXPECT_EQ("Item::move(): runtime was destroyed previously", e.error_message());
1016 }
1017}
1018
1019TEST_F(DestroyedTest, list_destroyed_while_reply_outstanding)
1020{
1021 set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("list slow")));
1022
1023 auto root = call(acc_->roots())[0];
1024 auto fut = root->list();
1025 runtime_->shutdown();
1026 try
1027 {
1028 ASSERT_TRUE(wait(fut));
1029 fut.result();
1030 FAIL();
1031 }
1032 catch (RuntimeDestroyedException const& e)
1033 {
1034 EXPECT_EQ("Folder::list(): runtime was destroyed previously", e.error_message());
1035 }
1036}
1037
1038TEST_F(DestroyedTest, lookup_destroyed_while_reply_outstanding)
1039{
1040 set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("lookup slow")));
1041
1042 auto root = call(acc_->roots())[0];
1043 auto fut = root->lookup("Child");
1044 runtime_->shutdown();
1045 try
1046 {
1047 ASSERT_TRUE(wait(fut));
1048 fut.result();
1049 FAIL();
1050 }
1051 catch (RuntimeDestroyedException const& e)
1052 {
1053 EXPECT_EQ("Folder::lookup(): runtime was destroyed previously", e.error_message());
1054 }
1055}
1056
1057TEST_F(DestroyedTest, create_folder_destroyed_while_reply_outstanding)
1058{
1059 set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("create_folder slow")));
1060
1061 auto root = call(acc_->roots())[0];
1062 auto fut = root->create_folder("Child");
1063 runtime_->shutdown();
1064 try
1065 {
1066 ASSERT_TRUE(wait(fut));
1067 fut.result();
1068 FAIL();
1069 }
1070 catch (RuntimeDestroyedException const& e)
1071 {
1072 EXPECT_EQ("Folder::create_folder(): runtime was destroyed previously", e.error_message());
1073 }
1074}
1075
1076TEST_F(DestroyedTest, create_file_destroyed_while_reply_outstanding)
1077{
1078 set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("create_file slow")));
1079
1080 auto root = call(acc_->roots())[0];
1081 auto fut = root->create_file("Child", 0);
1082 runtime_->shutdown();
1083 try
1084 {
1085 ASSERT_TRUE(wait(fut));
1086 fut.result();
1087 FAIL();
1088 }
1089 catch (RuntimeDestroyedException const& e)
1090 {
1091 EXPECT_EQ("Folder::create_file(): runtime was destroyed previously", e.error_message());
1092 }
1093}
1094
1095TEST_F(DestroyedTest, create_uploader_destroyed_while_reply_outstanding)
1096{
1097 set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("create_file slow")));
1098
1099 auto root = call(acc_->roots())[0];
1100 auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
1101 auto fut = file->create_uploader(ConflictPolicy::overwrite, 0);
1102 runtime_->shutdown();
1103 try
1104 {
1105 ASSERT_TRUE(wait(fut));
1106 fut.result();
1107 FAIL();
1108 }
1109 catch (RuntimeDestroyedException const& e)
1110 {
1111 EXPECT_EQ("File::create_uploader(): runtime was destroyed previously", e.error_message());
1112 }
1113}
1114
1115TEST_F(DestroyedTest, create_downloader_destroyed_while_reply_outstanding)
1116{
1117 set_provider(unique_ptr<provider::ProviderBase>(new MockProvider("create_file slow")));
1118
1119 auto root = call(acc_->roots())[0];
1120 auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
1121 auto fut = file->create_downloader();
1122 runtime_->shutdown();
1123 try
1124 {
1125 ASSERT_TRUE(wait(fut));
1126 fut.result();
1127 FAIL();
1128 }
1129 catch (RuntimeDestroyedException const& e)
1130 {
1131 EXPECT_EQ("File::create_downloader(): runtime was destroyed previously", e.error_message());
1132 }
1133}
1134
891int main(int argc, char** argv)1135int main(int argc, char** argv)
892{1136{
893 QCoreApplication app(argc, argv);1137 QCoreApplication app(argc, argv);
8941138
=== modified file 'tests/utils/CMakeLists.txt'
--- tests/utils/CMakeLists.txt 2016-07-12 06:42:53 +0000
+++ tests/utils/CMakeLists.txt 2016-08-23 01:48:44 +0000
@@ -1,9 +1,23 @@
1pkg_check_modules(QTDBUSTEST_DEPS libqtdbustest-1 REQUIRED)1pkg_check_modules(QTDBUSTEST_DEPS libqtdbustest-1 REQUIRED)
22
3set_source_files_properties(${CMAKE_SOURCE_DIR}/data/provider.xml PROPERTIES
4 CLASSNAME ProviderClient
5 INCLUDE unity/storage/internal/dbusmarshal.h
6)
7qt5_add_dbus_interface(generated_files
8 ${CMAKE_SOURCE_DIR}/data/provider.xml
9 ProviderClient
10)
11set_source_files_properties(${generated_files} PROPERTIES GENERATED TRUE)
12
3add_library(testutils STATIC13add_library(testutils STATIC
4 DBusEnvironment.cpp14 DBusEnvironment.cpp
15 ProviderFixture.cpp
16 ${generated_files}
5)17)
6target_compile_options(testutils PRIVATE ${QTDBUSTEST_DEPS_CFLAGS})18target_compile_options(testutils PRIVATE ${QTDBUSTEST_DEPS_CFLAGS} ${ONLINEACCOUNTS_DEPS_CFLAGS})
7target_link_libraries(testutils19target_link_libraries(testutils
8 PUBLIC Qt5::DBus Qt5::Core20 PUBLIC Qt5::DBus Qt5::Core
9 PRIVATE ${QTDBUSTEST_DEPS_LIBRARIES})21 PRIVATE Qt5::Test ${QTDBUSTEST_DEPS_LIBRARIES} ${ONLINEAACOUNTS_DEPS_LIBRARIES})
22
23add_definitions(-DBOOST_THREAD_VERSION=4)
1024
=== added file 'tests/utils/ProviderFixture.cpp'
--- tests/utils/ProviderFixture.cpp 1970-01-01 00:00:00 +0000
+++ tests/utils/ProviderFixture.cpp 2016-08-23 01:48:44 +0000
@@ -0,0 +1,79 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: James Henstridge <james.henstridge@canonical.com>
17 */
18
19#include "ProviderFixture.h"
20
21#include <unity/storage/internal/dbus_error.h>
22
23#include <QSignalSpy>
24
25using namespace unity::storage::provider;
26using namespace std;
27
28namespace
29{
30
31const auto SERVICE_CONNECTION_NAME = QStringLiteral("service-session-bus");
32const auto BUS_PATH = QStringLiteral("/provider");
33
34} // namespace
35
36ProviderFixture::ProviderFixture()
37{
38 dbus_.reset(new DBusEnvironment);
39 dbus_->start_services();
40 service_connection_.reset(new QDBusConnection(QDBusConnection::connectToBus(dbus_->busAddress(),
41 SERVICE_CONNECTION_NAME)));
42 account_manager_.reset(new OnlineAccounts::Manager("", *service_connection_));
43}
44
45ProviderFixture::~ProviderFixture()
46{
47 test_server_.reset();
48 service_connection_.reset();
49 QDBusConnection::disconnectFromBus(SERVICE_CONNECTION_NAME);
50 dbus_.reset();
51}
52
53QDBusConnection const& ProviderFixture::connection() const
54{
55 return dbus_->connection();
56}
57
58void ProviderFixture::set_provider(unique_ptr<ProviderBase>&& provider)
59{
60 account_manager_->waitForReady();
61 OnlineAccounts::Account* account = account_manager_->account(2, "oauth2-service");
62 ASSERT_NE(nullptr, account);
63
64 test_server_.reset(
65 new unity::storage::provider::testing::TestServer(move(provider), account,
66 *service_connection_, BUS_PATH.toStdString()));
67}
68
69void ProviderFixture::wait_for(QDBusPendingCall const& call)
70{
71 QDBusPendingCallWatcher watcher(call);
72 QSignalSpy spy(&watcher, &QDBusPendingCallWatcher::finished);
73 ASSERT_TRUE(spy.wait());
74}
75
76QString ProviderFixture::bus_path() const
77{
78 return BUS_PATH;
79}
080
=== added file 'tests/utils/ProviderFixture.h'
--- tests/utils/ProviderFixture.h 1970-01-01 00:00:00 +0000
+++ tests/utils/ProviderFixture.h 2016-08-23 01:48:44 +0000
@@ -0,0 +1,49 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: James Henstridge <james.henstridge@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/provider/ProviderBase.h>
22#include <unity/storage/provider/testing/TestServer.h>
23#include <utils/DBusEnvironment.h>
24#include <utils/ProviderClient.h>
25
26#include <gtest/gtest.h>
27#include <OnlineAccounts/Account>
28#include <OnlineAccounts/Manager>
29#include <QDBusConnection>
30
31#include <memory>
32
33class ProviderFixture : public ::testing::Test
34{
35public:
36 ProviderFixture();
37 virtual ~ProviderFixture();
38
39 QDBusConnection const& connection() const;
40 void set_provider(std::unique_ptr<unity::storage::provider::ProviderBase>&& provider);
41 void wait_for(QDBusPendingCall const& call);
42 QString bus_path() const;
43
44protected:
45 std::unique_ptr<DBusEnvironment> dbus_;
46 std::unique_ptr<QDBusConnection> service_connection_;
47 std::unique_ptr<OnlineAccounts::Manager> account_manager_;
48 std::unique_ptr<unity::storage::provider::testing::TestServer> test_server_;
49};

Subscribers

People subscribed via source and target branches

to all changes: