tests: Improve removing old test data

I was using my own cpp file to remove old test data to start with a
clean slate.  I've decided it's easier to just remove the files before
running tests if they exist.

I also use this patch to update the test design and add an idea for the
future.

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2013-09-29 20:58:34 -04:00 committed by Anna Schumaker
parent 31ea73b0d9
commit 9880e98d0d
7 changed files with 33 additions and 81 deletions

View File

@ -44,7 +44,6 @@ Files:
playlist.h
prefs.h
print.h
test.h
version.h
ocarina/lib/
audio.cpp
@ -57,7 +56,6 @@ Files:
library.cpp
playlist.cpp
prefs.cpp
test.cpp
@ -82,19 +80,6 @@ API:
Test framework: (lib/test.cpp)
Unit tests will require a basic framework for manipulating files and
directories in the filesystem. Compiling the tests/ directory will
enable the CONFIG_TEST option, which in turn compiles the test library.
API:
void rm_test_config()
Remove the $XDG_CONFG_HOME/ocarina-test/ directory.
void rm_test_data()
Remove the $XDG_DATA_HOME/ocarina-test/ directory.
Versioning: (include/version.h)
This file contains a simple function for returning a string stating
the current version.
@ -251,15 +236,22 @@ Database: (lib/database.cpp)
File << <CHILD_CLASS_DATA>
- Flags:
enum DatabaseFlags {
DB_NORMAL,
DB_UNIQUE,
}
- Database:
template <class T>
class Database {
private:
unsigned int _size; /* Number of valid rows */
File filename;
DatabaseFlags flags;
vector<T> db;
public:
Database::Database(filename);
Database::Database(filename, flags);
void load();
void save();
@ -280,8 +272,9 @@ Database: (lib/database.cpp)
...
- API:
Database : Database(filename);
Database : Database(filename, flags);
Initializes database to use ~/.ocarina{-debug}/filename.
Set up flags.
void Database : load();
Reads data from file.
@ -292,6 +285,8 @@ Database: (lib/database.cpp)
template <class T>
unsigned int Database : insert(T &);
Adds a new item to the db, returns the id of the item.
if DB_UNIQUE is set, check if the item already exists in the
DB and return it's ID instead of adding a new item.
void Database : delete(unsigned int index);
Mark db[index] as invalid (quick deletion).
@ -879,3 +874,7 @@ Future work:
need to manage it externally. This can still be done with a
script, a cron job, and maybe a "mirror this track" option in
the library? Perhaps create a mirror group?
- Extra testing ideas: (6.1)
- Run tests through valgrind to help find memory leaks
- Combine earlier tests into a single file

View File

@ -73,3 +73,7 @@ Future work:
need to manage it externally. This can still be done with a
script, a cron job, and maybe a "mirror this track" option in
the library? Perhaps create a mirror group?
- Extra testing ideas: (6.1)
- Run tests through valgrind to help find memory leaks
- Combine earlier tests into a single file

View File

@ -1,19 +0,0 @@
== Files ==
ocarina/include/
test.h
ocarina/lib/
test.cpp
== Depends ==
install
Test framework: (lib/test.cpp)
Unit tests will require a basic framework for manipulating files and
directories in the filesystem. Compiling the tests/ directory will
enable the CONFIG_TEST option, which in turn compiles the test library.
API:
void rm_test_config()
Remove the $XDG_CONFG_HOME/ocarina-test/ directory.
void rm_test_data()
Remove the $XDG_DATA_HOME/ocarina-test/ directory.

View File

@ -1,12 +0,0 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#ifndef OCARINA_TEST_H
#define OCARINA_TEST_H
#ifdef CONFIG_TEST
void rm_test_config();
void rm_test_data();
#endif /* CONFIG_TEST */
#endif /* OCARINA_TEST_H */

View File

@ -30,9 +30,4 @@ if CONFIG.FILE:
if CONFIG.IDLE:
build += [ env.Object("idle.cpp") ]
####################
if CONFIG.TEST:
build += [ env.Object("test.cpp") ]
Return("build")

View File

@ -1,27 +0,0 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <test.h>
#include <string>
#include <glib.h>
#include <stdlib.h>
/* A bit hackish, but it works... */
static void rm_dir(const char *dir)
{
std::string cmd = "rm -rf ";
cmd += dir;
cmd += "/ocarina-test";
system(cmd.c_str());
}
void rm_test_config()
{
rm_dir(g_get_user_config_dir());
}
void rm_test_data()
{
rm_dir(g_get_user_data_dir());
}

View File

@ -1,5 +1,6 @@
#!/usr/bin/python
import os, subprocess
import os, subprocess, shutil
import xdg.BaseDirectory
Import("env", "CONFIG")
@ -41,8 +42,19 @@ def Test(group, src):
Export("Test")
#
# Clean up leftover test data
#
def rm_test_dir(dir):
dir = os.path.join(dir, "ocarina-test")
if os.path.exists(dir):
shutil.rmtree(dir)
rm_test_dir(xdg.BaseDirectory.xdg_config_home);
rm_test_dir(xdg.BaseDirectory.xdg_data_home);
#
# Read SConscript files
#
scripts = [ "database", "file", "filter", "group", "idle", "index", "print" ]
for s in scripts:
CONFIG.reset()