FitsInTest.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2013 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "include/core/SkTypes.h"
  8. #include "include/private/SkTFitsIn.h"
  9. #include "tests/Test.h"
  10. #include <limits>
  11. #define TEST(S, s, D, expected) REPORTER_ASSERT(reporter, (SkTFitsIn<D>((S)(s)) == (expected)))
  12. enum TestEnum_t : uint8_t {
  13. kFoo,
  14. kBar,
  15. kBaz,
  16. };
  17. DEF_TEST(FitsIn, reporter) {
  18. TEST(uint16_t, 257, int8_t, false);
  19. TEST(int32_t, 1, int8_t, true);
  20. TEST(int32_t, -1, int8_t, true);
  21. TEST(int32_t, (int32_t)(std::numeric_limits<int8_t>::max)(), int8_t, true);
  22. TEST(int32_t, ((int32_t)(std::numeric_limits<int8_t>::max)())+1, int8_t, false);
  23. TEST(int32_t, (int32_t)(std::numeric_limits<int8_t>::min)(), int8_t, true);
  24. TEST(int32_t, (int32_t)((std::numeric_limits<int8_t>::min)())-1, int8_t, false);
  25. TEST(int32_t, 1, uint8_t, true);
  26. TEST(int32_t, -1, uint8_t, false);
  27. TEST(int32_t, (int32_t)(std::numeric_limits<uint8_t>::max)(), uint8_t, true);
  28. TEST(int32_t, ((int32_t)(std::numeric_limits<uint8_t>::max)())+1, uint8_t, false);
  29. TEST(int32_t, 0, uint8_t, true);
  30. TEST(int32_t, -1, uint8_t, false);
  31. TEST(int32_t, -127, uint8_t, false);
  32. TEST(int32_t, -128, uint8_t, false);
  33. TEST(uint8_t, 2, TestEnum_t, true);
  34. TEST(TestEnum_t, kBar, uint8_t, true);
  35. TEST(int32_t, 1000, int8_t, false);
  36. TEST(int32_t, 1000, uint8_t, false);
  37. TEST(int32_t, 1, int32_t, true);
  38. TEST(int32_t, -1, int32_t, true);
  39. TEST(int32_t, 1, uint32_t, true);
  40. TEST(int32_t, -1, uint32_t, false);
  41. TEST(int32_t, 1, int64_t, true);
  42. TEST(int32_t, -1, int64_t, true);
  43. TEST(int32_t, 1, uint64_t, true);
  44. TEST(int32_t, -1, uint64_t, false);
  45. TEST(uint32_t, 1, int8_t, true);
  46. TEST(uint32_t, 1, uint8_t, true);
  47. TEST(uint32_t, 1, int32_t, true);
  48. TEST(uint32_t, 1, uint32_t, true);
  49. TEST(uint32_t, 1, int64_t, true);
  50. TEST(uint32_t, 1, uint64_t, true);
  51. TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int8_t, false);
  52. TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint8_t, false);
  53. TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int32_t, false);
  54. TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint32_t, true);
  55. TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), int64_t, true);
  56. TEST(uint32_t, (std::numeric_limits<uint32_t>::max)(), uint64_t, true);
  57. TEST(uint64_t, 1, int8_t, true);
  58. TEST(uint64_t, 1, uint8_t, true);
  59. TEST(uint64_t, 1, int32_t, true);
  60. TEST(uint64_t, 1, uint32_t, true);
  61. TEST(uint64_t, 1, int64_t, true);
  62. TEST(uint64_t, 1, uint64_t, true);
  63. // Uncommenting the following should cause compile failures.
  64. //TEST(float, 1, uint64_t, true);
  65. }