Skip to content

Commit

Permalink
Add build test for clap::helpers::Host
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinitou committed Jan 19, 2024
1 parent 1beec8a commit a47eb1c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prerequisites
# Prerequisites
*.d

# Compiled Object files
Expand Down Expand Up @@ -31,9 +31,10 @@
*.out
*.app

#vs
# Visual Studio
.vs
out
.vscode

#clion
.idea
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ if (${CLAP_HELPERS_BUILD_TESTS})
add_executable(${PROJECT_NAME}-tests EXCLUDE_FROM_ALL
tests/create-an-actual-plugin.cc
tests/hex-encoder.cc
tests/host.cc
tests/plugin.cc
tests/param-queue-tests.cc
tests/event-list-tests.cc
Expand Down
4 changes: 2 additions & 2 deletions include/clap/helpers/host.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,15 @@ namespace clap { namespace helpers {
///////////////
template <MisbehaviourHandler h, CheckingLevel l>
Host<h, l> &Host<h, l>::from(const clap_host *host) noexcept {
if constexpr (l >= CheckingLevel::Minimal) {
CLAP_IF_CONSTEXPR (l >= CheckingLevel::Minimal) {
if (!host) CLAP_HELPERS_UNLIKELY {
std::cerr << "Passed an null host pointer" << std::endl;
std::terminate();
}
}

auto self = static_cast<Host *>(host->host_data);
if constexpr (l >= CheckingLevel::Minimal) {
CLAP_IF_CONSTEXPR (l >= CheckingLevel::Minimal) {
if (!self) CLAP_HELPERS_UNLIKELY {
std::cerr << "Passed an invalid host pointer because the host_data is null"
<< std::endl;
Expand Down
6 changes: 6 additions & 0 deletions include/clap/helpers/macros.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#pragma once

#if defined(__cplusplus) && __cplusplus >= 201703L
# define CLAP_IF_CONSTEXPR if constexpr
#else
# define CLAP_IF_CONSTEXPR if
#endif

#if defined(__cplusplus) && __cplusplus >= 202002L
# define CLAP_HELPERS_UNLIKELY [[unlikely]]
#else
Expand Down
34 changes: 34 additions & 0 deletions tests/host.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <clap/helpers/plugin-proxy.hxx>
#include <clap/helpers/host.hh>
#include <clap/helpers/host.hxx>

#include <catch2/catch_all.hpp>

template class clap::helpers::Host<clap::helpers::MisbehaviourHandler::Terminate,
clap::helpers::CheckingLevel::Maximal>;
template class clap::helpers::Host<clap::helpers::MisbehaviourHandler::Terminate,
clap::helpers::CheckingLevel::Minimal>;
template class clap::helpers::Host<clap::helpers::MisbehaviourHandler::Terminate,
clap::helpers::CheckingLevel::None>;
template class clap::helpers::Host<clap::helpers::MisbehaviourHandler::Ignore,
clap::helpers::CheckingLevel::Maximal>;

template class clap::helpers::PluginProxy<clap::helpers::MisbehaviourHandler::Terminate,
clap::helpers::CheckingLevel::Maximal>;
template class clap::helpers::PluginProxy<clap::helpers::MisbehaviourHandler::Terminate,
clap::helpers::CheckingLevel::Minimal>;
template class clap::helpers::PluginProxy<clap::helpers::MisbehaviourHandler::Terminate,
clap::helpers::CheckingLevel::None>;
template class clap::helpers::PluginProxy<clap::helpers::MisbehaviourHandler::Ignore,
clap::helpers::CheckingLevel::Maximal>;

CATCH_TEST_CASE("Host - Link") {
clap::helpers::Host<clap::helpers::MisbehaviourHandler::Terminate,
clap::helpers::CheckingLevel::Maximal> *h0 = nullptr;
clap::helpers::Host<clap::helpers::MisbehaviourHandler::Terminate,
clap::helpers::CheckingLevel::Minimal> *h1 = nullptr;
clap::helpers::Host<clap::helpers::MisbehaviourHandler::Terminate,
clap::helpers::CheckingLevel::None> *h2 = nullptr;
clap::helpers::Host<clap::helpers::MisbehaviourHandler::Ignore,
clap::helpers::CheckingLevel::Maximal> *h3 = nullptr;
}

0 comments on commit a47eb1c

Please sign in to comment.