xref: /aosp_15_r20/system/media/audio_utils/tests/audio_trace_tests.cpp (revision b9df5ad1c9ac98a7fefaac271a55f7ae3db05414)
1 /*
2  * Copyright (C) 2024 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 <audio_utils/Trace.h>
18 
19 #include <gtest/gtest.h>
20 
TEST(trace_object,basic)21 TEST(trace_object, basic) {
22     android::audio_utils::trace::Object obj;
23 
24     EXPECT_TRUE(obj.empty());
25     obj.set("one", 10);
26     EXPECT_FALSE(obj.empty());
27 
28     auto trace = obj.toTrace();
29 
30     EXPECT_NE(trace.find("one"), std::string::npos);
31     EXPECT_NE(trace.find("10"), std::string::npos);
32     EXPECT_EQ("{ one=10 }", trace);
33 
34     obj.set("two", "twenty");
35     auto trace2 = obj.toTrace();
36     EXPECT_NE(trace2.find("one"), std::string::npos);
37     EXPECT_NE(trace2.find("10"), std::string::npos);
38     EXPECT_NE(trace2.find("two"), std::string::npos);
39     EXPECT_NE(trace2.find("twenty"), std::string::npos);
40     EXPECT_EQ("{ one=10 two=\"twenty\" }", trace2);
41 
42     obj.clear();
43     EXPECT_TRUE(obj.empty());
44     EXPECT_EQ("{  }", obj.toTrace());
45 }
46