1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/arc/tracing/arc_tracing_event_matcher.h"
#include "base/json/json_reader.h"
#include "chrome/browser/ash/arc/tracing/arc_tracing_event.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace arc {
namespace {
ArcTracingEvent MakeEvent(const char* json_str) {
return ArcTracingEvent(
std::move(base::JSONReader::Read(json_str)->GetDict()));
}
} // namespace
using ArcTracingEventMatcherTest = testing::Test;
TEST_F(ArcTracingEventMatcherTest, CategoryNameMatch) {
ArcTracingEventMatcher matcher("exo:Surface::Attach");
EXPECT_TRUE(
matcher.Match(MakeEvent(R"({"cat":"exo","name":"Surface::Attach"})")));
EXPECT_FALSE(
matcher.Match(MakeEvent(R"({"cat":"exo","name":"Surface::Attac"})")));
EXPECT_FALSE(
matcher.Match(MakeEvent(R"({"cat":"exo","name":"Surface::AttacH"})")));
EXPECT_FALSE(
matcher.Match(MakeEvent(R"({"cat":"exo","name":"Surface::Attach2"})")));
EXPECT_FALSE(matcher.Match(
MakeEvent(R"({"cat":"android","name":"Surface::Attach"})")));
}
TEST_F(ArcTracingEventMatcherTest, CategoryNamePrefixMatch) {
ArcTracingEventMatcher matcher("android:ARC_VSYNC|*");
EXPECT_FALSE(
matcher.Match(MakeEvent(R"({"cat":"android","name":"ARC_VSYNC"})")));
EXPECT_TRUE(
matcher.Match(MakeEvent(R"({"cat":"android","name":"ARC_VSYNC|"})")));
EXPECT_TRUE(
matcher.Match(MakeEvent(R"({"cat":"android","name":"ARC_VSYNC|123"})")));
EXPECT_TRUE(
matcher.Match(MakeEvent(R"({"cat":"android","name":"ARC_VSYNC|abc"})")));
EXPECT_FALSE(
matcher.Match(MakeEvent(R"({"cat":"android","name":"XARC_VSYNC|123"})")));
}
TEST_F(ArcTracingEventMatcherTest, CategoryNamePrefixAndroidInt64) {
ArcTracingEventMatcher matcher("android:ARC_VSYNC|*");
EXPECT_EQ(std::nullopt, matcher.ReadAndroidEventInt64(
MakeEvent(R"({"name":"ARC_VSYNC"})")));
EXPECT_EQ(std::nullopt, matcher.ReadAndroidEventInt64(
MakeEvent(R"({"name":"ARC_VSYNC|"})")));
EXPECT_EQ(std::nullopt, matcher.ReadAndroidEventInt64(
MakeEvent(R"({"name":"ARC_VSYNC|abc"})")));
EXPECT_EQ(std::make_optional(0), matcher.ReadAndroidEventInt64(
MakeEvent(R"({"name":"ARC_VSYNC|0"})")));
EXPECT_EQ(std::make_optional(777777777777LL),
matcher.ReadAndroidEventInt64(
MakeEvent(R"({"name":"ARC_VSYNC|777777777777"})")));
EXPECT_EQ(std::make_optional(-777777777777LL),
matcher.ReadAndroidEventInt64(
MakeEvent(R"({"name":"ARC_VSYNC|-777777777777"})")));
}
} // namespace arc
|