Tidy tests

This commit is contained in:
Alexander Kojevnikov 2013-02-19 21:58:08 -08:00
parent 3936fe780b
commit 8c68b3f53d
5 changed files with 42 additions and 32 deletions

View File

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

View File

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

View File

@ -20,28 +20,28 @@
#include "test.h"
static void 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"));
}
void test_utils()
{
test_vercmp();
}
static void test_vercmp()
{
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");
}

View File

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

View File

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