• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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/utils/defer.h"
16 
17 #include "gtest/gtest.h"
18 
19 namespace tint {
20 namespace utils {
21 namespace {
22 
TEST(DeferTest,Basic)23 TEST(DeferTest, Basic) {
24   bool deferCalled = false;
25   { TINT_DEFER(deferCalled = true); }
26   ASSERT_TRUE(deferCalled);
27 }
28 
TEST(DeferTest,DeferOrder)29 TEST(DeferTest, DeferOrder) {
30   int counter = 0;
31   int a = 0, b = 0, c = 0;
32   {
33     TINT_DEFER(a = ++counter);
34     TINT_DEFER(b = ++counter);
35     TINT_DEFER(c = ++counter);
36   }
37   ASSERT_EQ(a, 3);
38   ASSERT_EQ(b, 2);
39   ASSERT_EQ(c, 1);
40 }
41 
42 }  // namespace
43 }  // namespace utils
44 }  // namespace tint
45