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/tracing/core/null_trace_writer.h" 18 19 #include "gmock/gmock.h" 20 #include "gtest/gtest.h" 21 #include "perfetto/base/utils.h" 22 #include "perfetto/tracing/core/trace_writer.h" 23 24 #include "perfetto/trace/test_event.pbzero.h" 25 #include "perfetto/trace/trace_packet.pbzero.h" 26 27 namespace perfetto { 28 namespace { 29 30 TEST(NullTraceWriterTest, WriterIdIsZero) { 31 NullTraceWriter writer; 32 EXPECT_EQ(writer.writer_id(), 0); 33 } 34 35 TEST(NullTraceWriterTest, Writing) { 36 NullTraceWriter writer; 37 for (size_t i = 0; i < 3 * base::kPageSize; i++) { 38 auto packet = writer.NewTracePacket(); 39 packet->set_for_testing()->set_str("Hello, world!"); 40 } 41 } 42 43 TEST(NullTraceWriterTest, FlushCallbackIsCalled) { 44 NullTraceWriter writer; 45 writer.Flush(); 46 bool was_called = false; 47 writer.Flush([&was_called] { was_called = true; }); 48 EXPECT_TRUE(was_called); 49 } 50 51 } // namespace 52 } // namespace perfetto 53