From 2d13b74c1211a3802f018c2ffd01a1c5aa5ff559 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sun, 22 Dec 2013 17:24:09 -0500 Subject: [PATCH] playlist: Create the initial playlist class Right now it just knows the value of its flags variable. More to come soon! Signed-off-by: Anna Schumaker --- config | 1 + include/playlist.h | 26 ++++++++++++++++++++++++ lib/Sconscript | 1 + lib/playlist.cpp | 29 +++++++++++++++++++++++++++ tests/Sconscript | 3 ++- tests/playlist/Sconscript | 6 ++++++ tests/playlist/playlist.cpp | 39 ++++++++++++++++++++++++++++++++++++ tests/playlist/playlist.good | 6 ++++++ 8 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 include/playlist.h create mode 100644 lib/playlist.cpp create mode 100644 tests/playlist/Sconscript create mode 100644 tests/playlist/playlist.cpp create mode 100644 tests/playlist/playlist.good diff --git a/config b/config index cb6e9362..4def61ee 100644 --- a/config +++ b/config @@ -40,6 +40,7 @@ class Config: self.GROUP = False self.IDLE = False self.LIBRARY = False + self.PLAYLIST = False self.TEST = TEST self.reconfigure() diff --git a/include/playlist.h b/include/playlist.h new file mode 100644 index 00000000..01b43941 --- /dev/null +++ b/include/playlist.h @@ -0,0 +1,26 @@ +/* + * Copyright 2013 (c) Anna Schumaker. + */ +#ifndef OCARINA_PLAYLIST_H +#define OCARINA_PLAYLIST_H + +enum playlist_flags { + PL_ENABLED = (1 << 0), + PL_RANDOM = (1 << 1), + PL_LOCKED = (1 << 2), +}; + +class Playlist { +private: + unsigned int flags; + +public: + Playlist(playlist_flags); + ~Playlist(); + + void set_flag(playlist_flags); + void unset_flag(playlist_flags); + const unsigned int get_flags(); +}; + +#endif /* OCARINA_PLAYLIST_H */ diff --git a/lib/Sconscript b/lib/Sconscript index 6a0d3558..a0002646 100644 --- a/lib/Sconscript +++ b/lib/Sconscript @@ -21,6 +21,7 @@ modules = { "GROUP" : Module("group.cpp", depends = [ "DATABASE" ]), "IDLE" : Module("idle.cpp"), "LIBRARY" : Module("library.cpp", package = "taglib", depends = [ "DATABASE", "IDLE" ]), + "PLAYLIST" : Module("playlist.cpp", depends = [ "FILE" ]), ########################### ########################### diff --git a/lib/playlist.cpp b/lib/playlist.cpp new file mode 100644 index 00000000..cd95763c --- /dev/null +++ b/lib/playlist.cpp @@ -0,0 +1,29 @@ +/* + * Copyright 2013 (c) Anna Schumaker. + */ + +#include + +Playlist :: Playlist(playlist_flags f) + : flags(f) +{ +} + +Playlist :: ~Playlist() +{ +} + +void Playlist :: set_flag(playlist_flags f) +{ + flags |= f; +} + +void Playlist :: unset_flag(playlist_flags f) +{ + flags &= ~f; +} + +const unsigned int Playlist :: get_flags() +{ + return flags; +} diff --git a/tests/Sconscript b/tests/Sconscript index 8a832a80..f3d67d1d 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -57,7 +57,8 @@ rm_test_dir(xdg.BaseDirectory.xdg_data_home); # # Read SConscript files # -scripts = [ "database", "file", "filter", "group", "idle", "index", "library", "print" ] +scripts = [ "database", "file", "filter", "group", "idle", "index", "library", + "playlist", "print" ] for s in scripts: CONFIG.reset(TEST = True) SConscript("%s/Sconscript" % s) diff --git a/tests/playlist/Sconscript b/tests/playlist/Sconscript new file mode 100644 index 00000000..4c0ff2c3 --- /dev/null +++ b/tests/playlist/Sconscript @@ -0,0 +1,6 @@ +#!/usr/bin/python +Import("Test", "CONFIG") + +CONFIG.PLAYLIST = True + +Test("playlist", "playlist.cpp") diff --git a/tests/playlist/playlist.cpp b/tests/playlist/playlist.cpp new file mode 100644 index 00000000..719a6e44 --- /dev/null +++ b/tests/playlist/playlist.cpp @@ -0,0 +1,39 @@ +/* + * Copyright 2013 (c) Anna Schumaker. + */ +#include +#include + +#include + +void test_flags(const std :: string &test, Playlist &plist, unsigned int expected) +{ + print("%s: ", test.c_str()); + if (plist.get_flags() == expected) + print("SUCCESS\n"); + else + print("FAILED\n"); +} + +/* Test flag setting / unsetting / getting */ +void test_0() +{ + Playlist plist(PL_ENABLED); + + test_flags("0a", plist, PL_ENABLED); + plist.set_flag(PL_RANDOM); + test_flags("0b", plist, PL_ENABLED | PL_RANDOM); + plist.set_flag(PL_ENABLED); + test_flags("0c", plist, PL_ENABLED | PL_RANDOM); + plist.unset_flag(PL_ENABLED); + test_flags("0d", plist, PL_RANDOM); + plist.unset_flag(PL_RANDOM); + test_flags("0f", plist, 0); + print("\n"); +} + +int main(int argc, char **argv) +{ + test_0(); + return 0; +} diff --git a/tests/playlist/playlist.good b/tests/playlist/playlist.good new file mode 100644 index 00000000..5fd69478 --- /dev/null +++ b/tests/playlist/playlist.good @@ -0,0 +1,6 @@ +0a: SUCCESS +0b: SUCCESS +0c: SUCCESS +0d: SUCCESS +0f: SUCCESS +