gtx_string_cast.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// Restrictions:
  16. /// By making use of the Software for military purposes, you choose to make
  17. /// a Bunny unhappy.
  18. ///
  19. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. /// THE SOFTWARE.
  26. ///
  27. /// @file test/gtx/gtx_string_cast.cpp
  28. /// @date 2011-09-01 / 2014-11-25
  29. /// @author Christophe Riccio
  30. ///////////////////////////////////////////////////////////////////////////////////
  31. #include <glm/glm.hpp>
  32. #include <glm/gtx/string_cast.hpp>
  33. #include <limits>
  34. int test_string_cast_vector()
  35. {
  36. int Error = 0;
  37. {
  38. glm::vec2 A1(1, 2);
  39. std::string A2 = glm::to_string(A1);
  40. Error += A2 != std::string("vec2(1.000000, 2.000000)") ? 1 : 0;
  41. glm::vec3 B1(1, 2, 3);
  42. std::string B2 = glm::to_string(B1);
  43. Error += B2 != std::string("vec3(1.000000, 2.000000, 3.000000)") ? 1 : 0;
  44. glm::vec4 C1(1, 2, 3, 4);
  45. std::string C2 = glm::to_string(C1);
  46. Error += C2 != std::string("vec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0;
  47. glm::dvec2 J1(1, 2);
  48. std::string J2 = glm::to_string(J1);
  49. Error += J2 != std::string("dvec2(1.000000, 2.000000)") ? 1 : 0;
  50. glm::dvec3 K1(1, 2, 3);
  51. std::string K2 = glm::to_string(K1);
  52. Error += K2 != std::string("dvec3(1.000000, 2.000000, 3.000000)") ? 1 : 0;
  53. glm::dvec4 L1(1, 2, 3, 4);
  54. std::string L2 = glm::to_string(L1);
  55. Error += L2 != std::string("dvec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0;
  56. }
  57. {
  58. glm::bvec2 M1(false, true);
  59. std::string M2 = glm::to_string(M1);
  60. Error += M2 != std::string("bvec2(false, true)") ? 1 : 0;
  61. glm::bvec3 O1(false, true, false);
  62. std::string O2 = glm::to_string(O1);
  63. Error += O2 != std::string("bvec3(false, true, false)") ? 1 : 0;
  64. glm::bvec4 P1(false, true, false, true);
  65. std::string P2 = glm::to_string(P1);
  66. Error += P2 != std::string("bvec4(false, true, false, true)") ? 1 : 0;
  67. }
  68. {
  69. glm::ivec2 D1(1, 2);
  70. std::string D2 = glm::to_string(D1);
  71. Error += D2 != std::string("ivec2(1, 2)") ? 1 : 0;
  72. glm::ivec3 E1(1, 2, 3);
  73. std::string E2 = glm::to_string(E1);
  74. Error += E2 != std::string("ivec3(1, 2, 3)") ? 1 : 0;
  75. glm::ivec4 F1(1, 2, 3, 4);
  76. std::string F2 = glm::to_string(F1);
  77. Error += F2 != std::string("ivec4(1, 2, 3, 4)") ? 1 : 0;
  78. }
  79. {
  80. glm::i8vec2 D1(1, 2);
  81. std::string D2 = glm::to_string(D1);
  82. Error += D2 != std::string("i8vec2(1, 2)") ? 1 : 0;
  83. glm::i8vec3 E1(1, 2, 3);
  84. std::string E2 = glm::to_string(E1);
  85. Error += E2 != std::string("i8vec3(1, 2, 3)") ? 1 : 0;
  86. glm::i8vec4 F1(1, 2, 3, 4);
  87. std::string F2 = glm::to_string(F1);
  88. Error += F2 != std::string("i8vec4(1, 2, 3, 4)") ? 1 : 0;
  89. }
  90. {
  91. glm::i16vec2 D1(1, 2);
  92. std::string D2 = glm::to_string(D1);
  93. Error += D2 != std::string("i16vec2(1, 2)") ? 1 : 0;
  94. glm::i16vec3 E1(1, 2, 3);
  95. std::string E2 = glm::to_string(E1);
  96. Error += E2 != std::string("i16vec3(1, 2, 3)") ? 1 : 0;
  97. glm::i16vec4 F1(1, 2, 3, 4);
  98. std::string F2 = glm::to_string(F1);
  99. Error += F2 != std::string("i16vec4(1, 2, 3, 4)") ? 1 : 0;
  100. }
  101. {
  102. glm::i64vec2 D1(1, 2);
  103. std::string D2 = glm::to_string(D1);
  104. Error += D2 != std::string("i64vec2(1, 2)") ? 1 : 0;
  105. glm::i64vec3 E1(1, 2, 3);
  106. std::string E2 = glm::to_string(E1);
  107. Error += E2 != std::string("i64vec3(1, 2, 3)") ? 1 : 0;
  108. glm::i64vec4 F1(1, 2, 3, 4);
  109. std::string F2 = glm::to_string(F1);
  110. Error += F2 != std::string("i64vec4(1, 2, 3, 4)") ? 1 : 0;
  111. }
  112. return Error;
  113. }
  114. int test_string_cast_matrix()
  115. {
  116. int Error = 0;
  117. glm::mat2x2 A1(1.000000, 2.000000, 3.000000, 4.000000);
  118. std::string A2 = glm::to_string(A1);
  119. Error += A2 != std::string("mat2x2((1.000000, 2.000000), (3.000000, 4.000000))") ? 1 : 0;
  120. return Error;
  121. }
  122. int main()
  123. {
  124. int Error = 0;
  125. Error += test_string_cast_vector();
  126. Error += test_string_cast_matrix();
  127. return Error;
  128. }