|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: Unit tests for class_hierarchyt output functions |
| 4 | +
|
| 5 | + Author: Diffblue Limited. All rights reserved. |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include <testing-utils/catch.hpp> |
| 10 | +#include <testing-utils/load_java_class.h> |
| 11 | + |
| 12 | +#include <goto-programs/class_hierarchy.h> |
| 13 | + |
| 14 | +#include <iostream> |
| 15 | +#include <sstream> |
| 16 | + |
| 17 | +void require_parent_child_relationship( |
| 18 | + const std::string &parent_raw, |
| 19 | + const std::string &child_raw, |
| 20 | + const std::string &output, |
| 21 | + const std::string &output_dot) |
| 22 | +{ |
| 23 | + std::string parent = "java::" + parent_raw; |
| 24 | + std::string child = "java::" + child_raw; |
| 25 | + |
| 26 | + std::stringstream |
| 27 | + plain_child_expectation, plain_parent_expectation, dot_expectation; |
| 28 | + |
| 29 | + plain_child_expectation << "Child of " << parent << ": " << child; |
| 30 | + plain_parent_expectation << "Parent of " << child << ": " << parent; |
| 31 | + dot_expectation << "\"" << child << "\" -> \"" << parent << "\""; |
| 32 | + |
| 33 | + REQUIRE(output.find(plain_child_expectation.str()) != std::string::npos); |
| 34 | + REQUIRE(output.find(plain_parent_expectation.str()) != std::string::npos); |
| 35 | + REQUIRE(output_dot.find(dot_expectation.str()) != std::string::npos); |
| 36 | +} |
| 37 | + |
| 38 | +SCENARIO( |
| 39 | + "Output a simple class hierarchy" |
| 40 | + "[core][goto-programs][class_hierarchy]") |
| 41 | +{ |
| 42 | + symbol_tablet symbol_table = |
| 43 | + load_java_class("HierarchyTest", "goto-programs/"); |
| 44 | + class_hierarchyt hierarchy; |
| 45 | + |
| 46 | + std::stringstream output_stream; |
| 47 | + std::stringstream output_dot_stream; |
| 48 | + |
| 49 | + hierarchy(symbol_table); |
| 50 | + hierarchy.output(output_stream); |
| 51 | + hierarchy.output_dot(output_dot_stream); |
| 52 | + |
| 53 | + std::string output = output_stream.str(); |
| 54 | + std::string output_dot = output_dot_stream.str(); |
| 55 | + |
| 56 | + require_parent_child_relationship( |
| 57 | + "HierarchyTest", "HierarchyTestChild1", output, output_dot); |
| 58 | + require_parent_child_relationship( |
| 59 | + "HierarchyTest", "HierarchyTestChild2", output, output_dot); |
| 60 | + require_parent_child_relationship( |
| 61 | + "HierarchyTestChild1", "HierarchyTestGrandchild", output, output_dot); |
| 62 | + require_parent_child_relationship( |
| 63 | + "HierarchyTestInterface1", "HierarchyTestGrandchild", output, output_dot); |
| 64 | + require_parent_child_relationship( |
| 65 | + "HierarchyTestInterface2", "HierarchyTestGrandchild", output, output_dot); |
| 66 | +} |
0 commit comments