tests: Create a core/ directory

I move all of the core tests into the core/ directory to keep them
together.  Gui unit tests will be put in new directories.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-06-14 10:50:18 -04:00
parent 40a99f7eda
commit c88746d2da
19 changed files with 118 additions and 89 deletions

2
.gitignore vendored
View File

@ -7,7 +7,7 @@ bin/
.sconsign.dblite
*.patch
*.tar.gz
tests/*-core
tests/*/*-core
tests/*-lib
*.gcov
*.gcda

View File

@ -2,99 +2,86 @@
import sys, os
Import("test_env")
tests = [
###
#
# (source.cpp, use collected lib_files?, [ other files ], [ other packages ])
#
test_env.UsePackage("glib-2.0")
test_env.DEBUG = True
("version.cpp", False, [], [ "glib-2.0" ]),
("file.cpp", True, [], []),
("database.cpp", True, [], []),
("index.cpp", True, [], []),
("filter.cpp", True, [], []),
("idle.cpp", False, [ "idle.cpp" ], []),
("tags.cpp", True, [], [ "taglib" ]),
("random.cpp", False, [ "random.cpp" ], []),
("queue.cpp", True, [ "callback.cpp", "random.cpp" ], []),
("library.cpp", True, [ "idle.cpp" ], []),
("playlist.cpp", True, [], []),
("deck.cpp", True, [], []),
("driver.cpp", False, [ "driver.cpp" ], []),
("audio.cpp", True, [ "driver.cpp" ], []),
]
env = test_env
env.UsePackage("glib-2.0")
if env.Coverage == True:
env.Append( CCFLAGS = [ "--coverage" ] )
env.Append( LINKFLAGS = [ "-lgcov", "-coverage" ] )
if test_env.Coverage == True:
test_env.Append( CCFLAGS = [ "--coverage" ] )
test_env.Append( LINKFLAGS = [ "-lgcov", "-coverage" ] )
check_depends = True
for arg in sys.argv:
if arg.find("tests") == 0 and len(arg) > 5:
if arg.find("tests/core") == 0 and len(arg) > 11:
check_depends = False
break
def expand_files(extra_files):
res = []
for f in extra_files:
res += [ env.Object("%s-core" % f, "../core/%s" % f) ]
return res
def make_program(src, name, extra_files):
return env.Program("%s" % name, [ src ] + expand_files(extra_files))
valgrind = "valgrind -q --leak-check=full --error-exitcode=42"
gcov = "gcov -r tests/%s/*.gcda"
def make_test(src, name):
cmd = "./tests/%s | tee ./tests/%s.out" % (name, name)
if env.Valgrind == True:
cmd = "valgrind -q --leak-check=full --error-exitcode=42 %s" % cmd
test = Command("%s.out" % name, [], "set -o pipefail; %s" % cmd)
Alias("tests/%s" % name, test)
AlwaysBuild(test)
return test
class OTest:
Prev = None
Env = test_env
def prepare_test(name, src, extra_files):
exe = make_program(src, name, extra_files)
test = make_test(src, name)
Depends(test, exe)
return test
def __init__(self, src, pkg = None):
self.Name = src.rsplit(".")[0]
self.Src = src
if pkg != None:
test_env.UsePackage(pkg)
res = []
lib_files = []
def get_program(self):
return test_env.Program(self.Name, self.Src)
ignore = open(".gitignore", 'w')
for src, lib, extra, pkgs in tests:
name = "%s" % src.rsplit(".")[0]
def prepare(self, subdir):
prog = self.get_program()
if lib == True:
lib_files += [ src ] + extra
extra = lib_files
path = "./tests/%s/%s" % (subdir, self.Name)
cmd = "%s | tee %s.out" % (path, path)
if test_env.Valgrind == True:
cmd = "%s %s" % (valgrind, cmd)
test = Command("%s.out" % self.Name, [], "set -x pipefail; %s" % cmd)
for p in pkgs:
env.UsePackage(p)
Depends(test, prog)
if (check_depends == True) and (OTest.Prev != None):
Depends(test, OTest.Prev)
Alias("tests/%s" % subdir, test)
Alias("tests/%s/%s" % (subdir, self.Name), test)
AlwaysBuild(test)
OTest.Prev = test
return test
test = prepare_test(name, src, extra)
if (check_depends == True) and (len(res) > 0):
Depends(test, res[len(res) - 1])
res += [ test ]
ignore.write(name + "\n")
ignore.close();
class TestList:
def __init__(self, subdir, tests):
self.subdir = subdir
self.tests = tests
if env.Coverage == True:
cov = Command("ocarina.gcov", [], "gcov -r tests/*.gcda")
Depends(cov, res[len(res) - 1])
res += [ cov ]
f = open(".gitignore", "w")
for t in tests:
f.write(t.Name + "\n")
f.close()
if env.CppCheck == True:
check = Command("cpp.check", [], "cppcheck -q .")
Depends(check, res[len(res) - 1])
res += [ check ]
def prepare(self):
res = []
for t in self.tests:
res += [ t.prepare(self.subdir) ]
if test_env.Coverage == True:
res += [ Command("%s.gcov" % self.subdir, [], gcov % self.subdir) ]
Depends(res[len(res) - 1], res[len(res) - 2])
AlwaysBuild(res[len(res) - 1])
return res
Export("OTest", "TestList")
core = SConscript("core/Sconscript")
res = [ core ]
if test_env.CppCheck == True:
res += [ Command("cpp.check", [], "cppcheck -q --error-exitcode=42 .") ]
Depends(res[len(res) - 1], res[len(res) - 2])
Return("res")
##scripts = [ "library", "deck", "audio", "gui" ]

42
tests/core/Sconscript Normal file
View File

@ -0,0 +1,42 @@
#!/usr/bin/python
Import("OTest", "TestList")
class CoreTest(OTest):
Objs = []
def __init__(self, src, pkg = None, extra = None):
OTest.__init__(self, src, pkg)
if extra != None:
self.add_object(extra)
def add_object(self, obj):
path = "../../core/%s" % obj
CoreTest.Objs += [ OTest.Env.Object("%s-core" % obj, path) ]
def get_program(self):
self.add_object(self.Src)
return OTest.Env.Program(self.Name, [ self.Src ] + CoreTest.Objs)
res = TestList("core", [
OTest ("version.cpp"),
CoreTest("file.cpp"),
CoreTest("database.cpp"),
CoreTest("index.cpp"),
CoreTest("filter.cpp"),
CoreTest("idle.cpp"),
CoreTest("tags.cpp", "taglib"),
CoreTest("random.cpp"),
CoreTest("queue.cpp", extra = "callback.cpp"),
CoreTest("library.cpp"),
CoreTest("playlist.cpp"),
CoreTest("deck.cpp"),
CoreTest("driver.cpp"),
CoreTest("audio.cpp"),
]).prepare()
Return("res")

View File

@ -4,7 +4,7 @@
#include <core/audio.h>
#include <core/driver.h>
#include <core/library.h>
#include "test.h"
#include <tests/test.h>
Track *TRACK_NULL = NULL;

View File

@ -4,7 +4,7 @@
*/
#include <core/database.h>
#include "test.h"
#include <tests/test.h>
#include <sstream>

