| 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 |
#include "gmock/gmock.h" |
| 18 |
#include "source/util/string_utils.h" |
| 19 |
#include "test/test_fixture.h" |
| 20 |
|
| 21 |
namespace spvtools { |
| 22 |
namespace { |
| 23 |
|
| 24 |
using utils::MakeVector; |
| 25 |
using ::testing::Eq; |
| 26 |
using Words = std::vector<uint32_t>; |
| 27 |
|
| 28 |
TEST(MakeVector, Samples) { |
| 29 |
EXPECT_THAT(MakeVector(""), Eq(Words{0})); |
| 30 |
EXPECT_THAT(MakeVector("a"), Eq(Words{0x0061})); |
| 31 |
EXPECT_THAT(MakeVector("ab"), Eq(Words{0x006261})); |
| 32 |
EXPECT_THAT(MakeVector("abc"), Eq(Words{0x00636261})); |
| 33 |
EXPECT_THAT(MakeVector("abcd"), Eq(Words{0x64636261, 0x00})); |
| 34 |
EXPECT_THAT(MakeVector("abcde"), Eq(Words{0x64636261, 0x0065})); |
| 35 |
} |
| 36 |
|
| 37 |
TEST(WordVectorPrintTo, PreservesFlagsAndFill) { |
| 38 |
std::stringstream s; |
| 39 |
s << std::setw(4) << std::oct << std::setfill('x') << 8 << " "; |
| 40 |
spvtest::PrintTo(spvtest::WordVector({10, 16}), &s); |
| 41 |
// The octal setting and fill character should be preserved |
| 42 |
// from before the PrintTo. |
| 43 |
// Width is reset after each emission of a regular scalar type. |
| 44 |
// So set it explicitly again. |
| 45 |
s << std::setw(4) << 9; |
| 46 |
|
| 47 |
EXPECT_THAT(s.str(), Eq("xx10 0x0000000a 0x00000010 xx11")); |
| 48 |
} |
| 49 |
|
| 50 |
} // namespace |
| 51 |
} // namespace spvtools |