arraysize_unsafe_test.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2016 The Crashpad Authors. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "util/misc/arraysize_unsafe.h"
  15. #include "base/compiler_specific.h"
  16. #include "gtest/gtest.h"
  17. namespace crashpad {
  18. namespace test {
  19. namespace {
  20. TEST(ArraySizeUnsafe, ArraySizeUnsafe) {
  21. char c1[1];
  22. static_assert(ARRAYSIZE_UNSAFE(c1) == 1, "c1");
  23. ALLOW_UNUSED_LOCAL(c1);
  24. char c2[2];
  25. static_assert(ARRAYSIZE_UNSAFE(c2) == 2, "c2");
  26. ALLOW_UNUSED_LOCAL(c2);
  27. char c4[4];
  28. static_assert(ARRAYSIZE_UNSAFE(c4) == 4, "c4");
  29. ALLOW_UNUSED_LOCAL(c4);
  30. int i1[1];
  31. static_assert(ARRAYSIZE_UNSAFE(i1) == 1, "i1");
  32. ALLOW_UNUSED_LOCAL(i1);
  33. int i2[2];
  34. static_assert(ARRAYSIZE_UNSAFE(i2) == 2, "i2");
  35. ALLOW_UNUSED_LOCAL(i2);
  36. int i4[4];
  37. static_assert(ARRAYSIZE_UNSAFE(i4) == 4, "i4");
  38. ALLOW_UNUSED_LOCAL(i4);
  39. long l8[8];
  40. static_assert(ARRAYSIZE_UNSAFE(l8) == 8, "l8");
  41. ALLOW_UNUSED_LOCAL(l8);
  42. int l9[9];
  43. static_assert(ARRAYSIZE_UNSAFE(l9) == 9, "l9");
  44. ALLOW_UNUSED_LOCAL(l9);
  45. struct S {
  46. char c;
  47. int i;
  48. long l;
  49. bool b;
  50. };
  51. S s1[1];
  52. static_assert(ARRAYSIZE_UNSAFE(s1) == 1, "s1");
  53. ALLOW_UNUSED_LOCAL(s1);
  54. S s10[10];
  55. static_assert(ARRAYSIZE_UNSAFE(s10) == 10, "s10");
  56. ALLOW_UNUSED_LOCAL(s10);
  57. }
  58. } // namespace
  59. } // namespace test
  60. } // namespace crashpad