summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStephen Sinclair <radarsat1@gmail.com>2018-10-16 15:01:30 +0200
committerStephen Sinclair <radarsat1@gmail.com>2018-10-16 15:01:30 +0200
commit4690b26068191afa44dc8a872e250990acb1d175 (patch)
tree0b6b1e4d752315423590e134f72e844760601540 /tests
parent154627e9e314bc99d5f29a1675bdbd7a7c80c612 (diff)
parent6919d3578769202957d1ba320ff458e959935e05 (diff)
Merge remote-tracking branch 'upstream/pr/136'
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/Makefile.am5
-rw-r--r--tests/apinames.cpp157
3 files changed, 164 insertions, 1 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 5c08f6d..5847027 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -20,6 +20,9 @@ target_link_libraries(record ${LIBRTAUDIO} ${LINKLIBS})
add_executable(duplex duplex.cpp)
target_link_libraries(duplex ${LIBRTAUDIO} ${LINKLIBS})
+add_executable(apinames apinames.cpp)
+target_link_libraries(apinames ${LIBRTAUDIO} ${LINKLIBS})
+
add_executable(testall testall.cpp)
target_link_libraries(testall ${LIBRTAUDIO} ${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..c270764
--- /dev/null
+++ b/tests/apinames.cpp
@@ -0,0 +1,157 @@
+/******************************************/
+/*
+ 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 <cctype>
+#include <cstdlib>
+#include <iostream>
+
+int test_cpp() {
+ std::vector<RtAudio::Api> apis;
+ RtAudio::getCompiledApi( apis );
+
+ // ensure the known APIs return valid names
+ std::cout << "API names by identifier (C++):\n";
+ for ( size_t i = 0; i < apis.size() ; ++i ) {
+ const std::string name = RtAudio::getApiName(apis[i]);
+ if (name.empty()) {
+ std::cout << "Invalid name for API " << (int)apis[i] << "\n";
+ exit(1);
+ }
+ const std::string displayName = RtAudio::getApiDisplayName(apis[i]);
+ if (displayName.empty()) {
+ std::cout << "Invalid display name for API " << (int)apis[i] << "\n";
+ exit(1);
+ }
+ std::cout << "* " << (int)apis[i] << " '" << name << "': '" << displayName << "'\n";
+ }
+
+ // ensure unknown APIs return the empty string
+ {
+ const std::string name = RtAudio::getApiName((RtAudio::Api)-1);
+ if (!name.empty()) {
+ std::cout << "Bad string for invalid API '" << name << "'\n";
+ exit(1);
+ }
+ const std::string displayName = RtAudio::getApiDisplayName((RtAudio::Api)-1);
+ if (displayName!="Unknown") {
+ std::cout << "Bad display string for invalid API '" << displayName << "'\n";
+ exit(1);
+ }
+ }
+
+ // try getting API identifier by name
+ std::cout << "API identifiers by name (C++):\n";
+ for ( size_t i = 0; i < apis.size() ; ++i ) {
+ std::string name = RtAudio::getApiName(apis[i]);
+ if ( RtAudio::getCompiledApiByName(name) != apis[i] ) {
+ std::cout << "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]);
+ RtAudio::Api api = RtAudio::getCompiledApiByName(name);
+ if ( api != RtAudio::UNSPECIFIED ) {
+ std::cout << "Identifier " << (int)api << " for invalid API '" << name << "'\n";
+ exit( 1 );
+ }
+ }
+
+ // try getting an API identifier by unknown name
+ {
+ RtAudio::Api api;
+ api = RtAudio::getCompiledApiByName("");
+ if ( api != RtAudio::UNSPECIFIED ) {
+ std::cout << "Bad identifier for unknown API name\n";
+ exit( 1 );
+ }
+ }
+
+ return 0;
+}
+
+#include "rtaudio_c.h"
+
+int test_c() {
+ const rtaudio_api_t *apis = rtaudio_compiled_api();
+
+ // ensure the known APIs return valid names
+ std::cout << "API names by identifier (C):\n";
+ for ( size_t i = 0; apis[i] != RTAUDIO_API_UNSPECIFIED; ++i) {
+ const std::string name = rtaudio_api_name(apis[i]);
+ if (name.empty()) {
+ std::cout << "Invalid name for API " << (int)apis[i] << "\n";
+ exit(1);
+ }
+ const std::string displayName = rtaudio_api_display_name(apis[i]);
+ if (displayName.empty()) {
+ std::cout << "Invalid display name for API " << (int)apis[i] << "\n";
+ exit(1);
+ }
+ std::cout << "* " << (int)apis[i] << " '" << name << "': '" << displayName << "'\n";
+ }
+
+ // ensure unknown APIs return the empty string
+ {
+ const char *s = rtaudio_api_name((rtaudio_api_t)-1);
+ const std::string name(s?s:"");
+ if (!name.empty()) {
+ std::cout << "Bad string for invalid API '" << name << "'\n";
+ exit(1);
+ }
+ s = rtaudio_api_display_name((rtaudio_api_t)-1);
+ const std::string displayName(s?s:"");
+ if (displayName!="Unknown") {
+ std::cout << "Bad display string for invalid API '" << displayName << "'\n";
+ exit(1);
+ }
+ }
+
+ // try getting API identifier by name
+ std::cout << "API identifiers by name (C):\n";
+ for ( size_t i = 0; apis[i] != RTAUDIO_API_UNSPECIFIED ; ++i ) {
+ const char *s = rtaudio_api_name(apis[i]);
+ std::string name(s?s:"");
+ if ( rtaudio_compiled_api_by_name(name.c_str()) != apis[i] ) {
+ std::cout << "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]);
+ rtaudio_api_t api = rtaudio_compiled_api_by_name(name.c_str());
+ if ( api != RTAUDIO_API_UNSPECIFIED ) {
+ std::cout << "Identifier " << (int)api << " for invalid API '" << name << "'\n";
+ exit( 1 );
+ }
+ }
+
+ // try getting an API identifier by unknown name
+ {
+ rtaudio_api_t api;
+ api = rtaudio_compiled_api_by_name("");
+ if ( api != RTAUDIO_API_UNSPECIFIED ) {
+ std::cout << "Bad identifier for unknown API name\n";
+ exit( 1 );
+ }
+ }
+
+ return 0;
+}
+
+int main()
+{
+ test_cpp();
+ test_c();
+}