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.

76 lines
2.4KB

  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 <cstdlib>
  12. #include <cctype>
  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. std::cout << "* " << (int)apis[i] << ": '" << name << "'\n";
  26. }
  27. // ensure unknown APIs return the empty string
  28. {
  29. const std::string &name = RtAudio::getCompiledApiName((RtAudio::Api)-1);
  30. if (!name.empty()) {
  31. std::cerr << "Bad string for invalid API\n";
  32. exit(1);
  33. }
  34. }
  35. // try getting API identifier by case-insensitive name
  36. std::cout << "API identifiers by name:\n";
  37. for ( size_t i = 0; i < apis.size() ; ++i ) {
  38. std::string name = RtAudio::getCompiledApiName(apis[i]);
  39. if ( RtAudio::getCompiledApiByName(name) != apis[i] ) {
  40. std::cerr << "Bad identifier for API '" << name << "'\n";
  41. exit( 1 );
  42. }
  43. std::cout << "* '" << name << "': " << (int)apis[i] << "\n";
  44. for ( size_t j = 0; j < name.size(); ++j )
  45. name[j] = (j & 1) ? toupper(name[j]) : tolower(name[j]);
  46. if ( RtAudio::getCompiledApiByName(name) != apis[i] ) {
  47. std::cerr << "Bad identifier for API '" << name << "'\n";
  48. exit( 1 );
  49. }
  50. std::cout << "* '" << name << "': " << (int)apis[i] << "\n";
  51. }
  52. // try getting an API identifier by unknown name
  53. {
  54. RtAudio::Api api;
  55. api = RtAudio::getCompiledApiByName("ALSO");
  56. if ( api != RtAudio::UNSPECIFIED ) {
  57. std::cerr << "Bad identifier for unknown API name\n";
  58. exit( 1 );
  59. }
  60. api = RtAudio::getCompiledApiByName("");
  61. if ( api != RtAudio::UNSPECIFIED ) {
  62. std::cerr << "Bad identifier for unknown API name\n";
  63. exit( 1 );
  64. }
  65. }
  66. return 0;
  67. }