queue: Update reand and write code
And update the unit test at the same time. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
869d67558e
commit
b9e5ce3356
|
@ -30,7 +30,7 @@ void Queue :: write(File &f)
|
|||
{
|
||||
f << _flags << " " << _tracks.size();
|
||||
for (unsigned int i = 0; i < _tracks.size(); i++)
|
||||
f << " " << _tracks[i];
|
||||
f << " " << _tracks[i]->id;
|
||||
}
|
||||
|
||||
void Queue :: read(File &f)
|
||||
|
@ -41,6 +41,7 @@ void Queue :: read(File &f)
|
|||
for (unsigned int i = 0; i < n; i++) {
|
||||
f >> id;
|
||||
_tracks[i] = tagdb :: lookup(id);
|
||||
_length += _tracks[i]->length;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -340,6 +340,37 @@ void test_sorting()
|
|||
test :: success();
|
||||
}
|
||||
|
||||
void test_saving()
|
||||
{
|
||||
TestQueue q(Q_RANDOM);
|
||||
TestQueue r(0);
|
||||
File f("test.q");
|
||||
|
||||
test_fill_q(&q);
|
||||
|
||||
test :: begin();
|
||||
f.open(OPEN_WRITE);
|
||||
q.write(f);
|
||||
f.close();
|
||||
test :: success();
|
||||
|
||||
test :: begin();
|
||||
f.open(OPEN_READ);
|
||||
r.read(f);
|
||||
f.close();
|
||||
test :: success();
|
||||
|
||||
test_equal(r.has_flag(Q_RANDOM), q.has_flag(Q_RANDOM));
|
||||
test_equal(r.size(), q.size());
|
||||
test_equal(r.size_str(), q.size_str());
|
||||
test_equal(r.length_str(), q.length_str());
|
||||
|
||||
test :: begin();
|
||||
for (unsigned int i = 0; i < q.size(); i++)
|
||||
check_equal(r[i]->id, q[i]->id);
|
||||
test :: success();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
test :: cp_library();
|
||||
|
@ -353,5 +384,6 @@ int main(int argc, char **argv)
|
|||
run_test("Queue Pick Next Test", test_next);
|
||||
run_test("Queue Select Track Test", test_select);
|
||||
run_test("Queue Sorting Test", test_sorting);
|
||||
run_test("Queue Save and Load Test", test_saving);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue