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