Skip to content

Commit 199caf6

Browse files
committed
factor out common call graph unit test functions into header
1 parent 0376eab commit 199caf6

File tree

4 files changed

+42
-62
lines changed

4 files changed

+42
-62
lines changed

unit/analyses/call_graph.cpp

+1-25
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,10 @@ Module: Unit test for call graph generation
1414
#include <analyses/call_graph_helpers.h>
1515

1616
#include <util/symbol_table.h>
17-
#include <util/std_code.h>
1817

1918
#include <goto-programs/goto_convert_functions.h>
2019

21-
static symbolt create_void_function_symbol(
22-
const irep_idt &name,
23-
const codet &code)
24-
{
25-
const code_typet void_function_type({}, empty_typet());
26-
symbolt function;
27-
function.name=name;
28-
function.type=void_function_type;
29-
function.mode=ID_java;
30-
function.value=code;
31-
return function;
32-
}
33-
34-
static bool multimap_key_matches(
35-
const std::multimap<irep_idt, irep_idt> &map,
36-
const irep_idt &key,
37-
const std::set<irep_idt> &values)
38-
{
39-
auto matching_values=map.equal_range(key);
40-
std::set<irep_idt> matching_set;
41-
for(auto it=matching_values.first; it!=matching_values.second; ++it)
42-
matching_set.insert(it->second);
43-
return matching_set==values;
44-
}
20+
#include "call_graph_test_utils.h"
4521

4622
SCENARIO("call_graph",
4723
"[core][util][call_graph]")

unit/analyses/call_graph_test_utils.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* call_graph_test_utils.h
3+
*
4+
* Created on: 25 Jun 2018
5+
* Author: polgreen
6+
*/
7+
8+
#ifndef CPROVER_ANALYSES_CALL_GRAPH_TEST_UTILS_H
9+
#define CPROVER_ANALYSES_CALL_GRAPH_TEST_UTILS_H
10+
11+
#include <analyses/call_graph.h>
12+
13+
#include <util/std_code.h>
14+
15+
static symbolt
16+
create_void_function_symbol(const irep_idt &name, const codet &code)
17+
{
18+
const code_typet void_function_type({}, empty_typet());
19+
symbolt function;
20+
function.name = name;
21+
function.type = void_function_type;
22+
function.mode = ID_java;
23+
function.value = code;
24+
return function;
25+
}
26+
27+
static bool multimap_key_matches(
28+
const std::multimap<irep_idt, irep_idt> &map,
29+
const irep_idt &key,
30+
const std::set<irep_idt> &values)
31+
{
32+
auto matching_values = map.equal_range(key);
33+
std::set<irep_idt> matching_set;
34+
for(auto it = matching_values.first; it != matching_values.second; ++it)
35+
matching_set.insert(it->second);
36+
return matching_set == values;
37+
}
38+
39+
#endif /* CPROVER_ANALYSES_CALL_GRAPH_TEST_UTILS_H */

unit/analyses/dependence_graph.cpp

+1-12
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,7 @@ Author: Chris Smowton, [email protected]
1818
#include <langapi/mode.h>
1919
#include <ansi-c/ansi_c_language.h>
2020

21-
static symbolt create_void_function_symbol(
22-
const irep_idt &name,
23-
const codet &code)
24-
{
25-
const code_typet void_function_type({}, empty_typet());
26-
symbolt function;
27-
function.name = name;
28-
function.type = void_function_type;
29-
function.mode = ID_java;
30-
function.value = code;
31-
return function;
32-
}
21+
#include "call_graph_test_utils.h"
3322

3423
const std::set<goto_programt::const_targett>&
3524
dependence_graph_test_get_control_deps(const dep_graph_domaint &domain)

unit/analyses/disconnect_unreachable_nodes_in_graph.cpp

+1-25
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,13 @@ Module: Unit test for graph class functions
1010

1111
#include <testing-utils/catch.hpp>
1212

13-
#include <analyses/call_graph.h>
1413
#include <analyses/call_graph_helpers.h>
1514

16-
#include <util/std_code.h>
1715
#include <util/symbol_table.h>
1816

1917
#include <goto-programs/goto_convert_functions.h>
2018

21-
static symbolt
22-
create_void_function_symbol(const irep_idt &name, const codet &code)
23-
{
24-
const code_typet void_function_type({}, empty_typet());
25-
symbolt function;
26-
function.name = name;
27-
function.type = void_function_type;
28-
function.mode = ID_java;
29-
function.value = code;
30-
return function;
31-
}
32-
33-
static bool multimap_key_matches(
34-
const std::multimap<irep_idt, irep_idt> &map,
35-
const irep_idt &key,
36-
const std::set<irep_idt> &values)
37-
{
38-
auto matching_values = map.equal_range(key);
39-
std::set<irep_idt> matching_set;
40-
for(auto it = matching_values.first; it != matching_values.second; ++it)
41-
matching_set.insert(it->second);
42-
return matching_set == values;
43-
}
19+
#include "call_graph_test_utils.h"
4420

4521
SCENARIO("graph", "[core][util][graph]")
4622
{

0 commit comments

Comments
 (0)