[gxml] GomCollection: Fixed get_item() with unit tests
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] GomCollection: Fixed get_item() with unit tests
- Date: Sun, 6 Nov 2016 19:52:17 +0000 (UTC)
commit faf265f4ca3aa65ba12b63601398c79b01f56329
Author: Daniel Espinosa <esodan gmail com>
Date: Sun Nov 6 11:49:13 2016 -0600
GomCollection: Fixed get_item() with unit tests
gxml/GomCollections.vala | 4 +++-
test/GomSerializationTest.vala | 12 +++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/gxml/GomCollections.vala b/gxml/GomCollections.vala
index ce73487..256e927 100644
--- a/gxml/GomCollections.vala
+++ b/gxml/GomCollections.vala
@@ -52,7 +52,9 @@ public interface GXml.GomCollection : Object
* {@link nodes_index}.
*/
public virtual DomElement? get_item (int index) throws GLib.Error {
- var e = element.child_nodes.get (index);
+ unowned List<int> i = nodes_index.nth (index);
+ if (i == null) return null;
+ var e = element.child_nodes.get (i.data);
if (e != null)
if (!(e is GomElement))
throw new DomError.INVALID_NODE_TYPE_ERROR
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index 238a1d7..94892ae 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -154,7 +154,6 @@ class GomSerializationTest : GXmlTest {
assert ("<BookStand Classification=\"Science\"/>" in s);
assert (bs.registers == null);
var br = new BookRegister ();
- br.year = 2016;
bs.registers = new GomArrayList.initialize (bs,br.local_name);
s = bs.to_string ();
assert (s != null);
@@ -162,19 +161,26 @@ class GomSerializationTest : GXmlTest {
assert ("<BookStand Classification=\"Science\"/>" in s);
try { bs.registers.add (br); } catch {}
br = new BookRegister.document (bs.owner_document);
+ br.year = 2016;
bs.registers.add (br);
s = bs.to_string ();
assert (s != null);
GLib.message ("DOC:"+s);
- assert ("<BookStand Classification=\"Science\"><BookRegister Year=\"0\"/></BookStand>" in s);
+ assert ("<BookStand Classification=\"Science\"><BookRegister Year=\"2016\"/></BookStand>" in s);
var br2 = new BookRegister.document (bs.owner_document);
bs.registers.add (br2);
+ br2.year = 2010;
+ bs.append_child (bs.owner_document.create_element ("Test"));
var br3 = new BookRegister.document (bs.owner_document);
bs.registers.add (br3);
+ br3.year = 2000;
s = bs.to_string ();
assert (s != null);
GLib.message ("DOC:"+s);
- assert ("<BookStand Classification=\"Science\"><BookRegister Year=\"0\"/><BookRegister
Year=\"0\"/><BookRegister Year=\"0\"/></BookStand>" in s);
+ assert ("<BookStand Classification=\"Science\"><BookRegister Year=\"2016\"/><BookRegister
Year=\"2010\"/><Test/><BookRegister Year=\"2000\"/></BookStand>" in s);
+ assert ((bs.registers.get_item (0) as BookRegister).year == 2016);
+ assert ((bs.registers.get_item (1) as BookRegister).year == 2010);
+ assert ((bs.registers.get_item (2) as BookRegister).year == 2000);
});
Test.add_func ("/gxml/gom-serialization/read/properties", () => {
var b = new Book ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]