• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "src/trace_processor/containers/nullable_vector.h"
18 
19 #include "test/gtest_and_gmock.h"
20 
21 namespace perfetto {
22 namespace trace_processor {
23 namespace {
24 
TEST(NullableVector,Append)25 TEST(NullableVector, Append) {
26   NullableVector<int64_t> sv;
27   sv.Append(10);
28   sv.Append(20);
29   sv.Append(std::nullopt);
30   sv.Append(40);
31 
32   ASSERT_FALSE(sv.IsDense());
33   ASSERT_EQ(sv.size(), 4u);
34   ASSERT_EQ(sv.Get(0), std::optional<int64_t>(10));
35   ASSERT_EQ(sv.Get(1), std::optional<int64_t>(20));
36   ASSERT_EQ(sv.Get(2), std::nullopt);
37   ASSERT_EQ(sv.Get(3), std::optional<int64_t>(40));
38 }
39 
TEST(NullableVector,Set)40 TEST(NullableVector, Set) {
41   NullableVector<int64_t> sv;
42   sv.Append(10);
43   sv.Append(20);
44   sv.Append(std::nullopt);
45   sv.Append(std::nullopt);
46   sv.Append(40);
47 
48   sv.Set(0, 15);
49   sv.Set(3, 30);
50 
51   ASSERT_EQ(*sv.Get(0), 15);
52   ASSERT_EQ(*sv.Get(1), 20);
53   ASSERT_EQ(sv.Get(2), std::nullopt);
54   ASSERT_EQ(*sv.Get(3), 30);
55   ASSERT_EQ(*sv.Get(4), 40);
56 }
57 
TEST(NullableVector,SetNonNull)58 TEST(NullableVector, SetNonNull) {
59   NullableVector<int64_t> sv;
60   sv.Append(1);
61   sv.Append(2);
62   sv.Append(3);
63   sv.Append(4);
64 
65   sv.Set(1, 22);
66 
67   ASSERT_EQ(sv.Get(0), std::optional<int64_t>(1));
68   ASSERT_EQ(sv.Get(1), std::optional<int64_t>(22));
69   ASSERT_EQ(sv.Get(2), std::optional<int64_t>(3));
70   ASSERT_EQ(sv.Get(3), std::optional<int64_t>(4));
71 }
72 
TEST(NullableVector,Dense)73 TEST(NullableVector, Dense) {
74   auto sv = NullableVector<int64_t>::Dense();
75 
76   sv.Append(0);
77   sv.Append(std::nullopt);
78   sv.Append(2);
79   sv.Append(3);
80   sv.Append(std::nullopt);
81 
82   ASSERT_TRUE(sv.IsDense());
83   ASSERT_EQ(sv.Get(0), 0);
84   ASSERT_EQ(sv.Get(1), std::nullopt);
85   ASSERT_EQ(sv.Get(2), 2);
86   ASSERT_EQ(sv.Get(3), 3);
87   ASSERT_EQ(sv.Get(4), std::nullopt);
88 
89   sv.Set(1, 1);
90   ASSERT_EQ(sv.Get(1), 1);
91   ASSERT_EQ(sv.Get(2), 2);
92 }
93 
94 }  // namespace
95 }  // namespace trace_processor
96 }  // namespace perfetto
97