~jamesh/storage-provider-webdav/error-on-list-file

« back to all changes in this revision

Viewing changes to tests/davprovider/davprovider_test.cpp

  • Committer: Tarmac
  • Author(s): James Henstridge
  • Date: 2016-11-11 09:39:03 UTC
  • mfrom: (14.1.5 delete-item)
  • Revision ID: tarmac-20161111093903-b9wrr227fdtcbxlg
Implemente the delete_item D-Bus operation.

Approved by unity-api-1-bot, Michi Henning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1024
1024
    }
1025
1025
}
1026
1026
 
 
1027
TEST_F(DavProviderTests, delete_item)
 
1028
{
 
1029
    auto account = get_client();
 
1030
    make_file("foo.txt");
 
1031
 
 
1032
    shared_ptr<Root> root;
 
1033
    {
 
1034
        QFutureWatcher<QVector<shared_ptr<Root>>> watcher;
 
1035
        QSignalSpy spy(&watcher, &decltype(watcher)::finished);
 
1036
        watcher.setFuture(account->roots());
 
1037
        if (spy.count() == 0)
 
1038
        {
 
1039
            ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
 
1040
        }
 
1041
        auto roots = watcher.result();
 
1042
        ASSERT_EQ(1, roots.size());
 
1043
        root = roots[0];
 
1044
    }
 
1045
 
 
1046
    shared_ptr<Item> item;
 
1047
    {
 
1048
        QFutureWatcher<shared_ptr<Item>> watcher;
 
1049
        QSignalSpy spy(&watcher, &decltype(watcher)::finished);
 
1050
        watcher.setFuture(root->get("foo.txt"));
 
1051
        if (spy.count() == 0)
 
1052
        {
 
1053
            ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
 
1054
        }
 
1055
        item = watcher.result();
 
1056
    }
 
1057
 
 
1058
    {
 
1059
        QFutureWatcher<void> watcher;
 
1060
        QSignalSpy spy(&watcher, &decltype(watcher)::finished);
 
1061
        watcher.setFuture(item->delete_item());
 
1062
        if (spy.count() == 0)
 
1063
        {
 
1064
            ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
 
1065
        }
 
1066
        watcher.waitForFinished(); // to catch any errors
 
1067
    }
 
1068
 
 
1069
    struct stat buf;
 
1070
    EXPECT_EQ(-1, stat(local_file("foo.txt").c_str(), &buf));
 
1071
    EXPECT_EQ(ENOENT, errno);
 
1072
}
 
1073
 
 
1074
TEST_F(DavProviderTests, delete_item_not_found)
 
1075
{
 
1076
    auto account = get_client();
 
1077
    make_file("foo.txt");
 
1078
 
 
1079
    shared_ptr<Root> root;
 
1080
    {
 
1081
        QFutureWatcher<QVector<shared_ptr<Root>>> watcher;
 
1082
        QSignalSpy spy(&watcher, &decltype(watcher)::finished);
 
1083
        watcher.setFuture(account->roots());
 
1084
        if (spy.count() == 0)
 
1085
        {
 
1086
            ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
 
1087
        }
 
1088
        auto roots = watcher.result();
 
1089
        ASSERT_EQ(1, roots.size());
 
1090
        root = roots[0];
 
1091
    }
 
1092
 
 
1093
    shared_ptr<Item> item;
 
1094
    {
 
1095
        QFutureWatcher<shared_ptr<Item>> watcher;
 
1096
        QSignalSpy spy(&watcher, &decltype(watcher)::finished);
 
1097
        watcher.setFuture(root->get("foo.txt"));
 
1098
        if (spy.count() == 0)
 
1099
        {
 
1100
            ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
 
1101
        }
 
1102
        item = watcher.result();
 
1103
    }
 
1104
 
 
1105
    ASSERT_EQ(0, unlink(local_file("foo.txt").c_str()));
 
1106
 
 
1107
    {
 
1108
        QFutureWatcher<void> watcher;
 
1109
        QSignalSpy spy(&watcher, &decltype(watcher)::finished);
 
1110
        watcher.setFuture(item->delete_item());
 
1111
        if (spy.count() == 0)
 
1112
        {
 
1113
            ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
 
1114
        }
 
1115
        try
 
1116
        {
 
1117
            watcher.waitForFinished(); // to catch any errors
 
1118
            FAIL();
 
1119
        }
 
1120
        catch (RemoteCommsException const& e)
 
1121
        {
 
1122
            EXPECT_EQ("Error from DELETE: 404", e.error_message());
 
1123
        }
 
1124
    }
 
1125
}
 
1126
 
1027
1127
int main(int argc, char**argv)
1028
1128
{
1029
1129
    QCoreApplication app(argc, argv);