[libgames-support] tests: Add test for importing old C scores
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgames-support] tests: Add test for importing old C scores
- Date: Sun, 14 Feb 2016 01:43:54 +0000 (UTC)
commit f61f11911e210d0515cd5c0c60c669f292431d04
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Sat Feb 13 19:34:49 2016 -0600
tests: Add test for importing old C scores
tests/test-scores.vala | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/tests/test-scores.vala b/tests/test-scores.vala
index 887e6c5..d99f155 100644
--- a/tests/test-scores.vala
+++ b/tests/test-scores.vala
@@ -1,6 +1,7 @@
/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright © 2014 Nikhar Agrawal
+ * Copyright © 2016 Michael Catanzaro <mcatanzaro gnome org>
*
* This file is part of libgames-support.
*
@@ -151,12 +152,60 @@ private void test_save_score_to_file ()
}
}
+private void test_import_from_score_directory ()
+{
+ try
+ {
+ var expected_score = new Score (42,
+ new DateTime.now_local ().to_unix (),
+ Environment.get_real_name ());
+ var category = new Category ("new-cat", "");
+
+ var test_directory = File.new_for_path (get_test_directory_name ());
+ test_directory.make_directory_with_parents ();
+
+ var old_scores_file = File.new_for_path (Path.build_filename (get_test_directory_name (),
+ "old-cat",
+ null));
+ var stream = old_scores_file.append_to (FileCreateFlags.NONE);
+ stream.write_all (@"$(expected_score.score) $(expected_score.time)\n".data, null);
+ stream.close ();
+ assert (old_scores_file.query_exists ());
+
+ var context = new Context.with_importer (
+ "libgames-support-test",
+ "",
+ null,
+ (key) => {
+ assert (key == "new-cat");
+ return category;
+ },
+ Games.Scores.Style.PLAIN_DESCENDING,
+ new Games.Scores.DirectoryImporter ((old_key) => {
+ assert (old_key == "old-cat");
+ return "new-cat";
+ }));
+ assert (!old_scores_file.query_exists ());
+
+ var imported_scores = context.get_high_scores (category);
+ assert (imported_scores.size == 1);
+
+ var imported_score = imported_scores.first ();
+ assert (Score.equals (expected_score, imported_score));
+ }
+ catch (Error e)
+ {
+ error (e.message);
+ }
+}
+
public int main (string args[])
{
Test.init (ref args);
var test_suite = TestSuite.get_root ();
test_suite.add (new TestCase ("Scores Files Exist", () => {}, test_scores_files_exist, delete_scores));
test_suite.add (new TestCase ("Save Score To File", () => {}, test_save_score_to_file, delete_scores));
+ test_suite.add (new TestCase ("Import from Score Directory", () => {}, test_import_from_score_directory,
delete_scores));
return Test.run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]