[aravis] tests: test get_value_as_string for integer, float and boolean nodes.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] tests: test get_value_as_string for integer, float and boolean nodes.
- Date: Sun, 19 Jun 2011 22:01:44 +0000 (UTC)
commit 6c59d002ba8e8757606e89a37407fa1b30969f7e
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Mon Jun 20 00:01:08 2011 +0200
tests: test get_value_as_string for integer, float and boolean nodes.
src/arvgcfloat.c | 2 +-
src/arvgcfloatnode.c | 3 +-
src/arvgcnode.c | 35 +++++++++++++++++++++------
tests/data/genicam.xml | 8 ++++++
tests/genicam.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 98 insertions(+), 10 deletions(-)
---
diff --git a/src/arvgcfloat.c b/src/arvgcfloat.c
index eb8ac00..3baf3ea 100644
--- a/src/arvgcfloat.c
+++ b/src/arvgcfloat.c
@@ -38,7 +38,7 @@ G_DEFINE_INTERFACE (ArvGcFloat, arv_gc_float, G_TYPE_OBJECT)
double
arv_gc_float_get_value (ArvGcFloat *gc_float)
{
- g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), 0);
+ g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), 0.0);
return ARV_GC_FLOAT_GET_INTERFACE (gc_float)->get_value (gc_float);
}
diff --git a/src/arvgcfloatnode.c b/src/arvgcfloatnode.c
index 3bcb7fc..b23d19a 100644
--- a/src/arvgcfloatnode.c
+++ b/src/arvgcfloatnode.c
@@ -87,7 +87,8 @@ arv_gc_float_node_get_value_as_string (ArvGcNode *node)
{
ArvGcFloatNode *float_node = ARV_GC_FLOAT_NODE (node);
- g_ascii_dtostr (float_node->v_string, G_ASCII_DTOSTR_BUF_SIZE, arv_gc_float_get_value (ARV_GC_FLOAT (node)));
+ g_ascii_formatd (float_node->v_string, G_ASCII_DTOSTR_BUF_SIZE,
+ "%g", arv_gc_float_get_value (ARV_GC_FLOAT (node)));
return float_node->v_string;
}
diff --git a/src/arvgcnode.c b/src/arvgcnode.c
index 9df4497..c572ddc 100644
--- a/src/arvgcnode.c
+++ b/src/arvgcnode.c
@@ -238,29 +238,48 @@ arv_gc_node_get_value_type (ArvGcNode *node)
return 0;
}
+/**
+ * arv_gc_node_set_value_from_string:
+ * @gc_node: a #ArvGcNode
+ * @string: new node value, as string
+ *
+ * Set the node value using a string representation of the value. May not be applicable to every node type, but safe.
+ */
+
void
-arv_gc_node_set_value_from_string (ArvGcNode *node, const char *string)
+arv_gc_node_set_value_from_string (ArvGcNode *gc_node, const char *string)
{
ArvGcNodeClass *node_class;
- g_return_if_fail (ARV_IS_GC_NODE (node));
+ g_return_if_fail (ARV_IS_GC_NODE (gc_node));
g_return_if_fail (string != NULL);
- node_class = ARV_GC_NODE_GET_CLASS (node);
+ node_class = ARV_GC_NODE_GET_CLASS (gc_node);
if (node_class->set_value_from_string != NULL)
- node_class->set_value_from_string (node, string);
+ node_class->set_value_from_string (gc_node, string);
}
+/**
+ * arv_gc_node_get_value_as_string:
+ * @gc_node: a #ArvGcNode
+ *
+ * Retrieve the node value a string.
+ *
+ * <warning><para>Please not the string content is still owned by the @node object, which means the returned pointer may not be still valid after a new call to this function.</para></warning>
+ *
+ * Returns: (transfer none): a string representation of the node value, %NULL if not applicable.
+ */
+
const char *
-arv_gc_node_get_value_as_string (ArvGcNode *node)
+arv_gc_node_get_value_as_string (ArvGcNode *gc_node)
{
ArvGcNodeClass *node_class;
- g_return_val_if_fail (ARV_IS_GC_NODE (node), NULL);
+ g_return_val_if_fail (ARV_IS_GC_NODE (gc_node), NULL);
- node_class = ARV_GC_NODE_GET_CLASS (node);
+ node_class = ARV_GC_NODE_GET_CLASS (gc_node);
if (node_class->get_value_as_string != NULL)
- return node_class->get_value_as_string (node);
+ return node_class->get_value_as_string (gc_node);
return NULL;
}
diff --git a/tests/data/genicam.xml b/tests/data/genicam.xml
index bda2d0c..ceca502 100644
--- a/tests/data/genicam.xml
+++ b/tests/data/genicam.xml
@@ -22,6 +22,14 @@
<pFeature>Enumeration</pFeature>
</Category>
+ <Float Name="RWFloat">
+ <Value>0.1</Value>
+ </Float>
+
+ <Boolean Name="RWBoolean">
+ <Value>1</Value>
+ </Boolean>
+
<Integer Name="RWInteger">
<Value>1</Value>
</Integer>
diff --git a/tests/genicam.c b/tests/genicam.c
index f54d706..c4f4618 100644
--- a/tests/genicam.c
+++ b/tests/genicam.c
@@ -8,6 +8,7 @@ integer_test (void)
ArvGc *genicam;
ArvGcNode *node;
gint64 v_int64;
+ const char *v_string;
device = arv_fake_device_new ("TEST0");
g_assert (ARV_IS_FAKE_DEVICE (device));
@@ -21,6 +22,63 @@ integer_test (void)
v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node));
g_assert_cmpint (v_int64, ==, 1);
+ v_string = arv_gc_node_get_value_as_string (node);
+ g_assert_cmpstr (v_string, ==, "1");
+
+ g_object_unref (device);
+}
+
+static void
+boolean_test (void)
+{
+ ArvDevice *device;
+ ArvGc *genicam;
+ ArvGcNode *node;
+ gboolean v_boolean;
+ const char *v_string;
+
+ device = arv_fake_device_new ("TEST0");
+ g_assert (ARV_IS_FAKE_DEVICE (device));
+
+ genicam = arv_device_get_genicam (device);
+ g_assert (ARV_IS_GC (genicam));
+
+ node = arv_gc_get_node (genicam, "RWBoolean");
+ g_assert (ARV_IS_GC_BOOLEAN (node));
+
+ v_boolean = arv_gc_boolean_get_value (ARV_GC_BOOLEAN (node));
+ g_assert_cmpint (v_boolean, ==, TRUE);
+
+ v_string = arv_gc_node_get_value_as_string (node);
+ g_assert_cmpstr (v_string, ==, "true");
+
+ g_object_unref (device);
+}
+
+static void
+float_test (void)
+{
+ ArvDevice *device;
+ ArvGc *genicam;
+ ArvGcNode *node;
+ double v_double;
+ const char *v_string;
+
+ device = arv_fake_device_new ("TEST0");
+ g_assert (ARV_IS_FAKE_DEVICE (device));
+
+ genicam = arv_device_get_genicam (device);
+ g_assert (ARV_IS_GC (genicam));
+
+ node = arv_gc_get_node (genicam, "RWFloat");
+ g_assert (ARV_IS_GC_FLOAT_NODE (node));
+
+ v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node));
+ g_assert_cmpfloat (v_double, ==, 0.1);
+
+ v_string = arv_gc_node_get_value_as_string (node);
+ g_assert_cmpstr (v_string, ==, "0.1");
+
g_object_unref (device);
}
@@ -68,6 +126,8 @@ main (int argc, char *argv[])
arv_set_fake_camera_genicam_filename (GENICAM_FILENAME);
g_test_add_func ("/genicam/integer", integer_test);
+ g_test_add_func ("/genicam/boolean", boolean_test);
+ g_test_add_func ("/genicam/float", float_test);
g_test_add_func ("/genicam/enumeration", enumeration_test);
result = g_test_run();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]