1 /*
2 * Copyright (C) 2023 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 "perfetto/base/status.h"
18
19 #include "test/gtest_and_gmock.h"
20
21 namespace perfetto {
22 namespace base {
23
TEST(StatusTest,GetMissingPayload)24 TEST(StatusTest, GetMissingPayload) {
25 base::Status status = base::ErrStatus("Error");
26 ASSERT_EQ(status.GetPayload("test.foo.com/bar"), std::nullopt);
27 }
28
TEST(StatusTest,SetThenGetPayload)29 TEST(StatusTest, SetThenGetPayload) {
30 base::Status status = base::ErrStatus("Error");
31 status.SetPayload("test.foo.com/bar", "payload_value");
32 ASSERT_EQ(status.GetPayload("test.foo.com/bar"), "payload_value");
33 }
34
TEST(StatusTest,SetEraseGetPayload)35 TEST(StatusTest, SetEraseGetPayload) {
36 base::Status status = base::ErrStatus("Error");
37 status.SetPayload("test.foo.com/bar", "payload_value");
38 ASSERT_TRUE(status.ErasePayload("test.foo.com/bar"));
39 ASSERT_EQ(status.GetPayload("test.foo.com/bar"), std::nullopt);
40 }
41
TEST(StatusTest,SetOverride)42 TEST(StatusTest, SetOverride) {
43 base::Status status = base::ErrStatus("Error");
44 status.SetPayload("test.foo.com/bar", "payload_value");
45 status.SetPayload("test.foo.com/bar", "other_value");
46 ASSERT_EQ(status.GetPayload("test.foo.com/bar"), "other_value");
47 }
48
TEST(StatusTest,SetGetOk)49 TEST(StatusTest, SetGetOk) {
50 base::Status status = base::OkStatus();
51 status.SetPayload("test.foo.com/bar", "payload_value");
52 ASSERT_EQ(status.GetPayload("test.foo.com/bar"), std::nullopt);
53 }
54
TEST(StatusTest,SetMultipleAndDuplicate)55 TEST(StatusTest, SetMultipleAndDuplicate) {
56 base::Status status = base::ErrStatus("Error");
57 status.SetPayload("test.foo.com/bar", "payload_value");
58 status.SetPayload("test.foo.com/bar1", "1");
59 status.SetPayload("test.foo.com/bar2", "2");
60 status.SetPayload("test.foo.com/bar", "other_value");
61 ASSERT_EQ(status.GetPayload("test.foo.com/bar"), "other_value");
62 ASSERT_EQ(status.GetPayload("test.foo.com/bar1"), "1");
63 ASSERT_EQ(status.GetPayload("test.foo.com/bar2"), "2");
64 }
65
66 } // namespace base
67 } // namespace perfetto
68