113 lines
1.7 KiB
C++
113 lines
1.7 KiB
C++
/*
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
*/
|
|
#include <error.h>
|
|
#include <playlist.h>
|
|
#include <print.h>
|
|
|
|
|
|
void list_tracks(const std::string &name)
|
|
{
|
|
std::set<unsigned int> tracks = playlist :: get_tracks(name);
|
|
std::set<unsigned int>::iterator it;
|
|
|
|
print("Playlist \"%s\": ", name.c_str());
|
|
for (it = tracks.begin(); it != tracks.end(); it++) {
|
|
if (it != tracks.begin())
|
|
print(", ");
|
|
print("%u", *it);
|
|
}
|
|
|
|
print("\n");
|
|
}
|
|
|
|
void check_error(int expected, int error)
|
|
{
|
|
if (expected != error)
|
|
print("Exception error: expected %d actual %d", expected, error);
|
|
}
|
|
|
|
/*
|
|
* Add songs to different playlists
|
|
*/
|
|
void test_0()
|
|
{
|
|
for (unsigned int i = 0; i < 128; i++) {
|
|
switch (i % 3) {
|
|
case 0:
|
|
playlist :: add("Banned", i);
|
|
break;
|
|
case 1:
|
|
playlist :: add("Favorites", i);
|
|
break;
|
|
default:
|
|
try {
|
|
playlist :: add("No Such Playlist", i);
|
|
} catch (int error) {
|
|
check_error(-E_EXIST, error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Find tracks in a playlist
|
|
*/
|
|
void test_1()
|
|
{
|
|
list_tracks("Banned");
|
|
list_tracks("Favorites");
|
|
|
|
try {
|
|
list_tracks("No Such Playlist");
|
|
} catch (int error) {
|
|
check_error(-E_EXIST, error);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Delete tracks from a playlist
|
|
*/
|
|
void test_2()
|
|
{
|
|
print("\n");
|
|
for (unsigned int i = 0; i < 30; i+=3)
|
|
playlist :: del("Banned", i);
|
|
list_tracks("Banned");
|
|
|
|
try {
|
|
playlist :: del("No Such Playlist", 2);
|
|
} catch (int error) {
|
|
check_error(-E_EXIST, error);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Check persistence of playlists
|
|
*/
|
|
void test_3()
|
|
{
|
|
print("\n");
|
|
|
|
playlist :: clear();
|
|
playlist :: init();
|
|
|
|
list_tracks("Banned");
|
|
list_tracks("Favorites");
|
|
|
|
try {
|
|
list_tracks("No Schu Playlist");
|
|
} catch (int error) {
|
|
check_error(-E_EXIST, error);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
test_0();
|
|
test_1();
|
|
test_2();
|
|
test_3();
|
|
return 0;
|
|
}
|