/src/igraph/fuzzing/basic_properties_directed.cpp
Line | Count | Source |
1 | | /* |
2 | | igraph library. |
3 | | Copyright (C) 2024 The igraph development team |
4 | | |
5 | | This program is free software; you can redistribute it and/or modify |
6 | | it under the terms of the GNU General Public License as published by |
7 | | the Free Software Foundation; either version 2 of the License, or |
8 | | (at your option) any later version. |
9 | | |
10 | | This program is distributed in the hope that it will be useful, |
11 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | GNU General Public License for more details. |
14 | | |
15 | | You should have received a copy of the GNU General Public License |
16 | | along with this program; if not, write to the Free Software |
17 | | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | | 02110-1301 USA |
19 | | */ |
20 | | |
21 | | #include <igraph.h> |
22 | | #include <cstdlib> |
23 | | |
24 | 680 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
25 | 680 | igraph_t graph; |
26 | 680 | igraph_vector_int_t edges; |
27 | | |
28 | 680 | igraph_set_warning_handler(igraph_warning_handler_ignore); |
29 | | |
30 | 680 | if (Size % 2 == 0 || Size > 512+1 || Size < 1) { |
31 | 14 | return 0; |
32 | 14 | } |
33 | | |
34 | 666 | igraph_vector_int_init(&edges, Size-1); |
35 | 60.8k | for (size_t i=0; i < Size-1; ++i) { |
36 | 60.2k | VECTOR(edges)[i] = Data[i+1]; |
37 | 60.2k | } |
38 | | |
39 | | /* Directed */ |
40 | 666 | if (igraph_create(&graph, &edges, Data[0], IGRAPH_DIRECTED) == IGRAPH_SUCCESS) { |
41 | 666 | igraph_bool_t has_loop, has_multi, has_mutual, is_simple, is_complete; |
42 | 666 | igraph_bool_t is_connected, is_dag, is_forest, is_tree, has_eulerian_path, has_eulerian_cycles; |
43 | 666 | igraph_int_t ecount, vcount; |
44 | 666 | igraph_real_t r; |
45 | | |
46 | 666 | vcount = igraph_vcount(&graph); |
47 | 666 | ecount = igraph_ecount(&graph); |
48 | | |
49 | 666 | igraph_has_multiple(&graph, &has_multi); |
50 | 666 | igraph_has_loop(&graph, &has_loop); |
51 | 666 | igraph_has_mutual(&graph, &has_mutual, false); |
52 | 666 | igraph_invalidate_cache(&graph); |
53 | | |
54 | 666 | igraph_is_simple(&graph, &is_simple, IGRAPH_DIRECTED); |
55 | 666 | igraph_invalidate_cache(&graph); |
56 | | |
57 | 666 | IGRAPH_ASSERT((has_multi || has_loop) == !is_simple); |
58 | | |
59 | 666 | igraph_is_complete(&graph, &is_complete); |
60 | 666 | igraph_invalidate_cache(&graph); |
61 | | |
62 | 666 | IGRAPH_ASSERT(!is_complete || ecount >= vcount*(vcount-1)); |
63 | | |
64 | 666 | igraph_is_connected(&graph, &is_connected, IGRAPH_STRONG); |
65 | 666 | igraph_invalidate_cache(&graph); |
66 | | |
67 | 666 | IGRAPH_ASSERT(!is_connected || ecount >= vcount || vcount <= 1); |
68 | 666 | IGRAPH_ASSERT(!is_complete || is_connected || vcount == 0); |
69 | | |
70 | 666 | igraph_is_dag(&graph, &is_dag); |
71 | 666 | igraph_invalidate_cache(&graph); |
72 | | |
73 | 666 | IGRAPH_ASSERT(!is_complete || !is_dag || vcount <= 1); |
74 | 666 | IGRAPH_ASSERT(!is_connected || !is_dag || vcount == 1); |
75 | | |
76 | 666 | igraph_is_forest(&graph, &is_forest, NULL, IGRAPH_OUT); |
77 | 666 | igraph_invalidate_cache(&graph); |
78 | | |
79 | 666 | IGRAPH_ASSERT(!is_forest || is_dag); |
80 | 666 | IGRAPH_ASSERT(!is_forest || !is_connected || vcount == 1); |
81 | | |
82 | 666 | igraph_is_tree(&graph, &is_tree, NULL, IGRAPH_OUT); |
83 | 666 | igraph_invalidate_cache(&graph); |
84 | | |
85 | 666 | IGRAPH_ASSERT(!is_tree || is_forest); |
86 | 666 | IGRAPH_ASSERT(!is_tree || ecount >= vcount-1); |
87 | | |
88 | 666 | igraph_is_eulerian(&graph, &has_eulerian_path, &has_eulerian_cycles); |
89 | 666 | igraph_invalidate_cache(&graph); |
90 | | |
91 | 666 | IGRAPH_ASSERT(!has_eulerian_cycles || has_eulerian_path); |
92 | | |
93 | 666 | igraph_density(&graph, NULL, &r, false); |
94 | | |
95 | 666 | IGRAPH_ASSERT(!is_complete || r >= 1 || vcount <= 1); |
96 | | |
97 | 666 | igraph_density(&graph, NULL, &r, true); |
98 | | |
99 | 666 | igraph_destroy(&graph); |
100 | 666 | } |
101 | | |
102 | 666 | igraph_vector_int_destroy(&edges); |
103 | | |
104 | 666 | IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY); |
105 | | |
106 | 666 | return 0; // Non-zero return values are reserved for future use. |
107 | 666 | } |