1 /*
2  * Copyright (C) 2022 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/perfetto_sql/intrinsics/table_functions/descendant.h"
18 
19 #include <memory>
20 
21 #include "perfetto/ext/base/status_or.h"
22 #include "perfetto/trace_processor/basic_types.h"
23 #include "src/trace_processor/db/table.h"
24 #include "src/trace_processor/storage/trace_storage.h"
25 #include "test/gtest_and_gmock.h"
26 
27 namespace perfetto::trace_processor {
28 namespace {
29 
TEST(Descendant,SliceTableNullConstraint)30 TEST(Descendant, SliceTableNullConstraint) {
31   // Insert a row to make sure that we are not returning an empty table just
32   // because the source is empty.
33   TraceStorage storage;
34   storage.mutable_slice_table()->Insert({});
35 
36   Descendant generator{Descendant::Type::kSlice, &storage};
37 
38   // Check that if we pass start_id = NULL as a constraint, we correctly return
39   // an empty table.
40   base::StatusOr<std::unique_ptr<Table>> res =
41       generator.ComputeTable({SqlValue()});
42   ASSERT_TRUE(res.ok());
43   ASSERT_EQ(res->get()->row_count(), 0u);
44 }
45 
TEST(Descendant,SliceByStackTableNullConstraint)46 TEST(Descendant, SliceByStackTableNullConstraint) {
47   // Insert a row to make sure that we are not returning an empty table just
48   // because the source is empty.
49   TraceStorage storage;
50   storage.mutable_slice_table()->Insert({});
51 
52   Descendant generator{Descendant::Type::kSliceByStack, &storage};
53 
54   // Check that if we pass start_id = NULL as a constraint, we correctly return
55   // an empty table.
56   base::StatusOr<std::unique_ptr<Table>> res =
57       generator.ComputeTable({SqlValue()});
58   ASSERT_TRUE(res.ok());
59   ASSERT_EQ(res->get()->row_count(), 0u);
60 }
61 
62 }  // namespace
63 }  // namespace perfetto::trace_processor
64