• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Tint Authors.
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 "src/reader/spirv/fail_stream.h"
16 
17 #include "gmock/gmock.h"
18 
19 namespace tint {
20 namespace reader {
21 namespace spirv {
22 namespace {
23 
24 using ::testing::Eq;
25 
26 using FailStreamTest = ::testing::Test;
27 
TEST_F(FailStreamTest,ConversionToBoolIsSameAsStatusMethod)28 TEST_F(FailStreamTest, ConversionToBoolIsSameAsStatusMethod) {
29   bool flag = true;
30   FailStream fs(&flag, nullptr);
31 
32   EXPECT_TRUE(fs.status());
33   EXPECT_TRUE(bool(fs));  // NOLINT
34   flag = false;
35   EXPECT_FALSE(fs.status());
36   EXPECT_FALSE(bool(fs));  // NOLINT
37   flag = true;
38   EXPECT_TRUE(fs.status());
39   EXPECT_TRUE(bool(fs));  // NOLINT
40 }
41 
TEST_F(FailStreamTest,FailMethodChangesStatusToFalse)42 TEST_F(FailStreamTest, FailMethodChangesStatusToFalse) {
43   bool flag = true;
44   FailStream fs(&flag, nullptr);
45   EXPECT_TRUE(flag);
46   EXPECT_TRUE(bool(fs));  // NOLINT
47   fs.Fail();
48   EXPECT_FALSE(flag);
49   EXPECT_FALSE(bool(fs));  // NOLINT
50 }
51 
TEST_F(FailStreamTest,FailMethodReturnsSelf)52 TEST_F(FailStreamTest, FailMethodReturnsSelf) {
53   bool flag = true;
54   FailStream fs(&flag, nullptr);
55   FailStream& result = fs.Fail();
56   EXPECT_THAT(&result, Eq(&fs));
57 }
58 
TEST_F(FailStreamTest,ShiftOperatorAccumulatesValues)59 TEST_F(FailStreamTest, ShiftOperatorAccumulatesValues) {
60   bool flag = true;
61   std::stringstream ss;
62   FailStream fs(&flag, &ss);
63 
64   ss << "prefix ";
65   fs << "cat " << 42;
66 
67   EXPECT_THAT(ss.str(), Eq("prefix cat 42"));
68 }
69 
70 }  // namespace
71 }  // namespace spirv
72 }  // namespace reader
73 }  // namespace tint
74