| 1 |
#include <stdexcept> |
| 2 |
|
| 3 |
#include <catch2/catch_all.hpp> |
| 4 |
|
| 5 |
#include <cgraph++/AGraph.h> |
| 6 |
|
| 7 |
TEST_CASE("AGraph can be constructed from DOT source and has an underlying C " |
| 8 |
"data structure") { |
| 9 |
CGraph::AGraph g{"graph {a}"}; |
| 10 |
REQUIRE(g.c_struct() != nullptr); |
| 11 |
} |
| 12 |
|
| 13 |
TEST_CASE("AGraph constructed from an empty string throws an exception") { |
| 14 |
REQUIRE_THROWS_AS(CGraph::AGraph(""), std::runtime_error); |
| 15 |
} |
| 16 |
|
| 17 |
TEST_CASE("AGraph constructed from bad DOT source throws an exception") { |
| 18 |
REQUIRE_THROWS_AS(CGraph::AGraph("THIS_SHOULD_GENERATE_A_SYNTAX_ERROR"), |
| 19 |
std::runtime_error); |
| 20 |
} |
| 21 |
|
| 22 |
TEST_CASE("AGraph can be move constructed") { |
| 23 |
CGraph::AGraph g{"graph {a}"}; |
| 24 |
const auto c_ptr = g.c_struct(); |
| 25 |
REQUIRE(c_ptr != nullptr); |
| 26 |
auto other{std::move(g)}; |
| 27 |
REQUIRE(other.c_struct() == c_ptr); |
| 28 |
} |
| 29 |
|
| 30 |
TEST_CASE("AGraph can be move assigned") { |
| 31 |
CGraph::AGraph g{"graph {a}"}; |
| 32 |
const auto c_ptr = g.c_struct(); |
| 33 |
REQUIRE(c_ptr != nullptr); |
| 34 |
auto other = CGraph::AGraph("graph {b}"); |
| 35 |
const auto other_c_ptr = other.c_struct(); |
| 36 |
REQUIRE(other_c_ptr != nullptr); |
| 37 |
REQUIRE(other_c_ptr != c_ptr); |
| 38 |
other = std::move(g); |
| 39 |
REQUIRE(other.c_struct() == c_ptr); |
| 40 |
} |