• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 #include "test/unit_spirv.h"
16 
17 namespace spvtools {
18 namespace {
19 
TEST(BinaryEndianness,InvalidCode)20 TEST(BinaryEndianness, InvalidCode) {
21   uint32_t invalidMagicNumber[] = {0};
22   spv_const_binary_t binary = {invalidMagicNumber, 1};
23   spv_endianness_t endian;
24   ASSERT_EQ(SPV_ERROR_INVALID_BINARY, spvBinaryEndianness(&binary, &endian));
25 }
26 
TEST(BinaryEndianness,Little)27 TEST(BinaryEndianness, Little) {
28   uint32_t magicNumber;
29   if (I32_ENDIAN_HOST == I32_ENDIAN_LITTLE) {
30     magicNumber = 0x07230203;
31   } else {
32     magicNumber = 0x03022307;
33   }
34   spv_const_binary_t binary = {&magicNumber, 1};
35   spv_endianness_t endian;
36   ASSERT_EQ(SPV_SUCCESS, spvBinaryEndianness(&binary, &endian));
37   ASSERT_EQ(SPV_ENDIANNESS_LITTLE, endian);
38 }
39 
TEST(BinaryEndianness,Big)40 TEST(BinaryEndianness, Big) {
41   uint32_t magicNumber;
42   if (I32_ENDIAN_HOST == I32_ENDIAN_BIG) {
43     magicNumber = 0x07230203;
44   } else {
45     magicNumber = 0x03022307;
46   }
47   spv_const_binary_t binary = {&magicNumber, 1};
48   spv_endianness_t endian;
49   ASSERT_EQ(SPV_SUCCESS, spvBinaryEndianness(&binary, &endian));
50   ASSERT_EQ(SPV_ENDIANNESS_BIG, endian);
51 }
52 
53 }  // namespace
54 }  // namespace spvtools
55