aboutsummaryrefslogtreecommitdiff
path: root/engines/testbed
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
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')
-rw-r--r--engines/testbed/module.mk5
-rw-r--r--engines/testbed/testbed.cpp8
-rw-r--r--engines/testbed/webserver.cpp102
-rw-r--r--engines/testbed/webserver.h64
4 files changed, 179 insertions, 0 deletions
diff --git a/engines/testbed/module.mk b/engines/testbed/module.mk
index 3a7eb2ebfb..99e6157cde 100644
--- a/engines/testbed/module.mk
+++ b/engines/testbed/module.mk
@@ -19,6 +19,11 @@ MODULE_OBJS += \
cloud.o
endif
+ifdef USE_SDL_NET
+MODULE_OBJS += \
+ webserver.o
+endif
+
MODULE_DIRS += \
engines/testbed
diff --git a/engines/testbed/testbed.cpp b/engines/testbed/testbed.cpp
index a2f9aad16c..5943d47c58 100644
--- a/engines/testbed/testbed.cpp
+++ b/engines/testbed/testbed.cpp
@@ -42,6 +42,9 @@
#ifdef USE_LIBCURL
#include "testbed/cloud.h"
#endif
+#ifdef USE_SDL_NET
+#include "testbed/webserver.h"
+#endif
namespace Testbed {
@@ -142,6 +145,11 @@ TestbedEngine::TestbedEngine(OSystem *syst)
ts = new CloudTestSuite();
_testsuiteList.push_back(ts);
#endif
+#ifdef USE_SDL_NET
+ // Webserver
+ ts = new WebserverTestSuite();
+ _testsuiteList.push_back(ts);
+#endif
}
TestbedEngine::~TestbedEngine() {
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
diff --git a/engines/testbed/webserver.h b/engines/testbed/webserver.h
new file mode 100644
index 0000000000..bdb37400b5
--- /dev/null
+++ b/engines/testbed/webserver.h
@@ -0,0 +1,64 @@
+/* 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.
+ *
+ */
+
+#ifndef TESTBED_WEBSERVER_H
+#define TESTBED_WEBSERVER_H
+
+#include "testbed/testsuite.h"
+
+namespace Testbed {
+
+namespace WebserverTests {
+
+// Helper functions for Webserver tests
+
+bool startServer();
+TestExitStatus testIP();
+TestExitStatus testIndexPage();
+
+} // End of namespace WebserverTests
+
+class WebserverTestSuite : public Testsuite {
+public:
+ /**
+ * The constructor for the WebserverTestSuite
+ * For every test to be executed one must:
+ * 1) Create a function that would invoke the test
+ * 2) Add that test to list by executing addTest()
+ *
+ * @see addTest()
+ */
+ WebserverTestSuite();
+ ~WebserverTestSuite() {}
+ const char *getName() const {
+ return "Webserver";
+ }
+
+ const char *getDescription() const {
+ return "Webserver tests";
+ }
+
+};
+
+} // End of namespace Testbed
+
+#endif // TESTBED_TEMPLATE_H