diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | Makefile.am | 78 | ||||
-rw-r--r-- | plugin/icedteanp/IcedTeaPluginUtils.h | 3 | ||||
-rw-r--r-- | plugin/icedteanp/IcedTeaRunnable.h | 3 | ||||
-rw-r--r-- | tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc | 48 | ||||
-rw-r--r-- | tests/cpp-unit-tests/main.cc | 105 |
6 files changed, 247 insertions, 3 deletions
@@ -1,5 +1,18 @@ 2012-11-21 Adam Domurad <[email protected]> + Support for C++ unit testing with UnitTest++ for IcedTeaWeb. + * tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc: New, contains tests + for utility functions. + * tests/cpp-unit-tests/main.cc: New, contains unit test runner. + * plugin/icedteanp/IcedTeaPluginUtils.h: Remove incorrect circular + include dependency + * plugin/icedteanp/IcedTeaRunnable.h: Add includes necessary for + self-sustaining header. + * Makefile.am: Add targets for unit test compilation and running, + eg 'make run-cpp-unit-tests'. + +2012-11-21 Adam Domurad <[email protected]> + Add the source code to UnitTest++ into the project. * tests/UnitTest++/COPYING: Part of UnitTest++ * tests/UnitTest++/Makefile: Part of UnitTest++ diff --git a/Makefile.am b/Makefile.am index 08b8c8b..0a301f3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,6 +25,9 @@ export TEST_EXTENSIONS_SRCDIR=$(TESTS_SRCDIR)/test-extensions export TEST_EXTENSIONS_TESTS_SRCDIR=$(TESTS_SRCDIR)/test-extensions-tests export REPRODUCERS_TESTS_SRCDIR=$(TESTS_SRCDIR)/reproducers export TEST_EXTENSIONS_DIR=$(TESTS_DIR)/test-extensions +export CPP_UNITTEST_FRAMEWORK_SRCDIR=$(TESTS_SRCDIR)/UnitTest++ +export CPP_UNITTEST_SRCDIR=$(TESTS_SRCDIR)/cpp-unit-tests +export CPP_UNITTEST_DIR=$(TESTS_DIR)/cpp-unit-tests export TEST_EXTENSIONS_COMPATIBILITY_SYMLINK=$(TESTS_DIR)/netx/jnlp_testsengine export TEST_EXTENSIONS_TESTS_DIR=$(TESTS_DIR)/test-extensions-tests export REPRODUCERS_TESTS_SERVER_DEPLOYDIR=$(TESTS_DIR)/reproducers_test_server_deploydir @@ -61,6 +64,10 @@ export MOZILLA_GLOBAL32_PLUGINDIR=/usr/lib/mozilla/plugins export OPERA_GLOBAL64_PLUGINDIR=/usr/lib64/opera/plugins export OPERA_GLOBAL32_PLUGINDIR=/usr/lib/opera/plugins export BUILT_PLUGIN_LIBRARY=IcedTeaPlugin.so +export CPP_UNITTEST_FRAMEWORK_BUILDDIR=$(CPP_UNITTEST_DIR)/UnitTest++ +export CPP_UNITTEST_FRAMEWORK_LIB_NAME=libUnitTest++.a +export CPP_UNITTEST_FRAMEWORK_LIB=$(CPP_UNITTEST_FRAMEWORK_BUILDDIR)/$(CPP_UNITTEST_FRAMEWORK_LIB_NAME) +export CPP_UNITTEST_EXECUTABLE=$(CPP_UNITTEST_DIR)/IcedTeaPluginUnitTests export MOZILLA_LOCAL_BACKUP_FILE=${HOME}/$(PLUGIN_LINK_NAME).origU export MOZILLA_GLOBAL_BACKUP_FILE=${HOME}/$(PLUGIN_LINK_NAME).origMG export OPERA_GLOBAL_BACKUP_FILE=${HOME}/$(PLUGIN_LINK_NAME).origOG @@ -288,6 +295,75 @@ $(PLUGIN_DIR)/$(BUILT_PLUGIN_LIBRARY): $(addprefix $(PLUGIN_DIR)/,$(PLUGIN_OBJEC $(MOZILLA_LIBS) \ -shared -o $@ +# Start of CPP Unit test targets + +# Note that UnitTest++ has its own makefile, however this is avoided because it creates an in-source build. +$(CPP_UNITTEST_FRAMEWORK_LIB): $(CPP_UNITTEST_FRAMEWORK_SRCDIR) + mkdir -p $(CPP_UNITTEST_FRAMEWORK_BUILDDIR) && \ + pushd $(CPP_UNITTEST_FRAMEWORK_SRCDIR) && \ + for cppfile in $$(find $(CPP_UNITTEST_FRAMEWORK_SRCDIR) -name '*.cpp') ; \ + do \ + objfile="$(CPP_UNITTEST_FRAMEWORK_BUILDDIR)/$$(basename $${cppfile%.cpp}).o" ; \ + $(CXX) $(CXXFLAGS) -c $$cppfile -o $$objfile || exit 1 ; \ + done ; \ + ar cr $(CPP_UNITTEST_FRAMEWORK_LIB) $(CPP_UNITTEST_FRAMEWORK_BUILDDIR)/*.o ; \ + popd + +clean-unittest++: + rm $(CPP_UNITTEST_FRAMEWORK_BUILDDIR)/*.o + rm $(CPP_UNITTEST_FRAMEWORK_LIB) + rmdir $(CPP_UNITTEST_FRAMEWORK_BUILDDIR) + rmdir $(CPP_UNITTEST_DIR) &> /dev/null + +stamps/cpp-unit-tests-compile.stamp: $(CPP_UNITTEST_FRAMEWORK_LIB) $(CPP_UNITTEST_SRCDIR) $(addprefix $(PLUGIN_DIR)/,$(PLUGIN_OBJECTS)) + mkdir -p $(CPP_UNITTEST_DIR) && \ + pushd $(CPP_UNITTEST_SRCDIR) && \ + for cppfile in $$(find $(CPP_UNITTEST_SRCDIR) -name '*.cc') ; \ + do \ + objfile="$(CPP_UNITTEST_DIR)/$$(basename $${cppfile%.cc}).o" ; \ + echo "Compiling $$cppfile to $$objfile"; \ + $(CXX) $(CXXFLAGS) \ + $(DEFS) $(VERSION_DEFS) \ + -DJDK_UPDATE_VERSION="\"$(JDK_UPDATE_VERSION)\"" \ + -DPLUGIN_NAME="\"IcedTea-Web Plugin\"" \ + -DPLUGIN_VERSION="\"$(PLUGIN_VERSION)\"" \ + -DPACKAGE_URL="\"$(PACKAGE_URL)\"" \ + -DMOZILLA_VERSION_COLLAPSED="$(MOZILLA_VERSION_COLLAPSED)" \ + -DICEDTEA_WEB_JRE="\"$(SYSTEM_JRE_DIR)\"" \ + -DPLUGIN_BOOTCLASSPATH=$(PLUGIN_BOOTCLASSPATH) \ + $(GLIB_CFLAGS) \ + $(GTK_CFLAGS) \ + $(MOZILLA_CFLAGS) \ + "-I$(CPP_UNITTEST_FRAMEWORK_SRCDIR)/src" \ + "-I$(PLUGIN_SRCDIR)" \ + -o $$objfile -c $$cppfile || exit 1 ; \ + done ; \ + popd ; \ + mkdir -p stamps ; \ + touch $@ + +$(CPP_UNITTEST_EXECUTABLE): $(CPP_UNITTEST_FRAMEWORK_LIB) stamps/cpp-unit-tests-compile.stamp + cd $(CPP_UNITTEST_DIR) && \ + $(CXX) $(CXXFLAGS) \ + $(addprefix $(PLUGIN_DIR)/,$(PLUGIN_OBJECTS)) \ + $(CPP_UNITTEST_DIR)/*.o \ + $(GLIB_LIBS) \ + $(GTK_LIBS) \ + $(MOZILLA_LIBS) \ + $(CPP_UNITTEST_FRAMEWORK_LIB)\ + $(BUILT_CPP_UNIT_TEST_FRAMEWORK) -o $@ + +clean-cpp-unit-tests: + rm stamps/cpp-unit-tests-compile.stamp &> /dev/null + rm $(CPP_UNITTEST_EXECUTABLE) + rm $(CPP_UNITTEST_DIR)/*.o + rmdir $(CPP_UNITTEST_DIR) &> /dev/null + +run-cpp-unit-tests: $(CPP_UNITTEST_EXECUTABLE) + $(CPP_UNITTEST_EXECUTABLE) + +# End of CPP Unit test targets + clean-IcedTeaPlugin: rm -f $(PLUGIN_DIR)/*.o rm -f $(PLUGIN_DIR)/$(BUILT_PLUGIN_LIBRARY) @@ -494,7 +570,7 @@ clean-plugin-docs: # check # ========================== -clean-tests: clean-netx-tests +clean-tests: clean-netx-tests clean-cpp-unit-tests clean-unittest++ if [ -e $(TESTS_DIR) ]; then \ rmdir $(TESTS_DIR) ; \ fi diff --git a/plugin/icedteanp/IcedTeaPluginUtils.h b/plugin/icedteanp/IcedTeaPluginUtils.h index 48250d1..ddcf12e 100644 --- a/plugin/icedteanp/IcedTeaPluginUtils.h +++ b/plugin/icedteanp/IcedTeaPluginUtils.h @@ -56,6 +56,7 @@ exception statement from your version. */ #include <vector> #include <npapi.h> +#include <glib.h> #if MOZILLA_VERSION_COLLAPSED < 1090100 #include <npupp.h> @@ -64,8 +65,6 @@ exception statement from your version. */ #include <npruntime.h> #endif -#include "IcedTeaNPPlugin.h" - #define PLUGIN_DEBUG(...) \ do \ { \ diff --git a/plugin/icedteanp/IcedTeaRunnable.h b/plugin/icedteanp/IcedTeaRunnable.h index d6e7a82..7134ab5 100644 --- a/plugin/icedteanp/IcedTeaRunnable.h +++ b/plugin/icedteanp/IcedTeaRunnable.h @@ -42,6 +42,9 @@ exception statement from your version. */ #define MOZILLA 1 #if MOZILLA +#include <string> +#include <npapi.h> + #if MOZILLA_VERSION_COLLAPSED < 1090100 #include <nsIRunnable.h> #include <string> diff --git a/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc b/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc new file mode 100644 index 0000000..854aeaa --- /dev/null +++ b/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc @@ -0,0 +1,48 @@ +/* Copyright (C) 2012 Red Hat + + This file is part of IcedTea. + + IcedTea 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, or (at your option) + any later version. + + IcedTea 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 IcedTea; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +#include <UnitTest++.h> + +#include <npapi.h> +#include "IcedTeaPluginUtils.h" + +TEST(NPVariantAsString) { + NPVariant var; + STRINGZ_TO_NPVARIANT("test", var); + + std::string cppstr = IcedTeaPluginUtilities::NPVariantAsString(var); + CHECK(cppstr == "test"); +} diff --git a/tests/cpp-unit-tests/main.cc b/tests/cpp-unit-tests/main.cc new file mode 100644 index 0000000..d1b6c65 --- /dev/null +++ b/tests/cpp-unit-tests/main.cc @@ -0,0 +1,105 @@ +/* Copyright (C) 2012 Red Hat + + This file is part of IcedTea. + + IcedTea 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, or (at your option) + any later version. + + IcedTea 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 IcedTea; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +// The test runner. +// Note that all modules compiled with the TEST macro will append tests to +// a global test list, that is accessible via Test::GetTestList(). +#include <cstdio> + +#include <UnitTest++.h> +#include <TestReporter.h> + +using namespace UnitTest; + +class IcedteaWebUnitTestReporter: public TestReporter { +public: + + IcedteaWebUnitTestReporter() { + // Unfortunately, there is no 'ReportSuccess' + // We use 'did_finish_correctly' to track successes + did_finish_correctly = false; + } + + virtual void ReportTestStart(const TestDetails& test) { + did_finish_correctly = true; + } + + virtual void ReportFailure(const TestDetails& details, + char const* failure) { + + printf("FAILED: %s line %d (%s)\n", details.testName, + details.lineNumber, failure); + + did_finish_correctly = false; + } + + virtual void ReportTestFinish(const TestDetails& details, + float secondsElapsed) { + + if (did_finish_correctly) { + printf("Passed: %s\n", details.testName); + } + } + + virtual void ReportSummary(int totalTestCount, int failedTestCount, + int failureCount, float secondsElapsed) { + + if (failedTestCount > 0) { + printf("TEST SUITE FAILURE: Not all tests have passed!\n"); + } + + printf("Total tests run: %d\n", totalTestCount); + printf("Test results: passed: %d; failed: %d\n", + totalTestCount - failedTestCount, failedTestCount); + } + +private: + bool did_finish_correctly; +}; + +static int run_icedtea_web_unit_tests() { + IcedteaWebUnitTestReporter reporter; + TestRunner runner(reporter); + + return runner.RunTestsIf(Test::GetTestList(), NULL /*All suites*/, + True() /*All tests*/, 0 /*No time limit*/); +} + +int main() { + return run_icedtea_web_unit_tests(); +} + + |