[gxml] Added MappeableElementPairKey test case
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Added MappeableElementPairKey test case
- Date: Tue, 21 Feb 2017 18:34:21 +0000 (UTC)
commit 5060232e760756a077b6d6907c8fdb49957df4cf
Author: Daniel Espinosa <esodan gmail com>
Date: Tue Feb 21 11:21:56 2017 -0600
Added MappeableElementPairKey test case
test/GomSerializationTest.vala | 48 +++++++++++++++++++++++++++++++++++++++-
1 files changed, 47 insertions(+), 1 deletions(-)
---
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index 5e12e60..d802017 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -210,7 +210,7 @@ class GomSerializationTest : GXmlTest {
FEBRUARY
}
}
- public class BookRegister : GomElement, MappeableElement {
+ public class BookRegister : GomElement, MappeableElement, MappeableElementPairKey {
private Book _book = null;
[Description (nick="::Year")]
public int year { get; set; }
@@ -235,8 +235,14 @@ class GomSerializationTest : GXmlTest {
_document = doc;
}
public string get_map_key () {
+ if (book == null) return "";
return "%d".printf (year)+"-"+book.name;
}
+ public string get_map_primary_key () { return "%d".printf (year); }
+ public string get_map_secondary_key () {
+ if (book == null) return "";
+ return book.name;
+ }
public Book create_book (string name) {
return Object.new (typeof (Book),
"owner-document", this.owner_document,
@@ -257,6 +263,7 @@ class GomSerializationTest : GXmlTest {
}
public class BookStand : GomElement {
HashRegisters _hashmap_registers = null;
+ HashPairRegisters _hashpair_registers = null;
[Description (nick="::Classification")]
public string classification { get; set; default = "Science"; }
public Dimension dimension_x { get; set; }
@@ -276,6 +283,17 @@ class GomSerializationTest : GXmlTest {
_hashmap_registers = value;
}
}
+ public HashPairRegisters hashpair_registers {
+ get {
+ if (_hashpair_registers == null)
+ _hashpair_registers = Object.new (typeof (HashPairRegisters),"element",this)
+ as HashPairRegisters;
+ return _hashpair_registers;
+ }
+ set {
+ _hashpair_registers = value;
+ }
+ }
public Books books { get; set; }
construct {
try { initialize ("BookStand"); } catch { assert_not_reached (); }
@@ -329,6 +347,12 @@ class GomSerializationTest : GXmlTest {
catch { assert_not_reached (); }
}
}
+ public class HashPairRegisters : GomHashPairedMap {
+ construct {
+ try { initialize (typeof (BookRegister)); }
+ catch { assert_not_reached (); }
+ }
+ }
public class Books : GomHashMap {
construct {
try { initialize_with_key (typeof (Book), "Name"); }
@@ -726,6 +750,28 @@ class GomSerializationTest : GXmlTest {
assert_not_reached ();
}
});
+ Test.add_func ("/gxml/gom-serialization/write/mappeablepairedkey", () => {
+ try {
+ var bs = new BookStand ();
+ assert (bs.hashpair_registers != null);
+ var br = bs.hashpair_registers.create_item () as BookRegister;
+ var book = br.create_book ("Book1");
+ assert (book.name == "Book1");
+ br.book = book;
+ br.year = 2017;
+ assert (bs.hashpair_registers.length == 0);
+ bs.hashpair_registers.append (br);
+ assert (bs.hashpair_registers.length == 1);
+ var b1 = bs.hashpair_registers.get ("2017","Book1") as BookRegister;
+ assert (b1 != null);
+ assert (b1.year == 2017);
+ assert (b1.book != null);
+ assert (b1.book.name == "Book1");
+ } catch (GLib.Error e) {
+ GLib.message ("Error: "+e.message);
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/gom-serialization/write/gom-property", () => {
try {
var m = new Motor ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]