1 #include <r_core.h>
2 #include <r_anal.h>
3 #include <r_util.h>
4 #include <r_util/r_graph_drawable.h>
5 #include "minunit.h"
6
test_inherit_graph_creation()7 bool test_inherit_graph_creation() {
8 RCore *core = r_core_new ();
9 r_core_cmd0 (core, "ac A");
10 r_core_cmd0 (core, "ac B");
11 r_core_cmd0 (core, "ac C");
12 r_core_cmd0 (core, "ac D");
13 r_core_cmd0 (core, "acb B A");
14 r_core_cmd0 (core, "acb C A");
15 r_core_cmd0 (core, "acb D B");
16 r_core_cmd0 (core, "acb D C");
17 RGraph *graph = r_anal_class_get_inheritance_graph (core->anal);
18 mu_assert_notnull (graph, "Couldn't create the graph");
19 mu_assert_eq (graph->nodes->length, 4, "Wrong node count");
20
21 RListIter *iter;
22 RGraphNode *node;
23 int i = 0;
24 ls_foreach (graph->nodes, iter, node) {
25 RGraphNodeInfo *info = node->data;
26 switch (i++) {
27 case 0:
28 mu_assert_streq (info->title, "A", "Wrong node name");
29 mu_assert_eq (node->out_nodes->length, 2, "Wrong node out-nodes");
30 {
31 RListIter *iter;
32 RGraphNode *out_node;
33 int i = 0;
34 ls_foreach (node->out_nodes, iter, out_node) {
35 RGraphNodeInfo *info = out_node->data;
36 switch (i++) {
37 case 0:
38 mu_assert_streq (info->title, "B", "Wrong node name");
39 break;
40 case 1:
41 mu_assert_streq (info->title, "C", "Wrong node name");
42 break;
43 }
44 }
45 }
46 break;
47 case 1:
48 mu_assert_streq (info->title, "B", "Wrong node name");
49 mu_assert_eq (node->out_nodes->length, 1, "Wrong node out-nodes");
50 mu_assert_eq (node->in_nodes->length, 1, "Wrong node in-nodes");
51 {
52 RListIter *iter;
53 RGraphNode *out_node;
54 int i = 0;
55 ls_foreach (node->out_nodes, iter, out_node) {
56 RGraphNodeInfo *info = out_node->data;
57 switch (i++) {
58 case 0:
59 mu_assert_streq (info->title, "D", "Wrong node name");
60 break;
61 }
62 }
63 }
64 break;
65 case 2:
66 mu_assert_streq (info->title, "C", "Wrong node name");
67 mu_assert_eq (node->out_nodes->length, 1, "Wrong node out-nodes");
68 mu_assert_eq (node->in_nodes->length, 1, "Wrong node in-nodes");
69 {
70 RListIter *iter;
71 RGraphNode *out_node;
72 int i = 0;
73 ls_foreach (node->out_nodes, iter, out_node) {
74 RGraphNodeInfo *info = out_node->data;
75 switch (i++) {
76 case 0:
77 mu_assert_streq (info->title, "D", "Wrong node name");
78 break;
79 }
80 }
81 }
82 break;
83 case 3:
84 mu_assert_streq (info->title, "D", "Wrong node name");
85 mu_assert_eq (node->in_nodes->length, 2, "Wrong node in-nodes");
86 break;
87 default:
88 break;
89 }
90 }
91 r_core_free (core);
92 r_graph_free (graph);
93 mu_end;
94 }
95
all_tests()96 int all_tests() {
97 mu_run_test (test_inherit_graph_creation);
98 return tests_passed != tests_run;
99 }
100
main(int argc,char ** argv)101 int main(int argc, char **argv) {
102 return all_tests ();
103 }
104