Audio plugin host https://kx.studio/carla
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.

CarlaString.cpp 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Carla Tests
  3. * Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "CarlaString.hpp"
  18. int main()
  19. {
  20. CarlaString str;
  21. // empty
  22. assert(str.length() == 0);
  23. assert(str.length() == std::strlen(""));
  24. assert(str.isEmpty());
  25. assert(str.contains(""));
  26. assert(str.contains("\0"));
  27. assert(! str.isNotEmpty());
  28. assert(! str.contains(" "));
  29. assert(! str.isDigit(0));
  30. // single number
  31. str = "5";
  32. assert(str.length() == 1);
  33. assert(str.length() == std::strlen("5"));
  34. assert(str.isNotEmpty());
  35. assert(str.contains(""));
  36. assert(str.contains("5"));
  37. assert(str.isDigit(0));
  38. assert(! str.isEmpty());
  39. assert(! str.contains("6"));
  40. assert(! str.isDigit(1));
  41. // single number, using constructor
  42. str = CarlaString(5);
  43. assert(str.length() == 1);
  44. assert(str.length() == std::strlen("5"));
  45. assert(str.isNotEmpty());
  46. assert(str.contains(""));
  47. assert(str.contains("5"));
  48. assert(str.isDigit(0));
  49. assert(! str.isEmpty());
  50. assert(! str.contains("6"));
  51. assert(! str.isDigit(1));
  52. // decimal number
  53. str = CarlaString(51);
  54. assert(str.length() == 2);
  55. assert(str.length() == std::strlen("51"));
  56. assert(str.isNotEmpty());
  57. assert(str.contains(""));
  58. assert(str.contains("1"));
  59. assert(str.contains("51"));
  60. assert(str.isDigit(0));
  61. assert(str.isDigit(1));
  62. assert(! str.isEmpty());
  63. assert(! str.contains("6"));
  64. assert(! str.isDigit(2));
  65. assert(! str.isDigit(-1));
  66. // negative number
  67. str = CarlaString(-51);
  68. assert(str.length() == 3);
  69. assert(str.length() == std::strlen("-51"));
  70. assert(str.isNotEmpty());
  71. assert(str.contains(""));
  72. assert(str.contains("-5"));
  73. assert(str.contains("51"));
  74. assert(str.isDigit(1));
  75. assert(str.isDigit(2));
  76. assert(! str.isEmpty());
  77. assert(! str.contains("6"));
  78. assert(! str.isDigit(0));
  79. assert(! str.isDigit(-1));
  80. // small operations
  81. str += "ah";
  82. assert(str.length() == 5);
  83. assert(str.length() == std::strlen("-51ah"));
  84. assert(str.contains("-51ah"));
  85. assert(! str.isDigit(3));
  86. // hexacimal number
  87. unsigned int n = 0x91;
  88. str += CarlaString(n, true);
  89. assert(str.length() == 9);
  90. assert(str.length() == std::strlen("-51ah0x91"));
  91. assert(str.contains("-51ah0x91"));
  92. assert(! str.isDigit(6));
  93. // float number
  94. str += CarlaString(0.0102f);
  95. assert(str.length() == 17);
  96. assert(str.length() == std::strlen("-51ah0x910.010200"));
  97. assert(str.contains("-51ah0x91"));
  98. assert(! str.isDigit(6));
  99. // double number
  100. str += CarlaString(7.9642);
  101. assert(str.length() == 23);
  102. assert(str.length() == std::strlen("-51ah0x910.0102007.9642"));
  103. assert(str.contains("7.9642"));
  104. // replace
  105. str.replace('0', 'k');
  106. str.replace('k', 'O');
  107. str.replace('O', '0');
  108. str.replace('0', '\0'); // shouldn't do anything
  109. // truncate
  110. str.truncate(11);
  111. assert(str.length() == 11);
  112. assert(str.length() == std::strlen("-51ah0x910."));
  113. // basic
  114. str.toBasic();
  115. assert(str.length() == 11);
  116. assert(str == "_51ah0x910_");
  117. // upper
  118. str.toUpper();
  119. assert(str.length() == 11);
  120. assert(str == "_51AH0X910_");
  121. // lower
  122. str.toLower();
  123. assert(str.length() == 11);
  124. assert(str == "_51ah0x910_");
  125. // random stuff
  126. CarlaString str1(1.23);
  127. str1 += "_ ?";
  128. CarlaString str2("test1");
  129. str2 = "test2";
  130. str2 += ".0";
  131. CarlaString str3("1.23_ ?test2.0 final");
  132. CarlaString str4 = "" + str1 + str2 + " final";
  133. assert(str3 == "1.23_ ?test2.0 final");
  134. assert(str3 == str4);
  135. assert(str3.length() == str4.length());
  136. assert(str3.length() == std::strlen("1.23_ ?test2.0 final"));
  137. CarlaString str5 = "ola " + str + " " + CarlaString(6);
  138. assert(str5 == "ola _51ah0x910_ 6");
  139. assert(str5.length() == std::strlen("ola _51ah0x910_ 6"));
  140. printf("FINAL: \"%s\"\n", (const char*)str5);
  141. // clear
  142. str.clear();
  143. assert(str.length() == 0);
  144. assert(str.length() == std::strlen(""));
  145. assert(str == "");
  146. return 0;
  147. }