Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for clap::helpers::Host #50

Merged
merged 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ if (${CLAP_HELPERS_BUILD_TESTS})
endif()

add_executable(${PROJECT_NAME}-tests EXCLUDE_FROM_ALL
tests/create-an-actual-host.cc
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch, maybe it is time to require C++17? ;-)
It is 2024 so it is already 7 years old.

Copy link
Contributor Author

@Trinitou Trinitou Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I would be fine with that
Maybe @baconpaul can tell? My original idea was to use clap::helpers::Host for clap-wrapper as well. So it should meet the requirements there, too. I think somewhere I read that they wrote something like "c++17 min" but just want to ensure that it would be OK.

The CMakeLists.txt defaulted to 11 before we started upgrading it recently and still does I think. So I guess we would have to change it there as well (?)
(edit: I justed looked it up: at least the clap-helpers-tests default to 11 so that it looks like it is the minimum.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok just removed the CLAP_IF_CONSTEXPR
We can solve the rest (c++11 etc) later

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
12 changes: 6 additions & 6 deletions include/clap/helpers/preset-discovery-metadata-receiver.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace clap { namespace helpers {

virtual bool beginPreset(const char *name, const char *load_key) noexcept { return false; }

virtual void addPluginId(const clap_plugin_id_t *plugin_id) noexcept {}
virtual void addPluginId(const clap_universal_plugin_id *plugin_id) noexcept {}

virtual void setCollectionId(const char *collection_id) noexcept {}

Expand All @@ -46,8 +46,8 @@ namespace clap { namespace helpers {

virtual void setDescription(const char *description) noexcept {}

virtual void setTimestamps(clap_timestamp_t creation_time,
clap_timestamp_t modification_time) noexcept {}
virtual void setTimestamps(clap_timestamp creation_time,
clap_timestamp modification_time) noexcept {}

virtual void addFeature(const char *feature) noexcept {}

Expand Down Expand Up @@ -77,7 +77,7 @@ namespace clap { namespace helpers {

static void
receiverAddPluginId(const struct clap_preset_discovery_metadata_receiver *receiver,
const clap_plugin_id_t *plugin_id) noexcept;
const clap_universal_plugin_id *plugin_id) noexcept;

static void
receiverSetCollectionId(const struct clap_preset_discovery_metadata_receiver *receiver,
Expand All @@ -95,8 +95,8 @@ namespace clap { namespace helpers {

static void
receiverSetTimestamps(const struct clap_preset_discovery_metadata_receiver *receiver,
clap_timestamp_t creation_time,
clap_timestamp_t modification_time) noexcept;
clap_timestamp creation_time,
clap_timestamp modification_time) noexcept;

static void receiverAddFeature(const struct clap_preset_discovery_metadata_receiver *receiver,
const char *feature) noexcept;
Expand Down
6 changes: 3 additions & 3 deletions include/clap/helpers/preset-discovery-metadata-receiver.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace clap { namespace helpers {
template <MisbehaviourHandler h, CheckingLevel l>
void PresetDiscoveryMetadataReceiver<h, l>::receiverAddPluginId(
const struct clap_preset_discovery_metadata_receiver *receiver,
const clap_plugin_id_t *plugin_id) noexcept {
const clap_universal_plugin_id *plugin_id) noexcept {
auto &self = from(receiver);
return self.addPluginId(plugin_id);
}
Expand Down Expand Up @@ -88,8 +88,8 @@ namespace clap { namespace helpers {
template <MisbehaviourHandler h, CheckingLevel l>
void PresetDiscoveryMetadataReceiver<h, l>::receiverSetTimestamps(
const struct clap_preset_discovery_metadata_receiver *receiver,
clap_timestamp_t creation_time,
clap_timestamp_t modification_time) noexcept {
clap_timestamp creation_time,
clap_timestamp modification_time) noexcept {
auto &self = from(receiver);
return self.setTimestamps(creation_time, modification_time);
}
Expand Down
36 changes: 36 additions & 0 deletions tests/create-an-actual-host.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Actually use host.hh / host.hxx to create a host. Assert that it is constructable
*/

#include "clap/helpers/host.hh"
#include "clap/helpers/host.hxx"

#include <type_traits>

#include <catch2/catch_all.hpp>

struct test_host : clap::helpers::Host<clap::helpers::MisbehaviourHandler::Terminate,
clap::helpers::CheckingLevel::Maximal>
{
test_host() : clap::helpers::Host<clap::helpers::MisbehaviourHandler::Terminate,
clap::helpers::CheckingLevel::Maximal>(
"Test Case Host",
"Free Audio",
"http://cleveraudio.org",
"1.0.0") {}

bool threadCheckIsMainThread() const noexcept override { return true; };
bool threadCheckIsAudioThread() const noexcept override { return false; };

void requestRestart() noexcept override {};
void requestProcess() noexcept override {};
void requestCallback() noexcept override {};
};

CATCH_TEST_CASE("Create an Actual Host")
{
CATCH_SECTION("Test Host is Creatable")
{
CATCH_REQUIRE(std::is_constructible<test_host>::value);
}
}
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we want to use a macros to expand all the combinations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, maybe in a later PR?

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;
}
Loading