|
Packit Service |
2781ba |
/*
|
|
Packit Service |
2781ba |
* This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
2781ba |
* it under the terms of the GNU General Public License as published by
|
|
Packit Service |
2781ba |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
2781ba |
* (at your option) any later version.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
2781ba |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
2781ba |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
2781ba |
* GNU General Public License for more details.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
2781ba |
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Copyright (C) 2011 Jon Nordby <jononor@gmail.com>
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Test saving/serialization of graphs to XML
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <glib.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <gegl.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "common.c"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Saving an empty graph should result in a valid UTF-8 encoded XML document,
|
|
Packit Service |
2781ba |
* with the same basic structure as if the graph was non-empty.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Kind-of a sanity test, should run before other tests. */
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
test_save_empty_graph (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const gchar * const expected_result = "\n<gegl>\n</gegl>\n";
|
|
Packit Service |
2781ba |
GeglNode *graph;
|
|
Packit Service |
2781ba |
gchar *xml;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
graph = gegl_node_new();
|
|
Packit Service |
2781ba |
xml = gegl_node_to_xml(graph, "");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
assert_equivalent_xml(xml, expected_result);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_object_unref(graph);
|
|
Packit Service |
2781ba |
g_free(xml);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* gegl:nop nodes should be discarded when saving the graph */
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
test_save_nop_nodes (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const gchar * const expected_result = "\n<gegl>\n</gegl>\n";
|
|
Packit Service |
2781ba |
GeglNode *graph, *op1, *op2;
|
|
Packit Service |
2781ba |
gchar *xml;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
graph = gegl_node_new();
|
|
Packit Service |
2781ba |
op1 = gegl_node_new_child(graph, "operation", "gegl:nop", NULL);
|
|
Packit Service |
2781ba |
op2 = gegl_node_new_child(graph, "operation", "gegl:nop", NULL);
|
|
Packit Service |
2781ba |
gegl_node_link_many(op1, op2, NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
xml = gegl_node_to_xml(op2, "");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
assert_equivalent_xml(xml, expected_result);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_object_unref(graph);
|
|
Packit Service |
2781ba |
g_free(xml);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Saving a graph with multiple nodes
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Note: Relies on the number and names of properties of the used operations to not change */
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
test_save_multiple_nodes (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const gchar * const expected_result = \
|
|
Packit Service |
2781ba |
"\n\
|
|
Packit Service |
2781ba |
<gegl>\n\
|
|
Packit Service |
2781ba |
<node operation='gegl:invert'>\n\
|
|
Packit Service |
2781ba |
</node>\n\
|
|
Packit Service |
2781ba |
<node operation='gegl:crop'>\n\
|
|
Packit Service |
2781ba |
<params>\n\
|
|
Packit Service |
2781ba |
<param name='x'>0</param>\n\
|
|
Packit Service |
2781ba |
<param name='y'>0</param>\n\
|
|
Packit Service |
2781ba |
<param name='width'>0</param>\n\
|
|
Packit Service |
2781ba |
<param name='height'>0</param>\n\
|
|
Packit Service |
2781ba |
</params>\n\
|
|
Packit Service |
2781ba |
</node>\n\
|
|
Packit Service |
2781ba |
</gegl>\n";
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
GeglNode *graph, *op1, *op2;
|
|
Packit Service |
2781ba |
gchar *xml;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
graph = gegl_node_new();
|
|
Packit Service |
2781ba |
op1 = gegl_node_new_child(graph, "operation", "gegl:crop",
|
|
Packit Service |
2781ba |
"x", 0.0, "y", 0.0,
|
|
Packit Service |
2781ba |
"width", 0.0, "height", 0.0,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
op2 = gegl_node_new_child(graph, "operation", "gegl:invert", NULL);
|
|
Packit Service |
2781ba |
gegl_node_link_many(op1, op2, NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
xml = gegl_node_to_xml(op2, "");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
assert_equivalent_xml(xml, expected_result);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_object_unref(graph);
|
|
Packit Service |
2781ba |
g_free(xml);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Test that saving a subgraph works */
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
test_save_toplevel_graph (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const gchar * const expected_result = \
|
|
Packit Service |
2781ba |
"\n\
|
|
Packit Service |
2781ba |
<gegl>\n\
|
|
Packit Service |
2781ba |
<node operation='gegl:invert'>\n\
|
|
Packit Service |
2781ba |
</node>\n\
|
|
Packit Service |
2781ba |
<node operation='gegl:crop'>\n\
|
|
Packit Service |
2781ba |
<params>\n\
|
|
Packit Service |
2781ba |
<param name='x'>0</param>\n\
|
|
Packit Service |
2781ba |
<param name='y'>0</param>\n\
|
|
Packit Service |
2781ba |
<param name='width'>0</param>\n\
|
|
Packit Service |
2781ba |
<param name='height'>0</param>\n\
|
|
Packit Service |
2781ba |
</params>\n\
|
|
Packit Service |
2781ba |
</node>\n\
|
|
Packit Service |
2781ba |
</gegl>\n";
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
GeglNode *graph, *op1, *op2;
|
|
Packit Service |
2781ba |
gchar *xml;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
graph = gegl_node_new();
|
|
Packit Service |
2781ba |
op1 = gegl_node_new_child(graph, "operation", "gegl:crop",
|
|
Packit Service |
2781ba |
"x", 0.0, "y", 0.0,
|
|
Packit Service |
2781ba |
"width", 0.0, "height", 0.0,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
op2 = gegl_node_new_child(graph, "operation", "gegl:invert", NULL);
|
|
Packit Service |
2781ba |
gegl_node_link_many(op1, op2, NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
xml = gegl_node_to_xml(graph, "");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
assert_equivalent_xml(xml, expected_result);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_object_unref(graph);
|
|
Packit Service |
2781ba |
g_free(xml);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
int
|
|
Packit Service |
2781ba |
main (int argc, char *argv[])
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
int result = -1;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_init(&argc, &argv);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_test_init(&argc, &argv, NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_test_add_func("/xml/save/empty_graph", test_save_empty_graph);
|
|
Packit Service |
2781ba |
g_test_add_func("/xml/save/only_nop_nodes", test_save_nop_nodes);
|
|
Packit Service |
2781ba |
g_test_add_func("/xml/save/multiple_nodes", test_save_multiple_nodes);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Expected failure
|
|
Packit Service |
2781ba |
g_test_add_func("/xml/save/toplevel_graph", test_save_toplevel_graph);
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
result = g_test_run();
|
|
Packit Service |
2781ba |
gegl_exit();
|
|
Packit Service |
2781ba |
return result;
|
|
Packit Service |
2781ba |
}
|