binary_endianness_test.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (c) 2015-2016 The Khronos Group Inc.
  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 "test/unit_spirv.h"
  15. namespace spvtools {
  16. namespace {
  17. TEST(BinaryEndianness, InvalidCode) {
  18. uint32_t invalidMagicNumber[] = {0};
  19. spv_const_binary_t binary = {invalidMagicNumber, 1};
  20. spv_endianness_t endian;
  21. ASSERT_EQ(SPV_ERROR_INVALID_BINARY, spvBinaryEndianness(&binary, &endian));
  22. }
  23. TEST(BinaryEndianness, Little) {
  24. uint32_t magicNumber;
  25. if (I32_ENDIAN_HOST == I32_ENDIAN_LITTLE) {
  26. magicNumber = 0x07230203;
  27. } else {
  28. magicNumber = 0x03022307;
  29. }
  30. spv_const_binary_t binary = {&magicNumber, 1};
  31. spv_endianness_t endian;
  32. ASSERT_EQ(SPV_SUCCESS, spvBinaryEndianness(&binary, &endian));
  33. ASSERT_EQ(SPV_ENDIANNESS_LITTLE, endian);
  34. }
  35. TEST(BinaryEndianness, Big) {
  36. uint32_t magicNumber;
  37. if (I32_ENDIAN_HOST == I32_ENDIAN_BIG) {
  38. magicNumber = 0x07230203;
  39. } else {
  40. magicNumber = 0x03022307;
  41. }
  42. spv_const_binary_t binary = {&magicNumber, 1};
  43. spv_endianness_t endian;
  44. ASSERT_EQ(SPV_SUCCESS, spvBinaryEndianness(&binary, &endian));
  45. ASSERT_EQ(SPV_ENDIANNESS_BIG, endian);
  46. }
  47. } // namespace
  48. } // namespace spvtools