• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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/trace_processor_impl.h"
18 
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21 
22 namespace perfetto {
23 namespace trace_processor {
24 namespace {
25 
TEST(TraceProcessorImplTest,GuessTraceType_Empty)26 TEST(TraceProcessorImplTest, GuessTraceType_Empty) {
27   const uint8_t prefix[] = "";
28   EXPECT_EQ(kUnknownTraceType, GuessTraceType(prefix, 0));
29 }
30 
TEST(TraceProcessorImplTest,GuessTraceType_Json)31 TEST(TraceProcessorImplTest, GuessTraceType_Json) {
32   const uint8_t prefix[] = "{\"traceEvents\":[";
33   EXPECT_EQ(kJsonTraceType, GuessTraceType(prefix, sizeof(prefix)));
34 }
35 
TEST(TraceProcessorImplTest,GuessTraceType_JsonWithSpaces)36 TEST(TraceProcessorImplTest, GuessTraceType_JsonWithSpaces) {
37   const uint8_t prefix[] = "\n{ \"traceEvents\": [";
38   EXPECT_EQ(kJsonTraceType, GuessTraceType(prefix, sizeof(prefix)));
39 }
40 
TEST(TraceProcessorImplTest,GuessTraceType_JsonMissingTraceEvents)41 TEST(TraceProcessorImplTest, GuessTraceType_JsonMissingTraceEvents) {
42   const uint8_t prefix[] = "[{";
43   EXPECT_EQ(kJsonTraceType, GuessTraceType(prefix, sizeof(prefix)));
44 }
45 
TEST(TraceProcessorImplTest,GuessTraceType_Proto)46 TEST(TraceProcessorImplTest, GuessTraceType_Proto) {
47   const uint8_t prefix[] = {0x0a, 0x00};  // An empty TracePacket.
48   EXPECT_EQ(kProtoTraceType, GuessTraceType(prefix, sizeof(prefix)));
49 }
50 
TEST(TraceProcessorImplTest,GuessTraceType_Fuchsia)51 TEST(TraceProcessorImplTest, GuessTraceType_Fuchsia) {
52   const uint8_t prefix[] = {0x10, 0x00, 0x04, 0x46, 0x78, 0x54, 0x16, 0x00};
53   EXPECT_EQ(kFuchsiaTraceType, GuessTraceType(prefix, sizeof(prefix)));
54 }
55 
56 }  // namespace
57 }  // namespace trace_processor
58 }  // namespace perfetto
59