aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-18 13:54:06 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit6d227a437a6b52f6bc0e75f459d79e22e3d8fb2d (patch)
treee746f22df6184ec925fa9e4fe3f0e12eb54c3e78 /engines
parent721ee9527e9ff8d028aa0ba70fb4e4c80f7e6060 (diff)
downloadscummvm-rg350-6d227a437a6b52f6bc0e75f459d79e22e3d8fb2d.tar.gz
scummvm-rg350-6d227a437a6b52f6bc0e75f459d79e22e3d8fb2d.tar.bz2
scummvm-rg350-6d227a437a6b52f6bc0e75f459d79e22e3d8fb2d.zip
TESTBED: Add CloudTests::testUploading()
Diffstat (limited to 'engines')
-rw-r--r--engines/testbed/cloud.cpp103
-rw-r--r--engines/testbed/cloud.h2
2 files changed, 101 insertions, 4 deletions
diff --git a/engines/testbed/cloud.cpp b/engines/testbed/cloud.cpp
index 73b0b8b5c1..5138454bd8 100644
--- a/engines/testbed/cloud.cpp
+++ b/engines/testbed/cloud.cpp
@@ -23,7 +23,7 @@
#include "common/config-manager.h"
#include "common/stream.h"
#include "common/util.h"
-
+#include "testbed/fs.h"
#include "testbed/cloud.h"
#include <backends/cloud/cloudmanager.h>
@@ -40,6 +40,7 @@ CloudTestSuite::CloudTestSuite() {
addTest("UserInfo", &CloudTests::testInfo, true);
addTest("ListDirectory", &CloudTests::testDirectoryListing, true);
addTest("CreateDirectory", &CloudTests::testDirectoryCreating, true);
+ addTest("FileUpload", &CloudTests::testUploading, true);
}
/*
@@ -121,6 +122,12 @@ void CloudTests::directoryCreatedCallback(Cloud::Storage::BoolResponse response)
}
}
+void CloudTests::fileUploadedCallback(Cloud::Storage::UploadResponse response) {
+ ConfParams.setCloudTestCallbackCalled(true);
+ Testsuite::logPrintf("Info! Uploaded file into '%s'\n", response.value.path().c_str());
+ Testsuite::logPrintf("Info! It's id = '%s' and size = '%lu'\n", response.value.id().c_str(), response.value.size());
+}
+
void CloudTests::errorCallback(Networking::ErrorResponse response) {
ConfParams.setCloudTestErrorCallbackCalled(true);
Testsuite::logPrintf("Info! Error Callback was called\n");
@@ -268,9 +275,9 @@ TestExitStatus CloudTests::testDirectoryCreating() {
// list it again
if (CloudMan.listDirectory(
- "",
- new Common::GlobalFunctionCallback<Cloud::Storage::FileArrayResponse>(&directoryListedCallback),
- new Common::GlobalFunctionCallback<Networking::ErrorResponse>(&errorCallback)
+ "",
+ new Common::GlobalFunctionCallback<Cloud::Storage::FileArrayResponse>(&directoryListedCallback),
+ new Common::GlobalFunctionCallback<Networking::ErrorResponse>(&errorCallback)
) == nullptr) {
Testsuite::logPrintf("Warning! No Request is returned!\n");
}
@@ -292,4 +299,92 @@ TestExitStatus CloudTests::testDirectoryCreating() {
return kTestPassed;
}
+TestExitStatus CloudTests::testUploading() {
+ ConfParams.setCloudTestCallbackCalled(false);
+ ConfParams.setCloudTestErrorCallbackCalled(false);
+
+ if (CloudMan.getCurrentStorage() == nullptr) {
+ Testsuite::logPrintf("Couldn't find connected Storage\n");
+ return kTestFailed;
+ }
+
+ Common::String info = "Testing Cloud Storage API upload() method.\n"
+ "In this test we'll try to upload a 'test1/file.txt' file.";
+
+ if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
+ Testsuite::logPrintf("Info! Skipping test : upload()\n");
+ return kTestSkipped;
+ }
+
+ if (!ConfParams.isGameDataFound()) {
+ Testsuite::logPrintf("Info! Couldn't find the game data, so skipping test : upload()\n");
+ return kTestSkipped;
+ }
+
+ const Common::String &path = ConfMan.get("path");
+ Common::FSDirectory gameRoot(path);
+ Common::FSDirectory *directory = gameRoot.getSubDirectory("test1");
+ Common::FSNode node = directory->getFSNode().getChild("file.txt");
+ delete directory;
+
+ if (CloudMan.getCurrentStorage()->uploadStreamSupported()) {
+ if (CloudMan.getCurrentStorage()->upload(
+ "/testbed/testfile.txt",
+ node.createReadStream(),
+ new Common::GlobalFunctionCallback<Cloud::Storage::UploadResponse>(&fileUploadedCallback),
+ new Common::GlobalFunctionCallback<Networking::ErrorResponse>(&errorCallback)
+ ) == nullptr) {
+ Testsuite::logPrintf("Warning! No Request is returned!\n");
+ }
+ } else {
+ Common::String filepath = node.getPath();
+ if (CloudMan.getCurrentStorage()->upload(
+ "/testbed/testfile.txt",
+ filepath.c_str(),
+ new Common::GlobalFunctionCallback<Cloud::Storage::UploadResponse>(&fileUploadedCallback),
+ new Common::GlobalFunctionCallback<Networking::ErrorResponse>(&errorCallback)
+ ) == nullptr) {
+ Testsuite::logPrintf("Warning! No Request is returned!\n");
+ }
+ }
+
+ if (!waitForCallbackMore()) return kTestSkipped;
+ Testsuite::clearScreen();
+
+ if (ConfParams.isCloudTestErrorCallbackCalled()) {
+ Testsuite::logPrintf("Error callback was called\n");
+ return kTestFailed;
+ }
+
+ Common::String info2 = "upload() is finished. Do you want to list '/testbed' directory?";
+
+ if (!Testsuite::handleInteractiveInput(info2, "Yes", "No", kOptionRight)) {
+ ConfParams.setCloudTestCallbackCalled(false);
+
+ if (CloudMan.listDirectory(
+ "/testbed/",
+ new Common::GlobalFunctionCallback<Cloud::Storage::FileArrayResponse>(&directoryListedCallback),
+ new Common::GlobalFunctionCallback<Networking::ErrorResponse>(&errorCallback)
+ ) == nullptr) {
+ Testsuite::logPrintf("Warning! No Request is returned!\n");
+ }
+
+ if (!waitForCallbackMore()) return kTestSkipped;
+ Testsuite::clearScreen();
+
+ if (ConfParams.isCloudTestErrorCallbackCalled()) {
+ Testsuite::logPrintf("Error callback was called\n");
+ return kTestFailed;
+ }
+ }
+
+ if (Testsuite::handleInteractiveInput("Was the CloudMan able to upload into 'testbed/testfile.txt' file?", "Yes", "No", kOptionRight)) {
+ Testsuite::logDetailedPrintf("Error! File was not uploaded!\n");
+ return kTestFailed;
+ }
+
+ Testsuite::logDetailedPrintf("File was uploaded\n");
+ return kTestPassed;
+}
+
} // End of namespace Testbed
diff --git a/engines/testbed/cloud.h b/engines/testbed/cloud.h
index 17bc0938c9..177ac740a9 100644
--- a/engines/testbed/cloud.h
+++ b/engines/testbed/cloud.h
@@ -39,11 +39,13 @@ bool waitForCallbackMore();
void infoCallback(Cloud::Storage::StorageInfoResponse response);
void directoryListedCallback(Cloud::Storage::FileArrayResponse response);
void directoryCreatedCallback(Cloud::Storage::BoolResponse response);
+void fileUploadedCallback(Cloud::Storage::UploadResponse response);
void errorCallback(Networking::ErrorResponse response);
TestExitStatus testInfo();
TestExitStatus testDirectoryListing();
TestExitStatus testDirectoryCreating();
+TestExitStatus testUploading();
} // End of namespace CloudTests