Setup dependent external sources
[platform/upstream/VK-GL-CTS.git] / external / spirv-tools / src / test / binary_endianness_test.cpp
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 "unit_spirv.h"
16
17 namespace {
18
19 TEST(BinaryEndianness, InvalidCode) {
20   uint32_t invalidMagicNumber[] = {0};
21   spv_const_binary_t binary = {invalidMagicNumber, 1};
22   spv_endianness_t endian;
23   ASSERT_EQ(SPV_ERROR_INVALID_BINARY, spvBinaryEndianness(&binary, &endian));
24 }
25
26 TEST(BinaryEndianness, Little) {
27   uint32_t magicNumber;
28   if (I32_ENDIAN_HOST == I32_ENDIAN_LITTLE) {
29     magicNumber = 0x07230203;
30   } else {
31     magicNumber = 0x03022307;
32   }
33   spv_const_binary_t binary = {&magicNumber, 1};
34   spv_endianness_t endian;
35   ASSERT_EQ(SPV_SUCCESS, spvBinaryEndianness(&binary, &endian));
36   ASSERT_EQ(SPV_ENDIANNESS_LITTLE, endian);
37 }
38
39 TEST(BinaryEndianness, Big) {
40   uint32_t magicNumber;
41   if (I32_ENDIAN_HOST == I32_ENDIAN_BIG) {
42     magicNumber = 0x07230203;
43   } else {
44     magicNumber = 0x03022307;
45   }
46   spv_const_binary_t binary = {&magicNumber, 1};
47   spv_endianness_t endian;
48   ASSERT_EQ(SPV_SUCCESS, spvBinaryEndianness(&binary, &endian));
49   ASSERT_EQ(SPV_ENDIANNESS_BIG, endian);
50 }
51
52 }  // anonymous namespace