From 6d227a437a6b52f6bc0e75f459d79e22e3d8fb2d Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 18 Jul 2016 13:54:06 +0600 Subject: TESTBED: Add CloudTests::testUploading() --- engines/testbed/cloud.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++++-- engines/testbed/cloud.h | 2 + 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 @@ -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(&directoryListedCallback), - new Common::GlobalFunctionCallback(&errorCallback) + "", + new Common::GlobalFunctionCallback(&directoryListedCallback), + new Common::GlobalFunctionCallback(&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(&fileUploadedCallback), + new Common::GlobalFunctionCallback(&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(&fileUploadedCallback), + new Common::GlobalFunctionCallback(&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(&directoryListedCallback), + new Common::GlobalFunctionCallback(&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 -- cgit v1.2.3