Artist: Move artist tag code into a new directory

core/tags.cpp was WAY too big, so I moved this code into a new file in
its own directory.  I also created a new unit test just for testing the
Artist tag.

This patch disables the "tags" test since it conflicts with the
tests/core/tags/ directory.  This is okay because the tagdb is gradually
being phased out!

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-08 13:43:23 -05:00
parent aa758481eb
commit b3d904c128
10 changed files with 84 additions and 38 deletions

View File

@ -4,5 +4,5 @@ Import("env")
env.UsePackage("gstreamer-1.0")
env.UsePackage("taglib")
res = Glob("*.cpp")
res = Glob("*.cpp") + SConscript("tags/Sconscript")
Return("res")

View File

@ -18,37 +18,6 @@ Database<Library> library_db("library.db", true);
Database<Track> track_db("track.db", false);
/**
*
* Artist tag
*
*/
Artist :: Artist() {}
Artist :: Artist(const std::string &s)
: name(s), lower(filter :: lowercase(name))
{
}
const std::string Artist :: primary_key() const
{
return name;
}
void Artist :: read(File &f)
{
name = f.getline();
lower = filter :: lowercase(name);
}
void Artist :: write(File &f)
{
f << name;
}
/**
*
* Album tag

3
core/tags/Sconscript Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/python
res = Glob("*.cpp")
Return("res")

29
core/tags/artist.cpp Normal file
View File

@ -0,0 +1,29 @@
/**
* @file
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/filter.h>
#include <core/tags/artist.h>
Artist :: Artist() {}
Artist :: Artist(const std::string &s)
: name(s), lower(filter :: lowercase(name))
{
}
const std::string Artist :: primary_key() const
{
return name;
}
void Artist :: read(File &f)
{
name = f.getline();
lower = filter :: lowercase(name);
}
void Artist :: write(File &f)
{
f << name;
}

View File

@ -12,10 +12,8 @@
*/
class Artist : public DatabaseEntry {
public:
/** Artist name */
std::string name;
/** Artist name (lowercase) */
std::string lower;
std::string name; /**< Artist name. */
std::string lower; /**< Artist name (lowercase). */
/** Artist tag constructor */
Artist();

View File

@ -4,7 +4,6 @@ database
index
filter
idle
tags
random
queue
library

View File

@ -14,8 +14,11 @@ test( "index" )
test( "filter" )
test( "idle" )
test( "tags/artist" )
test_env.UsePackage("taglib")
test( "tags" )
objs += [ get_test_obj("tags", "core") ]
#test( "tags" )
test( "random" )
objs += [ get_test_obj("callback", "core") ]

1
tests/core/tags/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
artist

View File

@ -0,0 +1,41 @@
/**
* @file
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/file.h>
#include <core/tags/artist.h>
#include <tests/test.h>
static void test_artist_tag()
{
Artist artist;
File f("artist_tag", 0);
test_equal(artist.name, (std::string)"");
test_equal(artist.lower, (std::string)"");
test_equal(artist.primary_key(), (std::string)"");
artist = Artist("Koji Kondo");
test_equal(artist.name, (std::string)"Koji Kondo");
test_equal(artist.lower, (std::string)"koji kondo");
test_equal(artist.primary_key(), (std::string)"Koji Kondo");
f.open(OPEN_WRITE);
artist.write(f);
f.close();
artist = Artist();
f.open(OPEN_READ);
artist.read(f);
f.close();
test_equal(artist.name, (std::string)"Koji Kondo");
test_equal(artist.lower, (std::string)"koji kondo");
test_equal(artist.primary_key(), (std::string)"Koji Kondo");
}
int main(int argc, char **argv)
{
run_test("Artist Tag Test", test_artist_tag);
return 0;
}

View File

@ -8,6 +8,9 @@ core = []
for f in Glob("../../core/*.cpp"):
f = str(f)
core += [ test_env.Object("%s-core" % os.path.basename(f), f) ]
for f in Glob("../../core/tags/*.cpp"):
f = str(f)
core += [ test_env.Object("tags/%s-core" % os.path.basename(f), f) ]
def test(name):
global core, objs