gtx_string_cast.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2011-09-01
  5. // Updated : 2011-09-01
  6. // Licence : This source is under MIT licence
  7. // File : test/gtx/string_cast.cpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include <glm/glm.hpp>
  10. #include <glm/gtx/string_cast.hpp>
  11. #include <iostream>
  12. #include <limits>
  13. int test_string_cast_scalar()
  14. {
  15. int Error = 0;
  16. glm::half A1(1.0);
  17. std::string A2 = glm::to_string(A1);
  18. Error += A2 != std::string("half(1.0000)") ? 1 : 0;
  19. float B1(1.0);
  20. std::string B2 = glm::to_string(B1);
  21. Error += B2 != std::string("float(1.000000)") ? 1 : 0;
  22. double C1(1.0);
  23. std::string C2 = glm::to_string(C1);
  24. Error += C2 != std::string("double(1.000000)") ? 1 : 0;
  25. return Error;
  26. }
  27. int test_string_cast_vector()
  28. {
  29. int Error = 0;
  30. glm::vec2 A1(1, 2);
  31. std::string A2 = glm::to_string(A1);
  32. Error += A2 != std::string("fvec2(1.000000, 2.000000)") ? 1 : 0;
  33. glm::vec3 B1(1, 2, 3);
  34. std::string B2 = glm::to_string(B1);
  35. Error += B2 != std::string("fvec3(1.000000, 2.000000, 3.000000)") ? 1 : 0;
  36. glm::vec4 C1(1, 2, 3, 4);
  37. std::string C2 = glm::to_string(C1);
  38. Error += C2 != std::string("fvec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0;
  39. glm::ivec2 D1(1, 2);
  40. std::string D2 = glm::to_string(D1);
  41. Error += D2 != std::string("ivec2(1, 2)") ? 1 : 0;
  42. glm::ivec3 E1(1, 2, 3);
  43. std::string E2 = glm::to_string(E1);
  44. Error += E2 != std::string("ivec3(1, 2, 3)") ? 1 : 0;
  45. glm::ivec4 F1(1, 2, 3, 4);
  46. std::string F2 = glm::to_string(F1);
  47. Error += F2 != std::string("ivec4(1, 2, 3, 4)") ? 1 : 0;
  48. glm::hvec2 G1(1, 2);
  49. std::string G2 = glm::to_string(G1);
  50. Error += G2 != std::string("hvec2(1.0000, 2.0000)") ? 1 : 0;
  51. glm::hvec3 H1(1, 2, 3);
  52. std::string H2 = glm::to_string(H1);
  53. Error += H2 != std::string("hvec3(1.0000, 2.0000, 3.0000)") ? 1 : 0;
  54. glm::hvec4 I1(1, 2, 3, 4);
  55. std::string I2 = glm::to_string(I1);
  56. Error += I2 != std::string("hvec4(1.0000, 2.0000, 3.0000, 4.0000)") ? 1 : 0;
  57. glm::dvec2 J1(1, 2);
  58. std::string J2 = glm::to_string(J1);
  59. Error += J2 != std::string("dvec2(1.000000, 2.000000)") ? 1 : 0;
  60. glm::dvec3 K1(1, 2, 3);
  61. std::string K2 = glm::to_string(K1);
  62. Error += K2 != std::string("dvec3(1.000000, 2.000000, 3.000000)") ? 1 : 0;
  63. glm::dvec4 L1(1, 2, 3, 4);
  64. std::string L2 = glm::to_string(L1);
  65. Error += L2 != std::string("dvec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0;
  66. return Error;
  67. }
  68. int test_string_cast_matrix()
  69. {
  70. int Error = 0;
  71. return Error;
  72. }
  73. int main()
  74. {
  75. int Error = 0;
  76. Error += test_string_cast_scalar();
  77. Error += test_string_cast_vector();
  78. Error += test_string_cast_matrix();
  79. return Error;
  80. }