Merge pull request #842 from jpcima/midnam-cpp-2
Midnam C++ tests with new API
This commit is contained in:
commit
48b9bccc71
7 changed files with 60 additions and 7 deletions
|
|
@ -1707,7 +1707,7 @@ midnam_export(LV2_Handle instance)
|
|||
static void
|
||||
midnam_free(char *string)
|
||||
{
|
||||
free(string);
|
||||
sfizz_free_memory(string);
|
||||
}
|
||||
|
||||
static const void *
|
||||
|
|
|
|||
10
src/sfizz.h
10
src/sfizz.h
|
|
@ -274,7 +274,7 @@ SFIZZ_EXPORTED_API int sfizz_get_num_curves(sfizz_synth_t* synth);
|
|||
* @param synth The synth.
|
||||
* @param model The model name used if a non-empty string, otherwise generated.
|
||||
*
|
||||
* @return A newly allocated XML string, which must be freed after use.
|
||||
* @return A newly allocated XML string, which must be freed after use using sfizz_free_memory().
|
||||
*/
|
||||
SFIZZ_EXPORTED_API char* sfizz_export_midnam(sfizz_synth_t* synth, const char* model);
|
||||
|
||||
|
|
@ -1097,6 +1097,14 @@ SFIZZ_EXPORTED_API int sfizz_get_cc_label_number(sfizz_synth_t* synth, int label
|
|||
*/
|
||||
SFIZZ_EXPORTED_API const char * sfizz_get_cc_label_text(sfizz_synth_t* synth, int label_index);
|
||||
|
||||
/**
|
||||
* @brief Free a block of memory allocated by the library.
|
||||
* @brief 1.0.0
|
||||
*
|
||||
* @param ptr The address of the memory to free.
|
||||
*/
|
||||
SFIZZ_EXPORTED_API void sfizz_free_memory(void* ptr);
|
||||
|
||||
/**
|
||||
* @addtogroup Messaging
|
||||
* @{
|
||||
|
|
|
|||
|
|
@ -980,7 +980,7 @@ public:
|
|||
*
|
||||
* @return A XML string.
|
||||
*/
|
||||
std::string exportMidnam(const char* model);
|
||||
std::string exportMidnam(const std::string& model) const;
|
||||
|
||||
/**
|
||||
* @addtogroup Messaging
|
||||
|
|
|
|||
|
|
@ -338,7 +338,7 @@ void sfz::Sfizz::enableLogging(const std::string& prefix) noexcept
|
|||
|
||||
void sfz::Sfizz::setLoggingPrefix(const std::string& prefix) noexcept
|
||||
{
|
||||
|
||||
(void)prefix;
|
||||
}
|
||||
|
||||
void sfz::Sfizz::disableLogging() noexcept
|
||||
|
|
@ -361,7 +361,7 @@ void sfz::Sfizz::clearExternalDefinitions()
|
|||
synth->synth.getParser().clearExternalDefinitions();
|
||||
}
|
||||
|
||||
std::string sfz::Sfizz::exportMidnam(const char* model)
|
||||
std::string sfz::Sfizz::exportMidnam(const std::string& model) const
|
||||
{
|
||||
return synth->synth.exportMidnam(model);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -319,7 +319,8 @@ void sfizz_enable_logging(sfizz_synth_t* synth, const char* prefix)
|
|||
|
||||
void sfizz_set_logging_prefix(sfizz_synth_t* synth, const char* prefix)
|
||||
{
|
||||
|
||||
(void)synth;
|
||||
(void)prefix;
|
||||
}
|
||||
|
||||
void sfizz_disable_logging(sfizz_synth_t* synth)
|
||||
|
|
@ -410,6 +411,11 @@ const char * sfizz_get_cc_label_text(sfizz_synth_t* synth, int label_index)
|
|||
return ccLabels[label_index].second.c_str();
|
||||
}
|
||||
|
||||
void sfizz_free_memory(void* ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
sfizz_client_t* sfizz_create_client(void* data)
|
||||
{
|
||||
return reinterpret_cast<sfizz_client_t*>(new sfz::Client(data));
|
||||
|
|
|
|||
38
tests/BindingsT.cpp
Normal file
38
tests/BindingsT.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
||||
// license. You should have receive a LICENSE.md file along with the code.
|
||||
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||
|
||||
#include "sfizz.h"
|
||||
#include "sfizz.hpp"
|
||||
#include "catch2/catch.hpp"
|
||||
#include "ghc/fs_std.hpp"
|
||||
|
||||
TEST_CASE("[Bindings] Midnam C++")
|
||||
{
|
||||
sfz::Sfizz synth;
|
||||
const auto path = fs::current_path() / "tests/TestFiles/labels.sfz";
|
||||
synth.loadSfzFile(path.string());
|
||||
const std::string xmlMidnam = synth.exportMidnam("");
|
||||
REQUIRE(xmlMidnam.find("<Note Number=\"12\" Name=\"Cymbals\" />") != xmlMidnam.npos);
|
||||
REQUIRE(xmlMidnam.find("<Note Number=\"65\" Name=\"Crash\" />") != xmlMidnam.npos);
|
||||
REQUIRE(xmlMidnam.find("<Control Type=\"7bit\" Number=\"54\" Name=\"Gain\" />") != xmlMidnam.npos);
|
||||
REQUIRE(xmlMidnam.find("<Control Type=\"7bit\" Number=\"2\" Name=\"Other\" />") != xmlMidnam.npos);
|
||||
}
|
||||
|
||||
TEST_CASE("[Bindings] Midnam C")
|
||||
{
|
||||
sfizz_synth_t* synth = sfizz_create_synth();
|
||||
const auto path = fs::current_path() / "tests/TestFiles/labels.sfz";
|
||||
const auto strPath = path.string();
|
||||
sfizz_load_file(synth, strPath.c_str());
|
||||
char* midnamChar = sfizz_export_midnam(synth, "");
|
||||
const std::string xmlMidnam = std::string(midnamChar);
|
||||
REQUIRE(xmlMidnam.find("<Note Number=\"12\" Name=\"Cymbals\" />") != xmlMidnam.npos);
|
||||
REQUIRE(xmlMidnam.find("<Note Number=\"65\" Name=\"Crash\" />") != xmlMidnam.npos);
|
||||
REQUIRE(xmlMidnam.find("<Control Type=\"7bit\" Number=\"54\" Name=\"Gain\" />") != xmlMidnam.npos);
|
||||
REQUIRE(xmlMidnam.find("<Control Type=\"7bit\" Number=\"2\" Name=\"Other\" />") != xmlMidnam.npos);
|
||||
sfizz_free_memory(midnamChar);
|
||||
sfizz_free(synth);
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ set(SFIZZ_TEST_SOURCES
|
|||
TestHelpers.h
|
||||
TestHelpers.cpp
|
||||
ParsingT.cpp
|
||||
BindingsT.cpp
|
||||
HelpersT.cpp
|
||||
HelpersT.cpp
|
||||
AudioBufferT.cpp
|
||||
|
|
@ -53,7 +54,7 @@ set(SFIZZ_TEST_SOURCES
|
|||
)
|
||||
|
||||
add_executable(sfizz_tests ${SFIZZ_TEST_SOURCES})
|
||||
target_link_libraries(sfizz_tests PRIVATE sfizz::internal sfizz::spin_mutex sfizz::jsl sfizz::filesystem)
|
||||
target_link_libraries(sfizz_tests PRIVATE sfizz::internal sfizz::static sfizz::spin_mutex sfizz::jsl sfizz::filesystem)
|
||||
sfizz_enable_lto_if_needed(sfizz_tests)
|
||||
sfizz_enable_fast_math(sfizz_tests)
|
||||
catch_discover_tests(sfizz_tests)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue