[gimp/metadata-browser: 26/45] New test case to test import/edit/export/import.



commit 9195f5c7241b86b4a82fbd1a56bb8473908a78ea
Author: Roman Joost <roman bromeco de>
Date:   Tue Sep 27 21:09:19 2011 +1000

    New test case to test import/edit/export/import.
    
    This test should assure that imported data is not touched until edited.
    If it is edited it should be only merged on export.

 .../metadata/tests/test-xmp-model-functional.c     |   87 ++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)
---
diff --git a/plug-ins/metadata/tests/test-xmp-model-functional.c 
b/plug-ins/metadata/tests/test-xmp-model-functional.c
index 6f6c66d..6a0746c 100644
--- a/plug-ins/metadata/tests/test-xmp-model-functional.c
+++ b/plug-ins/metadata/tests/test-xmp-model-functional.c
@@ -39,6 +39,24 @@ typedef struct
   XMPModel *xmp_model;
 } GimpTestFixture;
 
+
+typedef struct
+{
+  const gchar *schema_name;
+  const gchar *name;
+  int          pos;
+} TestDataEntry;
+
+static TestDataEntry propertiestotest[] =
+{
+   { "dc",  "title",       1 },
+   { "dc",  "creator",     0 },
+   { "dc",  "description", 1 },
+   { NULL,  NULL,          0 }
+};
+TestDataEntry * const import_exportdata = propertiestotest;
+
+
 static void gimp_test_xmp_model_setup       (GimpTestFixture *fixture,
                                              gconstpointer    data);
 static void gimp_test_xmp_model_teardown    (GimpTestFixture *fixture,
@@ -79,6 +97,74 @@ gimp_test_xmp_model_teardown (GimpTestFixture *fixture,
 }
 
 /**
+ * test_xmp_model_import_export_structures:
+ * @fixture:
+ * @data:
+ *
+ * Test to assure the round trip of data import, editing, export is
+ * working.
+ **/
+static void
+test_xmp_model_import_export_structures (GimpTestFixture *fixture,
+                                         gconstpointer    data)
+{
+  int             i, j;
+  gboolean        result;
+  const gchar   **before_value;
+  const gchar   **after_value;
+  GString        *buffer;
+  TestDataEntry  *testdata;
+  const gchar    *scalarvalue = "test";
+  GError        **error       = NULL;
+
+  for (i = 0; import_exportdata[i].name != NULL; ++i)
+   {
+    testdata = &(import_exportdata[i]);
+
+    /* backup the original raw value */
+    before_value = xmp_model_get_raw_property_value (fixture->xmp_model,
+                                                     testdata->schema_name,
+                                                     testdata->name);
+    g_assert (before_value != NULL);
+
+    /* set a new scalar value */
+    result = xmp_model_set_scalar_property (fixture->xmp_model,
+                                            testdata->schema_name,
+                                            testdata->name,
+                                            scalarvalue);
+    g_assert (result == TRUE);
+
+    /* export */
+    buffer = g_string_new ("GIMP_TEST");
+    xmp_generate_packet (fixture->xmp_model, buffer);
+
+    /* import */
+    xmp_model_parse_buffer (fixture->xmp_model,
+                            buffer->str,
+                            buffer->len,
+                            TRUE,
+                            error);
+    after_value = xmp_model_get_raw_property_value (fixture->xmp_model,
+                                                    testdata->schema_name,
+                                                    testdata->name);
+    /* check that the scalar value is correctly exported */
+    g_assert (after_value != NULL);
+    g_assert_cmpstr (after_value[testdata->pos], ==, scalarvalue);
+
+    /* check that the original data is not changed */
+    for (j = 0; after_value[j] != NULL; ++j)
+     {
+       if (j == testdata->pos)
+         continue;
+
+       g_assert (before_value[j] != NULL);
+       g_assert (after_value[j]  != NULL);
+       g_assert_cmpstr (before_value[j], ==, after_value[j]);
+     }
+   }
+}
+
+/**
  * test_xmp_model_import_export:
  * @fixture:
  * @data:
@@ -158,6 +244,7 @@ int main(int argc, char **argv)
   g_test_init (&argc, &argv, NULL);
 
   ADD_TEST (test_xmp_model_import_export);
+  ADD_TEST (test_xmp_model_import_export_structures);
 
   result = g_test_run ();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]