Common init code for test cases; start of unit tests for propedit

This commit is contained in:
Moritz Bunkus 2012-08-15 09:16:52 +02:00
parent b5e41242b4
commit 1cd37eb212
10 changed files with 160 additions and 7 deletions

View File

@ -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}

View File

@ -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,

View File

@ -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

View File

@ -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();
}

48
tests/unit/init.cpp Normal file
View File

@ -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 <moritz@bunkus.org>.
*/
#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;
}

52
tests/unit/init.h Normal file
View File

@ -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 <moritz@bunkus.org>.
*/
#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

View File

@ -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:

View File

@ -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());
}
}

BIN
tests/unit/propedit/propedit Executable file

Binary file not shown.

View File

@ -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();
}