• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #include "src/core/util/unique_ptr_with_bitset.h"
20 
21 #include <grpc/support/port_platform.h>
22 #include <stdint.h>
23 
24 #include <limits>
25 #include <memory>
26 
27 #include "gtest/gtest.h"
28 
29 namespace grpc_core {
30 
TEST(UniquePtrWithBitsetTest,Basic)31 TEST(UniquePtrWithBitsetTest, Basic) {
32   UniquePtrWithBitset<int, 1> ptr;
33   EXPECT_EQ(ptr.get(), nullptr);
34   EXPECT_EQ(ptr.TestBit(0), false);
35   ptr.reset(new int(42));
36   EXPECT_EQ(*ptr, 42);
37   EXPECT_EQ(ptr.TestBit(0), false);
38   ptr.SetBit(0);
39   EXPECT_EQ(ptr.TestBit(0), true);
40   ptr.reset();
41   EXPECT_EQ(ptr.get(), nullptr);
42   EXPECT_EQ(ptr.TestBit(0), true);
43   ptr.ClearBit(0);
44   EXPECT_EQ(ptr.TestBit(0), false);
45   ptr.reset(new int(43));
46   ptr.SetBit(0);
47 
48   UniquePtrWithBitset<int, 1> ptr2;
49   ptr2 = std::move(ptr);
50   EXPECT_EQ(*ptr2, 43);
51   EXPECT_EQ(ptr2.TestBit(0), true);
52 }
53 
54 }  // namespace grpc_core
55 
main(int argc,char ** argv)56 int main(int argc, char** argv) {
57   ::testing::InitGoogleTest(&argc, argv);
58   return RUN_ALL_TESTS();
59 }
60