diff --git a/Rakefile b/Rakefile index 60db5c761..26db855ad 100644 --- a/Rakefile +++ b/Rakefile @@ -56,7 +56,7 @@ def setup_globals $manpages = $programs.collect { |name| "doc/man/#{name}.1" } $system_includes = "-I. -Ilib -Ilib/avilib-0.6.10 -Ilib/utf8-cpp/source -Ilib/pugixml/src -Isrc" - $system_libdirs = "-Llib/avilib-0.6.10 -Llib/librmff -Llib/pugixml/src -Lsrc/common -Lsrc/input -Lsrc/output -Lsrc/mpegparser -Lsrc/merge -Lsrc/info -Lsrc/extract -Lsrc/propedit" + $system_libdirs = "-Llib/avilib-0.6.10 -Llib/librmff -Llib/pugixml/src -Lsrc/common" $source_directories = %w{lib/avilib-0.6.10 lib/librmff src src/input src/output src/common src/common/chapters src/common/compression src/common/strings src/common/tags src/common/xml src/mmg src/mmg/header_editor src/mmg/options src/mmg/tabs src/extract src/propedit src/merge src/info src/mpegparser} diff --git a/rake.d/gtest.rb b/rake.d/gtest.rb index 00ffebe37..0a771cd15 100644 --- a/rake.d/gtest.rb +++ b/rake.d/gtest.rb @@ -1,9 +1,6 @@ #!/usr/bin/env ruby -gtest_apps = %w{common} -gtest_libs = { - 'common' => [], -} +gtest_apps = %w{common propedit} namespace :tests do desc "Build and run the unit tests" @@ -19,6 +16,11 @@ $build_system_modules[:gtest] = { end, :define_tasks => lambda do + gtest_libs = { + 'common' => [], + 'propedit' => [ :mtxpropedit ], + } + # # Google Test framework # @@ -27,13 +29,18 @@ $build_system_modules[:gtest] = { sources([ 'lib/gtest/src' ], :type => :dir). create + Library. + new('tests/unit/libmtxunittest'). + sources('tests/unit', :type => :dir). + create + gtest_apps.each do |app| Application. new("tests/unit/#{app}/#{app}"). description("Build the unit tests executable for '#{app}'"). aliases("unit_tests_#{app}"). sources([ "tests/unit/#{app}" ], :type => :dir). - libraries($common_libs, gtest_libs[app], :gtest, :pthread). + libraries(gtest_libs[app], :mtxunittest, $common_libs, :gtest, :pthread). create end end, diff --git a/rake.d/target.rb b/rake.d/target.rb index 343df2bad..1c5a8db4b 100644 --- a/rake.d/target.rb +++ b/rake.d/target.rb @@ -104,6 +104,7 @@ class Target when :mtxinfo then "src/info/libmtxinfo.a" when :mtxextract then "src/extract/libmtxextract.a" when :mtxpropedit then "src/propedit/libmtxpropedit.a" + when :mtxunittest then "tests/unit/libmtxunittest.a" when :avi then "lib/avilib-0.6.10/libavi.a" when :rmff then "lib/librmff/librmff.a" when :pugixml then "lib/pugixml/src/libpugixml.a" @@ -129,6 +130,14 @@ class Target when :boost_system then c(:BOOST_SYSTEM_LIB) when :qt then c(:QT_LIBS) when :wxwidgets then c(:WXWIDGETS_LIBS) + when :mpegparser then [ '-Lsrc/mpegparser', '-lmpegparser' ] + when :mtxinput then [ '-Lsrc/input', '-lmtxinput' ] + when :mtxoutput then [ '-Lsrc/output', '-lmtxoutput' ] + when :mtxmerge then [ '-Lsrc/merge', '-lmtxmerge' ] + when :mtxinfo then [ '-Lsrc/info', '-lmtxinfo' ] + when :mtxextract then [ '-Lsrc/extract', '-lmtxextract' ] + when :mtxpropedit then [ '-Lsrc/propedit', '-lmtxpropedit' ] + when :mtxunittest then [ '-Ltests/unit', '-lmtxunittest' ] when String then entry else "-l#{entry}" end diff --git a/tests/unit/common/common.cpp b/tests/unit/common/common.cpp index cf66419e3..13a126fc6 100644 --- a/tests/unit/common/common.cpp +++ b/tests/unit/common/common.cpp @@ -1,10 +1,11 @@ #include "common/common_pch.h" -#include "gtest/gtest.h" +#include "tests/unit/init.h" int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); + ::mtxut::init_suite(); return RUN_ALL_TESTS(); } diff --git a/tests/unit/init.cpp b/tests/unit/init.cpp new file mode 100644 index 000000000..a1d1b46db --- /dev/null +++ b/tests/unit/init.cpp @@ -0,0 +1,48 @@ +/* + mkvmerge -- utility for splicing together matroska files + from component media subtypes + + Distributed under the GPL + see the file COPYING for details + or visit http://www.gnu.org/copyleft/gpl.html + + helper functions for unit tests + + Written by Moritz Bunkus . +*/ + +#include "common/common_pch.h" + +#include "tests/unit/init.h" + +#include "src/common/unique_numbers.h" + +namespace { + +void +mxmsg_handler(unsigned int level, + std::string const &message) { + if (MXMSG_WARNING == level) + g_warning_issued = true; + + else if (MXMSG_ERROR == level) + throw mtxut::mxerror_x{message}; +} + +} + +void +mtxut::init_suite() { + clear_list_of_unique_numbers(UNIQUE_ALL_IDS); + mtx_common_init("UNITTESTS"); + + set_mxmsg_handler(MXMSG_INFO, mxmsg_handler); + set_mxmsg_handler(MXMSG_WARNING, mxmsg_handler); + set_mxmsg_handler(MXMSG_ERROR, mxmsg_handler); +} + +void +mtxut::init_case() { + clear_list_of_unique_numbers(UNIQUE_ALL_IDS); + g_warning_issued = false; +} diff --git a/tests/unit/init.h b/tests/unit/init.h new file mode 100644 index 000000000..e937edc0f --- /dev/null +++ b/tests/unit/init.h @@ -0,0 +1,52 @@ +/* + mkvmerge -- utility for splicing together matroska files + from component media subtypes + + Distributed under the GPL + see the file COPYING for details + or visit http://www.gnu.org/copyleft/gpl.html + + definitions for helper functions for unit tests + + Written by Moritz Bunkus . +*/ + +#ifndef MTX_TESTS_UNIT_INIT_H +#define MTX_TESTS_UNIT_INIT_H + +#include "common/common_pch.h" + +#include "gtest/gtest.h" + +extern bool g_warning_issued; + +namespace mtxut { + +class mxerror_x: public std::exception { +protected: + std::string m_message; + +public: + mxerror_x(std::string const &message) + : m_message{message} + { + } + + virtual ~mxerror_x() throw() { } + + + virtual const char *what() const throw() { + return m_message.c_str(); + } + + virtual std::string error() const throw() { + return m_message; + } +}; + +void init_suite(); +void init_case(); + +} + +#endif // MTX_TESTS_UNIT_INIT_H diff --git a/tests/unit/propedit/Rakefile b/tests/unit/propedit/Rakefile new file mode 100644 index 000000000..d2942860f --- /dev/null +++ b/tests/unit/propedit/Rakefile @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby + +$build_unit_tests = true + +import ['..', '../..', '../../..'].collect { |subdir| FileList[File.dirname(__FILE__) + "/#{subdir}/build-config.in"].to_a }.flatten.compact.first.gsub(/build-config.in/, 'Rakefile') + +# Local Variables: +# mode: ruby +# End: diff --git a/tests/unit/propedit/chapter_target.cpp b/tests/unit/propedit/chapter_target.cpp new file mode 100644 index 000000000..99bd10f1c --- /dev/null +++ b/tests/unit/propedit/chapter_target.cpp @@ -0,0 +1,16 @@ +#include "common/common_pch.h" + +#include "propedit/chapter_target.h" + +#include "gtest/gtest.h" + +namespace { + +TEST(ChapterTarget, Basics) { + chapter_target_c ct; + + EXPECT_TRUE(ct.has_changes()); +} + + +} diff --git a/tests/unit/propedit/propedit b/tests/unit/propedit/propedit new file mode 100755 index 000000000..a5df3b641 Binary files /dev/null and b/tests/unit/propedit/propedit differ diff --git a/tests/unit/propedit/propedit.cpp b/tests/unit/propedit/propedit.cpp new file mode 100644 index 000000000..13a126fc6 --- /dev/null +++ b/tests/unit/propedit/propedit.cpp @@ -0,0 +1,11 @@ +#include "common/common_pch.h" + +#include "tests/unit/init.h" + +int +main(int argc, + char **argv) { + ::testing::InitGoogleTest(&argc, argv); + ::mtxut::init_suite(); + return RUN_ALL_TESTS(); +}