ocarina/tests/audio/audio.cpp

93 lines
2.0 KiB
C++

/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <audio.h>
#include <deck.h>
#include <library.h>
#include <print.h>
#include <stdlib.h>
#include <string>
#include <unistd.h>
void gen_library()
{
system("tests/library/gen_library.sh");
print("\n");
}
void check_ret(const std :: string &test, bool ret, bool expected)
{
print("Test %s: ", test.c_str());
if (ret == expected)
print("Success!\n");
else
print("Failed.\n");
}
void check_ret(const std :: string &test, long ret, long expected)
{
print("Test %s: ", test.c_str());
if (ret == expected)
print("Success!\n");
else
print("Failed (Expected %ld but got %ld)\n", expected, ret);
}
/* Call various functions without a track loaded */
void test_0()
{
check_ret("0a", audio :: play(), false);
check_ret("0b", audio :: pause(), false);
check_ret("0c", audio :: seek_to(10), false);
check_ret("0d", audio :: next(), false);
check_ret("0e", audio :: stop(), false);
check_ret("0f", audio :: position(), 0);
check_ret("0g", audio :: duration(), 0);
try {
print("Test 0h: ");
audio :: current_trackid();
print("Failed.\n");
} catch (int error) {
print("Success!\n");
}
print("\n");
}
void test_1()
{
library :: Song song;
library :: lookup(0, &song);
check_ret("1a", audio :: next(), true);
check_ret("1b", audio :: play(), true);
check_ret("1c", audio :: pause(), true);
check_ret("1d", audio :: seek_to(1 * GST_SECOND), true);
check_ret("1e", audio :: position(), 1 * GST_SECOND);
check_ret("1f", audio :: stop(), true);
check_ret("1g", audio :: current_trackid() == 0, true);
check_ret("1h", audio :: position(), 0);
check_ret("1i", audio :: duration(), song.track->length);
}
int main(int argc, char **argv)
{
Playlist *plist;
gen_library();
/* Initialize before testing */
audio :: init(&argc, &argv);
test_0();
/* Read in library, set up a playlist */
library :: add_path("/tmp/library/0");
plist = deck :: create();
for (unsigned int i = 0; i < 150; i++)
plist->add(i);
test_1();
return 0;
}