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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 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.isNotEmpty());
  27. assert(! str.contains("-"));
  28. assert(! str.isDigit(0));
  29. // single number
  30. str = "5";
  31. assert(str.length() == 1);
  32. assert(str.length() == std::strlen("5"));
  33. assert(str.isNotEmpty());
  34. assert(str.contains(""));
  35. assert(str.contains("5"));
  36. assert(str.isDigit(0));
  37. assert(! str.isEmpty());
  38. assert(! str.contains("6"));
  39. assert(! str.isDigit(1));
  40. // single number, using constructor
  41. str = CarlaString(5);
  42. assert(str.length() == 1);
  43. assert(str.length() == std::strlen("5"));
  44. assert(str.isNotEmpty());
  45. assert(str.contains(""));
  46. assert(str.contains("5"));
  47. assert(str.isDigit(0));
  48. assert(! str.isEmpty());
  49. assert(! str.contains("6"));
  50. assert(! str.isDigit(1));
  51. // decimal number
  52. str = CarlaString(51);
  53. assert(str.length() == 2);
  54. assert(str.length() == std::strlen("51"));
  55. assert(str.isNotEmpty());
  56. assert(str.contains(""));
  57. assert(str.contains("1"));
  58. assert(str.contains("51"));
  59. assert(str.isDigit(0));
  60. assert(str.isDigit(1));
  61. assert(! str.isEmpty());
  62. assert(! str.contains("6"));
  63. assert(! str.isDigit(2));
  64. assert(! str.isDigit(-1));
  65. // negative number
  66. str = CarlaString(-51);
  67. assert(str.length() == 3);
  68. assert(str.length() == std::strlen("-51"));
  69. assert(str.isNotEmpty());
  70. assert(str.contains(""));
  71. assert(str.contains("-5"));
  72. assert(str.contains("51"));
  73. assert(str.isDigit(1));
  74. assert(str.isDigit(2));
  75. assert(! str.isEmpty());
  76. assert(! str.contains("6"));
  77. assert(! str.isDigit(0));
  78. assert(! str.isDigit(-1));
  79. // small operations
  80. str += "ah";
  81. assert(str.length() == 5);
  82. assert(str.length() == std::strlen("-51ah"));
  83. assert(str.contains("-51ah"));
  84. assert(! str.isDigit(3));
  85. // hexacimal number
  86. unsigned int n = 0x91;
  87. str += CarlaString(n, true);
  88. assert(str.length() == 9);
  89. assert(str.length() == std::strlen("-51ah0x91"));
  90. assert(str.contains("-51ah0x91"));
  91. assert(! str.isDigit(6));
  92. // float number
  93. str += CarlaString(0.0102f);
  94. assert(str.length() == 17);
  95. assert(str.length() == std::strlen("-51ah0x910.010200"));
  96. assert(str.contains("-51ah0x91"));
  97. assert(! str.isDigit(6));
  98. // double number
  99. str += CarlaString(7.9642);
  100. assert(str.length() == 23);
  101. assert(str.length() == std::strlen("-51ah0x910.0102007.9642"));
  102. assert(str.contains("7.9642"));
  103. // replace
  104. str.replace('0', 'k');
  105. str.replace('k', 'O');
  106. str.replace('O', '0');
  107. str.replace('0', '\0'); // shouldn't do anything
  108. // truncate
  109. str.truncate(11);
  110. assert(str.length() == 11);
  111. assert(str.length() == std::strlen("-51ah0x910."));
  112. // basic
  113. str.toBasic();
  114. assert(str.length() == 11);
  115. assert(str == "_51ah0x910_");
  116. // upper
  117. str.toUpper();
  118. assert(str.length() == 11);
  119. assert(str == "_51AH0X910_");
  120. // lower
  121. str.toLower();
  122. assert(str.length() == 11);
  123. assert(str == "_51ah0x910_");
  124. // random stuff
  125. CarlaString str1(1.23);
  126. str1 += "_ ?";
  127. CarlaString str2("test1");
  128. str2 = "test2";
  129. str2 += ".0";
  130. CarlaString str3("1.23_ ?test2.0 final");
  131. CarlaString str4 = "" + str1 + str2 + " final";
  132. assert(str3 == "1.23_ ?test2.0 final");
  133. assert(str3 == str4);
  134. assert(str3.length() == str4.length());
  135. assert(str3.length() == std::strlen("1.23_ ?test2.0 final"));
  136. CarlaString str5 = "ola " + str + " " + CarlaString(6);
  137. assert(str5 == "ola _51ah0x910_ 6");
  138. assert(str5.length() == std::strlen("ola _51ah0x910_ 6"));
  139. printf("FINAL: \"%s\"\n", (const char*)str5);
  140. // clear
  141. str.clear();
  142. assert(str.length() == 0);
  143. assert(str.length() == std::strlen(""));
  144. assert(str == "");
  145. return 0;
  146. }