Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

build.cpp 4.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include "core.h"
  14. #include "lol/unit.h"
  15. namespace lol
  16. {
  17. LOLUNIT_FIXTURE(BuildTest)
  18. {
  19. LOLUNIT_TEST(TypeSizeHalf)
  20. {
  21. LOLUNIT_ASSERT_EQUAL(sizeof(half), 2);
  22. LOLUNIT_ASSERT_EQUAL(sizeof(f16vec2), 4);
  23. LOLUNIT_ASSERT_EQUAL(sizeof(f16vec3), 6);
  24. LOLUNIT_ASSERT_EQUAL(sizeof(f16vec4), 8);
  25. LOLUNIT_ASSERT_EQUAL(sizeof(f16mat2), 8);
  26. LOLUNIT_ASSERT_EQUAL(sizeof(f16mat3), 18);
  27. LOLUNIT_ASSERT_EQUAL(sizeof(f16mat4), 32);
  28. }
  29. LOLUNIT_TEST(TypeSizeFloat)
  30. {
  31. LOLUNIT_ASSERT_EQUAL(sizeof(float), 4);
  32. LOLUNIT_ASSERT_EQUAL(sizeof(vec2), 8);
  33. LOLUNIT_ASSERT_EQUAL(sizeof(vec3), 12);
  34. LOLUNIT_ASSERT_EQUAL(sizeof(vec4), 16);
  35. LOLUNIT_ASSERT_EQUAL(sizeof(mat2), 16);
  36. LOLUNIT_ASSERT_EQUAL(sizeof(mat3), 36);
  37. LOLUNIT_ASSERT_EQUAL(sizeof(mat4), 64);
  38. }
  39. LOLUNIT_TEST(TypeSizeDouble)
  40. {
  41. LOLUNIT_ASSERT_EQUAL(sizeof(double), 8);
  42. LOLUNIT_ASSERT_EQUAL(sizeof(dvec2), 16);
  43. LOLUNIT_ASSERT_EQUAL(sizeof(dvec3), 24);
  44. LOLUNIT_ASSERT_EQUAL(sizeof(dvec4), 32);
  45. LOLUNIT_ASSERT_EQUAL(sizeof(dmat2), 32);
  46. LOLUNIT_ASSERT_EQUAL(sizeof(dmat3), 72);
  47. LOLUNIT_ASSERT_EQUAL(sizeof(dmat4), 128);
  48. }
  49. LOLUNIT_TEST(TypeSizeInt8)
  50. {
  51. LOLUNIT_ASSERT_EQUAL(sizeof(i8vec2), 2);
  52. LOLUNIT_ASSERT_EQUAL(sizeof(u8vec2), 2);
  53. LOLUNIT_ASSERT_EQUAL(sizeof(i8vec3), 3);
  54. LOLUNIT_ASSERT_EQUAL(sizeof(u8vec3), 3);
  55. LOLUNIT_ASSERT_EQUAL(sizeof(i8vec4), 4);
  56. LOLUNIT_ASSERT_EQUAL(sizeof(u8vec4), 4);
  57. LOLUNIT_ASSERT_EQUAL(sizeof(i8mat2), 4);
  58. LOLUNIT_ASSERT_EQUAL(sizeof(u8mat2), 4);
  59. LOLUNIT_ASSERT_EQUAL(sizeof(i8mat3), 9);
  60. LOLUNIT_ASSERT_EQUAL(sizeof(u8mat3), 9);
  61. LOLUNIT_ASSERT_EQUAL(sizeof(i8mat4), 16);
  62. LOLUNIT_ASSERT_EQUAL(sizeof(u8mat4), 16);
  63. }
  64. LOLUNIT_TEST(TypeSizeInt16)
  65. {
  66. LOLUNIT_ASSERT_EQUAL(sizeof(i16vec2), 4);
  67. LOLUNIT_ASSERT_EQUAL(sizeof(u16vec2), 4);
  68. LOLUNIT_ASSERT_EQUAL(sizeof(i16vec3), 6);
  69. LOLUNIT_ASSERT_EQUAL(sizeof(u16vec3), 6);
  70. LOLUNIT_ASSERT_EQUAL(sizeof(i16vec4), 8);
  71. LOLUNIT_ASSERT_EQUAL(sizeof(u16vec4), 8);
  72. LOLUNIT_ASSERT_EQUAL(sizeof(i16mat2), 8);
  73. LOLUNIT_ASSERT_EQUAL(sizeof(u16mat2), 8);
  74. LOLUNIT_ASSERT_EQUAL(sizeof(i16mat3), 18);
  75. LOLUNIT_ASSERT_EQUAL(sizeof(u16mat3), 18);
  76. LOLUNIT_ASSERT_EQUAL(sizeof(i16mat4), 32);
  77. LOLUNIT_ASSERT_EQUAL(sizeof(u16mat4), 32);
  78. }
  79. LOLUNIT_TEST(TypeSizeInt32)
  80. {
  81. LOLUNIT_ASSERT_EQUAL(sizeof(ivec2), 8);
  82. LOLUNIT_ASSERT_EQUAL(sizeof(uvec2), 8);
  83. LOLUNIT_ASSERT_EQUAL(sizeof(ivec3), 12);
  84. LOLUNIT_ASSERT_EQUAL(sizeof(uvec3), 12);
  85. LOLUNIT_ASSERT_EQUAL(sizeof(ivec4), 16);
  86. LOLUNIT_ASSERT_EQUAL(sizeof(uvec4), 16);
  87. LOLUNIT_ASSERT_EQUAL(sizeof(imat2), 16);
  88. LOLUNIT_ASSERT_EQUAL(sizeof(umat2), 16);
  89. LOLUNIT_ASSERT_EQUAL(sizeof(imat3), 36);
  90. LOLUNIT_ASSERT_EQUAL(sizeof(umat3), 36);
  91. LOLUNIT_ASSERT_EQUAL(sizeof(imat4), 64);
  92. LOLUNIT_ASSERT_EQUAL(sizeof(umat4), 64);
  93. }
  94. LOLUNIT_TEST(TypeSizeInt64)
  95. {
  96. LOLUNIT_ASSERT_EQUAL(sizeof(i64vec2), 16);
  97. LOLUNIT_ASSERT_EQUAL(sizeof(u64vec2), 16);
  98. LOLUNIT_ASSERT_EQUAL(sizeof(i64vec3), 24);
  99. LOLUNIT_ASSERT_EQUAL(sizeof(u64vec3), 24);
  100. LOLUNIT_ASSERT_EQUAL(sizeof(i64vec4), 32);
  101. LOLUNIT_ASSERT_EQUAL(sizeof(u64vec4), 32);
  102. LOLUNIT_ASSERT_EQUAL(sizeof(i64mat2), 32);
  103. LOLUNIT_ASSERT_EQUAL(sizeof(u64mat2), 32);
  104. LOLUNIT_ASSERT_EQUAL(sizeof(i64mat3), 72);
  105. LOLUNIT_ASSERT_EQUAL(sizeof(u64mat3), 72);
  106. LOLUNIT_ASSERT_EQUAL(sizeof(i64mat4), 128);
  107. LOLUNIT_ASSERT_EQUAL(sizeof(u64mat4), 128);
  108. }
  109. #if !defined LOL_DEBUG
  110. LOLUNIT_TEST(FastMath)
  111. {
  112. double x, y;
  113. y = x = 1.0 + RandF(0.1f, 0.2f);
  114. y += 4503599627370496.0;
  115. /* The compiler should optimise this away */
  116. y -= 4503599627370496.0;
  117. LOLUNIT_ASSERT_EQUAL(x, y);
  118. }
  119. #endif
  120. LOLUNIT_TEST(FastMathOverride)
  121. {
  122. double x, y;
  123. y = x = 1.0 + RandF(0.1f, 0.2f);
  124. y += 4503599627370496.0;
  125. FP_USE(y);
  126. /* The compiler should not optimise this away */
  127. y -= 4503599627370496.0;
  128. LOLUNIT_ASSERT_EQUAL(1.0, y);
  129. }
  130. LOLUNIT_TEST(IsNaN)
  131. {
  132. union { float f; uint32_t x; } u;
  133. u.x = 0x7fc00000u;
  134. LOLUNIT_ASSERT(isnan(u.f));
  135. }
  136. };
  137. } /* namespace lol */