diff --git a/core/core.cpp b/core/core.cpp index 160c76a8..4416faa4 100644 --- a/core/core.cpp +++ b/core/core.cpp @@ -20,7 +20,7 @@ void core :: init(struct core_init_data *init) playlist_init(init->playlist_ops); collection_init(init->collection_ops); history_init(init->history_ops); - deck :: init(init->tempq_ops); + tempq_init(init->tempq_ops); audio :: init(); } diff --git a/core/deck.cpp b/core/deck.cpp index 0aace50b..720be476 100644 --- a/core/deck.cpp +++ b/core/deck.cpp @@ -12,11 +12,6 @@ static std::list queue_deck; static struct file deck_file; -TempQueue :: TempQueue() -{ - queue_init(this, 0, NULL); -} - TempQueue :: TempQueue(bool random, struct queue_ops *ops) { unsigned int flags = Q_ENABLED | Q_SAVE_FLAGS | Q_SAVE_SORT; @@ -61,51 +56,23 @@ void TempQueue :: del(unsigned int id) } -static void upgrade_v0() +void tempq_init(struct queue_ops *ops) { - int random, ascending; - unsigned int num, field; - queue *library = collection_get_queue(); - - file_readf(&deck_file, "%d %u", &random, &num); - if (random) - queue_set_flag(library, Q_RANDOM); - - for (unsigned int i = 0; i < num; i++) { - file_readf(&deck_file, "%u %d", &field, &ascending); - queue_sort(library, (compare_t)field, (i == 0) ? true : false); - if (!ascending) - queue_sort(library, (compare_t)field, false); - } -} - -void deck :: init(struct queue_ops *temp_ops) -{ - unsigned int num; - bool upgraded = false; - std::list::iterator it; + unsigned int num, i; file_init(&deck_file, "deck", 1); - if (!file_open(&deck_file, OPEN_READ)) return; - - if (file_version(&deck_file) == 0) { - upgrade_v0(); - upgraded = true; - } + if (file_version(&deck_file) < 1) + return; file_readf(&deck_file, "%u", &num); - queue_deck.resize(num); - - for (it = queue_deck.begin(); it != queue_deck.end(); it++) { - it->read(deck_file); - it->q_ops = temp_ops; + for (i = 0; i < num; i++) { + queue_deck.push_back(TempQueue(false, NULL)); + queue_deck.back().read(deck_file); + queue_deck.back().q_ops = ops; } file_close(&deck_file); - - if (upgraded) - deck :: write(); } void deck :: write() diff --git a/include/core/deck.h b/include/core/deck.h index 709b1d17..0e6087a0 100644 --- a/include/core/deck.h +++ b/include/core/deck.h @@ -17,7 +17,6 @@ extern "C" { class TempQueue : public queue { public: - TempQueue(); TempQueue(bool, struct queue_ops *); void read(file &); @@ -43,11 +42,6 @@ public: namespace deck { - /** - * Read the deck file from disk and restore the queues. - */ - void init(struct queue_ops *); - /** * Save the current queues to a file on disk. */ @@ -107,4 +101,8 @@ namespace deck }; + +/* Called to initialize the temporary queue manager. */ +void tempq_init(struct queue_ops *); + #endif /* OCARINA_CORE_DECK_H */ diff --git a/tests/Data/deck b/tests/Data/deck index 0449cb69..8e645fcb 100644 --- a/tests/Data/deck +++ b/tests/Data/deck @@ -1,4 +1,4 @@ -0 -2 3 0 1 8 1 7 1 2 +1 +2 1 4 0 1 2 3 1 5 4 5 6 7 8 diff --git a/tests/core/audio.cpp b/tests/core/audio.cpp index 00be2438..47d5f237 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.cpp @@ -93,7 +93,7 @@ void test_init() playlist_init(NULL); collection_init(NULL); history_init(NULL); - deck :: init(NULL); + tempq_init(NULL); audio :: init(); track = audio :: current_track(); diff --git a/tests/core/deck.cpp b/tests/core/deck.cpp index 44e5f19b..3b3a397c 100644 --- a/tests/core/deck.cpp +++ b/tests/core/deck.cpp @@ -6,21 +6,39 @@ extern "C" { #include #include #include +#include #include #include } #include "test.h" static queue *Q_NULL = NULL; -static struct track *TRACK_NULL = NULL; static void test_init() { - unsigned int val; - file f; - std::list::iterator it; + filter_init(); + tags_init(); + playlist_init(NULL); + collection_init(NULL); + history_init(NULL); - test_equal(deck :: next(), TRACK_NULL); + test_equal(deck :: next(), NULL); + tempq_init(NULL); + test_equal(deck :: next(), NULL); + test_equal(deck :: get(0), NULL); + test_equal(deck :: index(NULL), 0); + test_equal(deck :: get_queues().size(), (size_t)0); + + history_deinit(); + collection_deinit(); + playlist_deinit(); + tags_deinit(); + filter_deinit(); +} + +static void test_create_mv_destroy() +{ + queue *q1, *q2; test_cp_data_dir(); filter_init(); @@ -28,49 +46,7 @@ static void test_init() playlist_init(NULL); collection_init(NULL); history_init(NULL); - deck :: init(NULL); - - test_equal(queue_has_flag(collection_get_queue(), Q_RANDOM), true); - test_equal(deck :: get_queues().size(), (size_t)2); - - it = deck :: get_queues().begin(); - test_equal(queue_size(&(*it)), (unsigned)4); - for (unsigned int i = 0; i < 4; i++) - test_equal(queue_at(&(*it), i)->tr_dbe.dbe_index, i); - - it++; - test_equal(queue_size(&(*it)), (unsigned)5); - for (unsigned int i = 0; i < 5; i++) - test_equal(queue_at(&(*it), i)->tr_dbe.dbe_index, i + 4); - - /* - * Test that we saved the deck in the new format - */ - file_init(&f, "deck", 0); - file_open(&f, OPEN_READ); - test_equal(file_version(&f), (unsigned)1); - file_readf(&f, "%u", &val); - test_equal(val, (unsigned)2); - - for (unsigned int i = 0; i < 2; i++) { - file_readf(&f, "%u", &val); /* queues[i].flags */ - test_equal(val, (unsigned)1); - - file_readf(&f, "%u", &val); /* queues[i].size */ - test_equal(val, 4 + i); - - for (unsigned int j = 0; j < 4 + i; j++) { - file_readf(&f, "%u", &val); - test_equal(val, (4 * i) + j); - } - } - - file_close(&f); -} - -static void test_create_mv_destroy() -{ - queue *q1, *q2; + tempq_init(NULL); q1 = deck :: create(true, NULL); test_not_equal(q1, Q_NULL); @@ -141,7 +117,7 @@ static void test_next_prev() } DECLARE_UNIT_TESTS( - UNIT_TEST("Deck Init", test_init), + UNIT_TEST("Temporary Queue Initialization", test_init), UNIT_TEST("Deck Create, Move, and Destroy", test_create_mv_destroy), UNIT_TEST("Deck Next and Prev", test_next_prev), );