diff options
| author | JP Cimalando <jp-dev@inbox.ru> | 2018-05-07 17:30:27 +0200 |
|---|---|---|
| committer | JP Cimalando <jp-dev@inbox.ru> | 2018-05-07 19:20:23 +0200 |
| commit | f7b624ba819036b9ebfb3f4d0517fd45e01919b2 (patch) | |
| tree | 5f31ce4d7ec0b8f6c90a85a3de0e533691d94104 /tests | |
| parent | 4a7ca4f1d42fff04eb085d85a3b298df2c937a34 (diff) | |
API names, and conversion from/to API identifier
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | tests/Makefile.am | 5 | ||||
| -rw-r--r-- | tests/apinames.cpp | 75 |
3 files changed, 82 insertions, 1 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0fb028f..f611d51 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,6 +18,9 @@ target_link_libraries(record rtaudio_static ${LINKLIBS}) add_executable(duplex duplex.cpp) target_link_libraries(duplex rtaudio_static ${LINKLIBS}) +add_executable(apinames apinames.cpp) +target_link_libraries(apinames rtaudio_static ${LINKLIBS}) + add_executable(testall testall.cpp) target_link_libraries(testall rtaudio_static ${LINKLIBS}) diff --git a/tests/Makefile.am b/tests/Makefile.am index e39fdde..c8159da 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,5 @@ -noinst_PROGRAMS = audioprobe playsaw playraw record duplex testall teststops +noinst_PROGRAMS = audioprobe playsaw playraw record duplex apinames testall teststops AM_CXXFLAGS = -Wall -I$(top_srcdir) @@ -18,6 +18,9 @@ record_LDADD = $(top_builddir)/librtaudio.la duplex_SOURCES = duplex.cpp duplex_LDADD = $(top_builddir)/librtaudio.la +apinames_SOURCES = apinames.cpp +apinames_LDADD = $(top_builddir)/librtaudio.la + testall_SOURCES = testall.cpp testall_LDADD = $(top_builddir)/librtaudio.la diff --git a/tests/apinames.cpp b/tests/apinames.cpp new file mode 100644 index 0000000..b915ad0 --- /dev/null +++ b/tests/apinames.cpp @@ -0,0 +1,75 @@ +/******************************************/ +/* + apinames.cpp + by Jean Pierre Cimalando, 2018. + + This program tests parts of RtAudio related + to API names, the conversion from name to API + and vice-versa. +*/ +/******************************************/ + +#include "RtAudio.h" +#include <cstdlib> +#include <cctype> +#include <iostream> + +int main() { + std::vector<RtAudio::Api> apis; + RtAudio::getCompiledApi( apis ); + + // ensure the known APIs return valid names + std::cout << "API names by identifier:\n"; + for ( size_t i = 0; i < apis.size() ; ++i ) { + const std::string &name = RtAudio::getCompiledApiName(apis[i]); + if (name.empty()) { + std::cerr << "Invalid name for API " << (int)apis[i] << "\n"; + exit(1); + } + std::cout << "* " << (int)apis[i] << ": '" << name << "'\n"; + } + + // ensure unknown APIs return the empty string + { + const std::string &name = RtAudio::getCompiledApiName((RtAudio::Api)-1); + if (!name.empty()) { + std::cerr << "Bad string for invalid API\n"; + exit(1); + } + } + + // try getting API identifier by case-insensitive name + std::cout << "API identifiers by name:\n"; + for ( size_t i = 0; i < apis.size() ; ++i ) { + std::string name = RtAudio::getCompiledApiName(apis[i]); + if ( RtAudio::getCompiledApiByName(name) != apis[i] ) { + std::cerr << "Bad identifier for API '" << name << "'\n"; + exit( 1 ); + } + std::cout << "* '" << name << "': " << (int)apis[i] << "\n"; + for ( size_t j = 0; j < name.size(); ++j ) + name[j] = (j & 1) ? toupper(name[j]) : tolower(name[j]); + if ( RtAudio::getCompiledApiByName(name) != apis[i] ) { + std::cerr << "Bad identifier for API '" << name << "'\n"; + exit( 1 ); + } + std::cout << "* '" << name << "': " << (int)apis[i] << "\n"; + } + + // try getting an API identifier by unknown name + { + RtAudio::Api api; + api = RtAudio::getCompiledApiByName("ALSO"); + if ( api != RtAudio::UNSPECIFIED ) { + std::cerr << "Bad identifier for unknown API name\n"; + exit( 1 ); + } + api = RtAudio::getCompiledApiByName(""); + if ( api != RtAudio::UNSPECIFIED ) { + std::cerr << "Bad identifier for unknown API name\n"; + exit( 1 ); + } + } + + return 0; +} |
