1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, see <https://www.gnu.org/licenses/>.
14  *
15  * Copyright (C) 2017 Red Hat, Inc.
16  */
17 
18 #include "config.h"
19 #include <stdio.h>
20 
21 #include "gegl.h"
22 
23 static void
sub_graph_crop_passthrough_invalidated(GeglNode * node,GeglRectangle * rect,gpointer user_data)24 sub_graph_crop_passthrough_invalidated (GeglNode *node, GeglRectangle *rect, gpointer user_data)
25 {
26   GeglRectangle bbox;
27   gboolean *result = (gboolean *) user_data;
28 
29   bbox = gegl_node_get_bounding_box (node);
30 
31   if (bbox.x != 0 || bbox.y != 0 || bbox.width != 100 || bbox.height != 100)
32     *result = FALSE;
33 }
34 
35 static gboolean
test_sub_graph_crop_passthrough(void)36 test_sub_graph_crop_passthrough (void)
37 {
38   GeglNode *color;
39   GeglNode *crop;
40   GeglNode *crop_color;
41   GeglNode *graph;
42   GeglNode *input;
43   GeglNode *output;
44   GeglNode *sub_graph;
45   gboolean result = TRUE;
46   gulong invalidated_id;
47 
48   graph = gegl_node_new ();
49 
50   color = gegl_node_new_child (graph,
51                                "operation", "gegl:color",
52                                NULL);
53 
54   crop_color = gegl_node_new_child (graph,
55                               "operation", "gegl:crop",
56                               "x", 0.0,
57                               "y", 0.0,
58                               "width", 100.0,
59                               "height", 100.0,
60                               NULL);
61 
62   sub_graph = gegl_node_new ();
63   gegl_node_add_child (graph, sub_graph);
64   input = gegl_node_get_input_proxy (sub_graph, "input");
65   output = gegl_node_get_output_proxy (sub_graph, "output");
66 
67   crop = gegl_node_new_child (sub_graph,
68                               "operation", "gegl:crop",
69                               "x", 10.0,
70                               "y", 10.0,
71                               "width", 10.0,
72                               "height", 10.0,
73                               NULL);
74 
75   gegl_node_link_many (input, crop, output, NULL);
76   gegl_node_link_many (color, crop_color, sub_graph, NULL);
77   gegl_node_process (sub_graph);
78 
79   invalidated_id = g_signal_connect (sub_graph,
80                                      "invalidated",
81                                      G_CALLBACK (sub_graph_crop_passthrough_invalidated),
82                                      &result);
83 
84   gegl_node_set_passthrough (crop, TRUE);
85 
86   g_signal_handler_disconnect (sub_graph, invalidated_id);
87 
88   g_object_unref (graph);
89   g_object_unref (sub_graph);
90 
91   return result;
92 }
93 
94 #define RUN_TEST(test_name) \
95 { \
96   if (test_name()) \
97     { \
98       printf ("" #test_name " ... PASS\n"); \
99       tests_passed++; \
100     } \
101   else \
102     { \
103       printf ("" #test_name " ... FAIL\n"); \
104       tests_failed++; \
105     } \
106   tests_run++; \
107 }
108 
109 int
main(int argc,char ** argv)110 main (int argc, char **argv)
111 {
112   gint tests_run    = 0;
113   gint tests_passed = 0;
114   gint tests_failed = 0;
115 
116   gegl_init (0, NULL);
117   g_object_set(G_OBJECT(gegl_config()),
118                "swap", "RAM",
119                "use-opencl", FALSE,
120                NULL);
121 
122   RUN_TEST (test_sub_graph_crop_passthrough)
123 
124   gegl_exit ();
125 
126   if (tests_passed == tests_run)
127     return 0;
128   return -1;
129 
130   return 0;
131 }
132