Skip to content

Commit

Permalink
Catch exception in the right place to skip tests without ALSA
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmoreno committed Dec 22, 2023
1 parent 78f7a06 commit dd2eb32
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
26 changes: 18 additions & 8 deletions tests/test_midirouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ void test_basic_midirouter() {

void test_midirouter_from_alsa() {
auto router = std::make_shared<rtpmididns::midirouter_t>();
auto aseq = std::make_shared<rtpmididns::aseq_t>("Test");
std::shared_ptr<rtpmididns::aseq_t> aseq;
try {
aseq = std::make_shared<rtpmididns::aseq_t>("Test");
} catch (rtpmididns::alsa_connect_exception &exc) {
ERROR("ALSA CONNECT EXCEPTION: {}", exc.what());
INFO("Skipping test as ALSA is not available.");
return;
}

auto alsanetwork =
std::make_shared<rtpmididns::local_alsa_multi_listener_t>("test", aseq);
router->add_peer(alsanetwork);
Expand Down Expand Up @@ -144,7 +152,14 @@ void test_midirouter_from_alsa() {

void test_midirouter_for_each_peer() {
auto router = std::make_shared<rtpmididns::midirouter_t>();
auto aseq = std::make_shared<rtpmididns::aseq_t>("Test");
std::shared_ptr<rtpmididns::aseq_t> aseq;
try {
aseq = std::make_shared<rtpmididns::aseq_t>("Test");
} catch (rtpmididns::alsa_connect_exception &exc) {
ERROR("ALSA CONNECT EXCEPTION: {}", exc.what());
INFO("Skipping test as ALSA is not available.");
return;
}
auto alsanetwork =
std::make_shared<rtpmididns::local_alsa_multi_listener_t>("test", aseq);
auto midiio = std::make_shared<test_midiio_t>();
Expand Down Expand Up @@ -181,11 +196,6 @@ int main(int argc, char **argv) {
TEST(test_midirouter_for_each_peer),
};

try {
testcase.run(argc, argv);
} catch (rtpmididns::alsa_connect_exception &exc) {
ERROR("ALSA CONNECT EXCEPTION: {}", exc.what());
INFO("Skipping test as ALSA is not available.");
}
testcase.run(argc, argv);
return testcase.exit_code();
}
28 changes: 19 additions & 9 deletions tests/test_midirouter2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ void test_send_receive_messages() {
// rtpmididns::settings.rtpmidid_name = "rtpmidid-test";
// rtpmididns::settings.rtpmidid_port = "60004";

auto aseq =
std::make_shared<rtpmididns::aseq_t>(rtpmididns::settings.alsa_name);
std::shared_ptr<rtpmididns::aseq_t> aseq;
try {
aseq =
std::make_shared<rtpmididns::aseq_t>(rtpmididns::settings.alsa_name);
} catch (rtpmididns::alsa_connect_exception &exc) {
ERROR("ALSA CONNECT EXCEPTION: {}", exc.what());
INFO("Skipping test as ALSA is not available.");
return;
}

test_client_id = aseq->client_id;

router->add_peer(rtpmididns::make_local_alsa_multi_listener(
Expand Down Expand Up @@ -81,7 +89,14 @@ void test_send_receive_messages() {
//
// 7. All data we send from A hsould be read a B, and vice versa.

auto aseq = std::make_shared<rtpmididns::aseq_t>("TESTING DEVICE");
std::shared_ptr<rtpmididns::aseq_t> aseq;
try {
aseq = std::make_shared<rtpmididns::aseq_t>("TESTING DEVICE");
} catch (rtpmididns::alsa_connect_exception &exc) {
ERROR("ALSA CONNECT EXCEPTION: {}", exc.what());
INFO("Skipping test as ALSA is not available.");
return;
}

// 1. ALSA A connect to WR RTPMIDID
INFO("1. ALSA A connect to WR RTPMIDID");
Expand Down Expand Up @@ -243,12 +258,7 @@ int main(int argc, char **argv) {
TEST(test_send_receive_messages),
};

try {
testcase.run(argc, argv);
} catch (rtpmididns::alsa_connect_exception &exc) {
ERROR("ALSA CONNECT EXCEPTION: {}", exc.what());
INFO("Skipping test as ALSA is not available.");
}
testcase.run(argc, argv);

return testcase.exit_code();
}

0 comments on commit dd2eb32

Please sign in to comment.