[gxml] Added GomArrayString and GomFixedArray methods
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Added GomArrayString and GomFixedArray methods
- Date: Sun, 22 Jan 2017 20:09:12 +0000 (UTC)
commit 37c95f6bbe0050d9741ac8693e527a782dbe8e35
Author: Daniel Espinosa <esodan gmail com>
Date: Sat Jan 21 21:29:51 2017 -0600
Added GomArrayString and GomFixedArray methods
* New select() and search() methods
* Added Unit Tests for GomArrayString and GomFixedArray
gxml/GomProperty.vala | 47 +++++++++++++++++++++++++++++++++++++++-
test/GomSerializationTest.vala | 36 ++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 1 deletions(-)
---
diff --git a/gxml/GomProperty.vala b/gxml/GomProperty.vala
index 04fa1fb..85daad8 100644
--- a/gxml/GomProperty.vala
+++ b/gxml/GomProperty.vala
@@ -82,7 +82,11 @@ public abstract class GXml.GomBaseProperty : Object, GXml.GomProperty {
/**
* {@inheritDoc}
*/
- public void initialize (string attribute_name) { message ("Type: "+this.get_type
().name());_attribute_name = attribute_name; }
+ public void initialize (string attribute_name) {
+#if DEBUG
+ message ("Type: "+this.get_type ().name());
+#endif
+ _attribute_name = attribute_name; }
/**
* Takes a string and check if it can be validated using
* {@link validation_rule}.
@@ -142,6 +146,27 @@ public class GXml.GomArrayString : GomBaseProperty {
}
return false;
}
+ /**
+ * Select one string from array at index:
+ */
+ public void select (int index) {
+ if (_values == null) return;
+ if (index < 0 || index > _values.length) return;
+ value = _values.index (index);
+ }
+ /**
+ * Check if string is in array
+ */
+ public bool search (string str) {
+ if (_values == null) return true;
+ for (int i = 0; i < _values.length; i++) {
+ if (_values.index (i) == str) return true;
+ }
+ return false;
+ }
+ /**
+ * {inheritDoc}
+ */
public override string value {
owned get {
return _value;
@@ -182,6 +207,26 @@ public class GXml.GomFixedArrayString : GomBaseProperty {
}
return false;
}
+ /**
+ * Select one string from array at index:
+ */
+ public void select (int index) {
+ if (index < 0 || index > _values.length) return;
+ value = _values[index];
+ }
+ /**
+ * Check if string is in array
+ */
+ public bool search (string str) {
+ if (_values == null) return true;
+ for (int i = 0; i < _values.length; i++) {
+ if (_values[i] == str) return true;
+ }
+ return false;
+ }
+ /**
+ * {inheritDoc}
+ */
public override string value {
owned get {
return _value;
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index 278150c..d6e2471 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -287,6 +287,8 @@ class GomSerializationTest : GXmlTest {
public Speed speed { get; set; }
public TensionType tension_type { get; set; }
public Tension tension { get; set; }
+ public Model model { get; set; }
+ public ModelVariation modelvariation { get; set; }
construct { try { initialize ("Motor"); } catch { assert_not_reached (); } }
public string to_string () {
var parser = new XParser (this);
@@ -327,6 +329,18 @@ class GomSerializationTest : GXmlTest {
try { initialize ("Tension"); } catch { assert_not_reached (); }
}
}
+ public class Model : GomFixedArrayString {
+ construct {
+ initialize ("Model");;
+ initialize_strings ({"MODEL1","MODEL2"});
+ }
+ }
+ public class ModelVariation : GomArrayString {
+ construct {
+ initialize ("ModelVariation");
+ initialize_strings ({"VAR1","VAR2 "});
+ }
+ }
}
public static void add_tests () {
Test.add_func ("/gxml/gom-serialization/write/properties", () => {
@@ -526,6 +540,28 @@ class GomSerializationTest : GXmlTest {
assert (s != null);
GLib.message ("DOC:"+s);
assert ("<Motor On=\"true\" Torque=\"3.1416\" Speed=\"3600.1011\" TensionType=\"dc\"
Tension=\"125\"/>" in s);
+ m.model = new Motor.Model ();
+ assert (m.model != null);
+ assert (m.model.value != null);
+ assert (m.model.value == "");
+ m.model.value = "Model3";
+ assert (m.model.value == "Model3");
+ assert (!m.model.is_valid_value ());
+ s = m.to_string ();
+ assert (s != null);
+ GLib.message ("DOC:"+s);
+ assert ("<Motor On=\"true\" Torque=\"3.1416\" Speed=\"3600.1011\" TensionType=\"dc\" Tension=\"125\"
Model=\"Model3\"/>" in s);
+ m.modelvariation = new Motor.ModelVariation ();
+ assert (m.modelvariation != null);
+ assert (m.modelvariation.value != null);
+ assert (m.modelvariation.value == "");
+ m.modelvariation.value = "var3";
+ assert (m.modelvariation.value == "var3");
+ assert (!m.modelvariation.is_valid_value ());
+ s = m.to_string ();
+ assert (s != null);
+ GLib.message ("DOC:"+s);
+ assert ("<Motor On=\"true\" Torque=\"3.1416\" Speed=\"3600.1011\" TensionType=\"dc\" Tension=\"125\"
Model=\"Model3\" ModelVariation=\"var3\"/>" in s);
} catch (GLib.Error e) {
GLib.message ("Error: "+e.message);
assert_not_reached ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]