36TEST_F(AutoplacerCancellation, DuringRoutingDiscardsCandidateAndKeepsBest)
38 auto net = std::make_shared<Wire>();
39 auto source = std::make_shared<AndGate>();
40 auto target = std::make_shared<AndGate>();
41 source->setInputs({
Bus{std::make_shared<Wire>()},
Bus{std::make_shared<Wire>()}});
42 source->setOutputs({
Bus{net}});
43 target->setOutputs({
Bus{std::make_shared<Wire>()}});
44 target->setInputs({
Bus{net},
Bus{std::make_shared<Wire>()}});
48 first.setPorts({{
"a", {-20, 20}}, {
"b", {-20, 60}}}, {{
"o", {100, 40}}});
49 second.
setPorts({{
"a", {-20, 20}}, {
"b", {-20, 60}}}, {{
"o", {100, 40}}});
50 std::vector<GraphicalLogicComponent*> components{&first, &second};
55 unsigned checks = 0, firstCompleteChecks = 0;
60 options.
progress = [&](
int done, int) {
61 if (done == 1 && !firstCompleteChecks)
62 firstCompleteChecks = checks;
65 ASSERT_FALSE(complete.cancelled);
66 ASSERT_FALSE(complete.wires.empty());
67 ASSERT_GT(firstCompleteChecks, 2u);
68 for (
unsigned cancelAt = 1; cancelAt <= firstCompleteChecks; ++cancelAt) {
71 options.
isCancelled = [&] {
return ++checks >= cancelAt; };
73 EXPECT_TRUE(result.cancelled) << cancelAt;
74 EXPECT_TRUE(result.components.empty()) << cancelAt;
75 EXPECT_TRUE(result.wires.empty()) << cancelAt;
77 bool cancelled =
false;
79 options.
progress = [&](
int done, int) {
84 EXPECT_FALSE(best.cancelled);
85 EXPECT_FALSE(best.wires.empty());
89 options.
isCancelled = [&] {
return cancelled && ++checks >= 4; };
91 EXPECT_FALSE(interrupted.cancelled);
92 EXPECT_EQ(interrupted.components, best.components);
93 ASSERT_EQ(interrupted.wires.size(), best.wires.size());
94 for (std::size_t i = 0; i < best.wires.size(); ++i) {
95 EXPECT_EQ(interrupted.wires[i].bus, best.wires[i].bus);
96 EXPECT_EQ(interrupted.wires[i].points, best.wires[i].points);
98 EXPECT_EQ(first.pos(), QPointF());
99 EXPECT_EQ(second.pos(), QPointF());