View File

@ -4,7 +4,7 @@
#include <core/callback.h>
#include <core/deck.h>
#include <core/library.h>
#include "test.h"
#include <tests/test.h>
static Queue *Q_NULL = NULL;
static Track *TRACK_NULL = NULL;

View File

@ -2,7 +2,7 @@
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/driver.h>
#include "test.h"
#include <tests/test.h>
static TestDriver *DRIVER_NULL = NULL;
static unsigned int eos_count = 0;

View File

@ -2,7 +2,7 @@
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/file.h>
#include "test.h"
#include <tests/test.h>
static void test_filepath()

View File

@ -4,7 +4,7 @@
*/
#include <core/filter.h>
#include "test.h"
#include <tests/test.h>
static void do_test_lowercase(const std::string &text, const std::string &lc)
{

View File

@ -4,7 +4,7 @@
*/
#include <core/idle.h>
#include "test.h"
#include <tests/test.h>
#include <sstream>

View File

@ -4,7 +4,7 @@
*/
#include <core/index.h>
#include "test.h"
#include <tests/test.h>
#include <sstream>

View File

@ -3,7 +3,7 @@
*/
#include <core/idle.h>
#include <core/library.h>
#include "test.h"
#include <tests/test.h>
static Queue *Q_NULL = NULL;
static Library *LIB_NULL = NULL;

View File

@ -3,7 +3,7 @@
*/
#include <core/library.h>
#include <core/playlist.h>
#include "test.h"
#include <tests/test.h>
static IndexEntry *IDX_NULL = NULL;
static Queue *Q_NULL = NULL;

View File

@ -5,7 +5,7 @@
#include <core/queue.h>
#include <core/random.h>
#include <core/tags.h>
#include "test.h"
#include <tests/test.h>
unsigned int count_add = 0;

View File

@ -3,7 +3,7 @@
*/
#include <core/random.h>
#include "test.h"
#include <tests/test.h>
#include <sstream>

View File

@ -4,7 +4,7 @@
*/
#include <core/tags.h>
#include "test.h"
#include <tests/test.h>
static Library *LIB_NULL = NULL;
static Track *TRACK_NULL = NULL;

View File

@ -2,7 +2,7 @@
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/version.h>
#include "test.h"
#include <tests/test.h>
#ifdef CONFIG_DEBUG
const std::string expected = "6.1-debug";