You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.6KB

  1. /******************************************/
  2. /*
  3. apinames.cpp
  4. by Jean Pierre Cimalando, 2018.
  5. This program tests parts of RtAudio related
  6. to API names, the conversion from name to API
  7. and vice-versa.
  8. */
  9. /******************************************/
  10. #include "RtAudio.h"
  11. #include <cctype>
  12. #include <cstdlib>
  13. #include <iostream>
  14. int main() {
  15. std::vector<RtAudio::Api> apis;
  16. RtAudio::getCompiledApi( apis );
  17. // ensure the known APIs return valid names
  18. std::cout << "API names by identifier:\n";
  19. for ( size_t i = 0; i < apis.size() ; ++i ) {
  20. const std::string &name = RtAudio::getCompiledApiName(apis[i]);
  21. if (name.empty()) {
  22. std::cerr << "Invalid name for API " << (int)apis[i] << "\n";
  23. exit(1);
  24. }
  25. const std::string &displayName = RtAudio::getCompiledApiDisplayName(apis[i]);
  26. if (displayName.empty()) {
  27. std::cerr << "Invalid display name for API " << (int)apis[i] << "\n";
  28. exit(1);
  29. }
  30. std::cout << "* " << (int)apis[i] << " '" << name << "': '" << displayName << "'\n";
  31. }
  32. // ensure unknown APIs return the empty string
  33. {
  34. const std::string &name = RtAudio::getCompiledApiName((RtAudio::Api)-1);
  35. if (!name.empty()) {
  36. std::cerr << "Bad string for invalid API\n";
  37. exit(1);
  38. }
  39. const std::string &displayName = RtAudio::getCompiledApiDisplayName((RtAudio::Api)-1);
  40. if (!displayName.empty()) {
  41. std::cerr << "Bad display string for invalid API\n";
  42. exit(1);
  43. }
  44. }
  45. // try getting API identifier by name
  46. std::cout << "API identifiers by name:\n";
  47. for ( size_t i = 0; i < apis.size() ; ++i ) {
  48. std::string name = RtAudio::getCompiledApiName(apis[i]);
  49. if ( RtAudio::getCompiledApiByName(name) != apis[i] ) {
  50. std::cerr << "Bad identifier for API '" << name << "'\n";
  51. exit( 1 );
  52. }
  53. std::cout << "* '" << name << "': " << (int)apis[i] << "\n";
  54. for ( size_t j = 0; j < name.size(); ++j )
  55. name[j] = (j & 1) ? toupper(name[j]) : tolower(name[j]);
  56. RtAudio::Api api = RtAudio::getCompiledApiByName(name);
  57. if ( api != RtAudio::UNSPECIFIED ) {
  58. std::cerr << "Identifier " << (int)api << " for invalid API '" << name << "'\n";
  59. exit( 1 );
  60. }
  61. }
  62. // try getting an API identifier by unknown name
  63. {
  64. RtAudio::Api api;
  65. api = RtAudio::getCompiledApiByName("");
  66. if ( api != RtAudio::UNSPECIFIED ) {
  67. std::cerr << "Bad identifier for unknown API name\n";
  68. exit( 1 );
  69. }
  70. }
  71. return 0;
  72. }