aboutsummaryrefslogtreecommitdiff
path: root/engines/testbed/webserver.cpp
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-18 16:47:37 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit830c7b578caaec95594e190d6727892b1973df62 (patch)
tree4546a4645e213b3a06713a31dbde90ba674d1ca7 /engines/testbed/webserver.cpp
parentb616cc3d574a4120440044b386f690f6d7f51a5f (diff)
downloadscummvm-rg350-830c7b578caaec95594e190d6727892b1973df62.tar.gz
scummvm-rg350-830c7b578caaec95594e190d6727892b1973df62.tar.bz2
scummvm-rg350-830c7b578caaec95594e190d6727892b1973df62.zip
TESTBED: Add Webserver test suite
Two tests now: IP resolving and index page check.
Diffstat (limited to 'engines/testbed/webserver.cpp')
-rw-r--r--engines/testbed/webserver.cpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/engines/testbed/webserver.cpp b/engines/testbed/webserver.cpp
new file mode 100644
index 0000000000..f17b5a6f8c
--- /dev/null
+++ b/engines/testbed/webserver.cpp
@@ -0,0 +1,102 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+*/
+
+#include "testbed/webserver.h"
+#include "backends/networking/sdl_net/localwebserver.h"
+#include "common/config-manager.h"
+#include <backends/networking/browser/openurl.h>
+
+namespace Testbed {
+
+WebserverTestSuite::WebserverTestSuite() {
+ addTest("ResolveIP", &WebserverTests::testIP, true);
+ addTest("IndexPage", &WebserverTests::testIndexPage, true);
+}
+
+///// TESTS GO HERE /////
+
+/** This test calls Storage::info(). */
+
+bool WebserverTests::startServer() {
+ Common::Point pt;
+ pt.x = 10; pt.y = 10;
+ Testsuite::writeOnScreen("Starting webserver...", pt);
+ LocalServer.start();
+ g_system->delayMillis(500);
+ Testsuite::clearScreen();
+ return LocalServer.isRunning();
+}
+
+TestExitStatus WebserverTests::testIP() {
+ if (!startServer()) {
+ Testsuite::logPrintf("Error! Can't start local webserver!\n");
+ return kTestFailed;
+ }
+
+ Common::String info = "Welcome to the Webserver test suite!\n"
+ "You would be visiting different server's pages and saying whether they work like they should.\n\n"
+ "Testing Webserver's IP resolving.\n"
+ "In this test we'll try to resolve server's IP.";
+
+ if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
+ Testsuite::logPrintf("Info! Skipping test : IP resolving\n");
+ return kTestSkipped;
+ }
+
+ if (Testsuite::handleInteractiveInput(
+ Common::String::format("Is this your machine's IP?\n%s", LocalServer.getAddress().c_str()),
+ "Yes", "No", kOptionRight)) {
+ Testsuite::logDetailedPrintf("Error! IP was not resolved!\n");
+ return kTestFailed;
+ }
+
+ Testsuite::logDetailedPrintf("IP was resolved\n");
+ return kTestPassed;
+}
+
+TestExitStatus WebserverTests::testIndexPage() {
+ if (!startServer()) {
+ Testsuite::logPrintf("Error! Can't start local webserver!\n");
+ return kTestFailed;
+ }
+
+ Common::String info = "Testing Webserver's index page.\n"
+ "In this test we'll try to open server's index page.";
+
+ if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
+ Testsuite::logPrintf("Info! Skipping test : index page\n");
+ return kTestSkipped;
+ }
+
+ Networking::Browser::openUrl(LocalServer.getAddress());
+ if (Testsuite::handleInteractiveInput(
+ Common::String::format("The %s page opens well?", LocalServer.getAddress().c_str()),
+ "Yes", "No", kOptionRight)) {
+ Testsuite::logDetailedPrintf("Error! Couldn't open server's index page!\n");
+ return kTestFailed;
+ }
+
+ Testsuite::logDetailedPrintf("Server's index page is OK\n");
+ return kTestPassed;
+}
+
+} // End of namespace Testbed