1 // Copyright (c) 2015-2016 The Khronos Group Inc.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include "unit_spirv.h"
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));
26 TEST(BinaryEndianness, Little) {
28 if (I32_ENDIAN_HOST == I32_ENDIAN_LITTLE) {
29 magicNumber = 0x07230203;
31 magicNumber = 0x03022307;
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);
39 TEST(BinaryEndianness, Big) {
41 if (I32_ENDIAN_HOST == I32_ENDIAN_BIG) {
42 magicNumber = 0x07230203;
44 magicNumber = 0x03022307;
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);
52 } // anonymous namespace