spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 8c68b3f53dcb2dc04089817ff530f9ecd3142f2b
parent 3936fe780b2f2805866fee6b23354f0ffa06b722
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Tue, 19 Feb 2013 21:58:08 -0800

Tidy tests

Diffstat:
Mconfigure.ac | 4++--
Mtests/Makefile.am | 9++++++---
Mtests/test-utils.cc | 40++++++++++++++++++++--------------------
Mtests/test.cc | 12+++++++-----
Mtests/test.h | 7++++++-
5 files changed, 41 insertions(+), 31 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -5,8 +5,8 @@ AM_INIT_AUTOMAKE([1.11.1 foreign no-dist-gzip dist-xz]) AM_SILENT_RULES([yes]) AC_LANG([C++]) -AC_PROG_CXX([g++47 g++]) -CXXFLAGS="$CXXFLAGS -std=gnu++0x -Wall -Wextra" +AC_PROG_CXX +CXXFLAGS="$CXXFLAGS -std=c++11 -Wall -Wextra" AC_PROG_CXXCPP AC_PROG_RANLIB AC_PROG_INSTALL diff --git a/tests/Makefile.am b/tests/Makefile.am @@ -10,14 +10,17 @@ test_SOURCES = \ AM_CPPFLAGS = \ -include config.h \ -I$(top_srcdir)/src \ - -pthread + -pthread \ + $(WX_CPPFLAGS) AM_CXXFLAGS = \ - $(FFMPEG_CFLAGS) + $(FFMPEG_CFLAGS) \ + $(WX_CXXFLAGS_ONLY) LDADD = \ ../src/libspek.a \ - $(FFMPEG_LIBS) + $(FFMPEG_LIBS) \ + $(WX_LIBS) AM_LDFLAGS = \ -pthread diff --git a/tests/test-utils.cc b/tests/test-utils.cc @@ -20,28 +20,28 @@ #include "test.h" -void test_utils() +static void test_vercmp() { - test_vercmp(); + test<int>("1.2.3 == 1.2.3", 0, spek_vercmp("1.2.3", "1.2.3")); + test("1.2.3 > 1.2.2", 1, spek_vercmp("1.2.3", "1.2.2")); + test("1.2.2 < 1.2.3", -1, spek_vercmp("1.2.2", "1.2.3")); + test("1.2.3 > 1", 1, spek_vercmp("1.2.3", "1")); + test("1.2.3 > 1.", 1, spek_vercmp("1.2.3", "1.")); + test("1.2.3 > 1.2", 1, spek_vercmp("1.2.3", "1.2")); + test("1.2.3 > 1.2.", 1, spek_vercmp("1.2.3", "1.2.")); + test("1.15.3 > 1.2", 1, spek_vercmp("1.15.3", "1.2")); + test("2 > 1.2.2", 1, spek_vercmp("2", "1.2.2")); + test("1.2.3 > ''", 1, spek_vercmp("1.2.3", "")); + test("'' == ''", 0, spek_vercmp("", "")); + test("123 == 123", 0, spek_vercmp("123", "123")); + test("0.2.3 < 1", -1, spek_vercmp("0.2.3", "1")); + test("0.9.8 < 0.10.1", -1, spek_vercmp("0.9.8", "0.10.1")); + test("1.200 < 2.20", -1, spek_vercmp("1.200", "2.20")); + test("1.0.0 < 2.0.0", -1, spek_vercmp("1.0.0", "2.0.0")); + test("1.0.0 < 1.0.1", -1, spek_vercmp("1.0.0", "1.0.1")); } -static void test_vercmp() +void test_utils() { - test(0 == spek_vercmp("1.2.3", "1.2.3"), "1.2.3 == 1.2.3"); - test(1 == spek_vercmp("1.2.3", "1.2.2"), "1.2.3 > 1.2.2"); - test(-1 == spek_vercmp("1.2.2", "1.2.3"), "1.2.2 < 1.2.3"); - test(1 == spek_vercmp("1.2.3", "1"), "1.2.3 > 1"); - test(1 == spek_vercmp("1.2.3", "1."), "1.2.3 > 1."); - test(1 == spek_vercmp("1.2.3", "1.2"), "1.2.3 > 1.2"); - test(1 == spek_vercmp("1.2.3", "1.2."), "1.2.3 > 1.2."); - test(1 == spek_vercmp("1.15.3", "1.2"), "1.15.3 > 1.2"); - test(1 == spek_vercmp("2", "1.2.2"), "2 > 1.2.2"); - test(1 == spek_vercmp("1.2.3", ""), "1.2.3 > ''"); - test(0 == spek_vercmp("", ""), "'' == ''"); - test(0 == spek_vercmp("123", "123"), "123 == 123"); - test(-1 == spek_vercmp("0.2.3", "1"), "0.2.3 < 1"); - test(-1 == spek_vercmp("0.9.8", "0.10.1"), "0.9.8 < 0.10.1"); - test(-1 == spek_vercmp("1.200", "2.20"), "1.200 < 2.20"); - test(-1 == spek_vercmp("1.0.0", "2.0.0"), "1.0.0 < 2.0.0"); - test(-1 == spek_vercmp("1.0.0", "1.0.1"), "1.0.0 < 1.0.1"); + test_vercmp(); } diff --git a/tests/test.cc b/tests/test.cc @@ -27,7 +27,9 @@ int main() { test_utils(); - std::cerr << g_passes << " / " << g_total << " test passed" << std::endl; + std::cerr << "-------------" << std::endl; + std::cerr << g_passes << "/" << g_total << " tests passed" << std::endl; + std::cerr << "-------------" << std::endl; if (g_passes < g_total) { return -1; } else { @@ -35,12 +37,12 @@ int main() } } -void test(bool condition, const std::string& message) +void test(const std::string& message, bool condition) { g_total++; - if (!condition) { - std::cerr << "FAIL: " << message << std::endl; - } else { + if (condition) { g_passes++; + } else { + std::cerr << "FAIL: " << message << std::endl; } } diff --git a/tests/test.h b/tests/test.h @@ -21,7 +21,12 @@ #include <string> -void test(bool condition, const std::string& message); +void test(const std::string& message, bool condition); + +template<class T> void test(const std::string& message, const T& expected, const T& actual) +{ + test(message, expected == actual); +} void test_utils();