Skip to content

Commit c238aee

Browse files
author
thk123
committed
Add a unit test for checking the ordering by instruction
1 parent 8e06fb2 commit c238aee

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ SRC += analyses/ai/ai.cpp \
1616
analyses/does_remove_const/is_type_at_least_as_const_as.cpp \
1717
big-int/big-int.cpp \
1818
compound_block_locations.cpp \
19+
goto-checker/report_util/is_property_less_than.cpp \
1920
goto-instrument/cover_instrument.cpp \
2021
goto-instrument/cover/cover_only.cpp \
2122
goto-programs/goto_model_function_type_consistency.cpp \
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2016-2020 Diffblue Limited. All Rights Reserved.
2+
3+
#include <goto-checker/report_util.cpp>
4+
#include <testing-utils/use_catch.h>
5+
6+
static goto_programt::instructiont instruction_for_location(
7+
const irep_idt &file,
8+
const irep_idt &function,
9+
size_t line_no)
10+
{
11+
source_locationt location;
12+
location.set_file(file);
13+
location.set_function(function);
14+
location.set_line(line_no);
15+
goto_programt::instructiont instruction;
16+
instruction.source_location = location;
17+
return instruction;
18+
}
19+
20+
static property_infot test_info(const goto_programt::const_targett &target)
21+
{
22+
return property_infot(target, "ignored", property_statust::UNKNOWN);
23+
}
24+
25+
static propertyt
26+
property(const irep_idt &identifier, const property_infot &info)
27+
{
28+
return std::make_pair(identifier, info);
29+
}
30+
31+
std::ostream &operator<<(std::ostream &os, const propertyt &value)
32+
{
33+
os << "{ property_id=" << value.first << ", "
34+
<< " property_location={ "
35+
<< " file=" << value.second.pc->source_location.get_file() << ", "
36+
<< " function=" << value.second.pc->source_location.get_function() << ", "
37+
<< " line=" << value.second.pc->source_location.get_line() << "}}";
38+
return os;
39+
}
40+
41+
TEST_CASE("Comparing two properties")
42+
{
43+
SECTION("Compare locations")
44+
{
45+
goto_programt::instructionst instructions;
46+
instructions.push_back(instruction_for_location("fileA", "funcA", 1));
47+
instructions.push_back(instruction_for_location("fileA", "funcA", 2));
48+
instructions.push_back(instruction_for_location("fileA", "funcB", 1));
49+
instructions.push_back(instruction_for_location("fileA", "funcB", 2));
50+
instructions.push_back(instruction_for_location("fileB", "funcA", 1));
51+
instructions.push_back(instruction_for_location("fileB", "funcA", 2));
52+
instructions.push_back(instruction_for_location("fileB", "funcB", 1));
53+
instructions.push_back(instruction_for_location("fileB", "funcB", 2));
54+
55+
for(auto first_location = instructions.begin();
56+
first_location != instructions.end();
57+
++first_location)
58+
{
59+
for(auto second_location = std::next(first_location);
60+
second_location != instructions.end();
61+
++second_location)
62+
{
63+
const propertyt p1 = property("ignored", test_info(first_location));
64+
const propertyt p2 = property("ignored", test_info(second_location));
65+
INFO(p1);
66+
INFO(p2);
67+
REQUIRE(is_property_less_than(p1, p2));
68+
REQUIRE_FALSE(is_property_less_than(p2, p1));
69+
}
70+
}
71+
}
72+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
goto-checker
2+
testing-utils

0 commit comments

Comments
 (0)