|
| 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 | +} |
0 commit comments