1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "base/process/process_handle.h"
8 #include "chrome/common/partial_circular_buffer.h"
9 #include "chrome/renderer/media/chrome_webrtc_log_message_delegate.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 TEST(ChromeWebRtcLogMessageDelegateTest
, Basic
) {
13 const uint32 kTestLogSize
= 1024; // 1 KB
14 const char kTestString
[] = "abcdefghijklmnopqrstuvwxyz";
16 base::MessageLoop
message_loop(base::MessageLoop::TYPE_IO
);
18 scoped_ptr
<ChromeWebRtcLogMessageDelegate
> log_message_delegate(
19 new ChromeWebRtcLogMessageDelegate(message_loop
.message_loop_proxy(),
22 base::SharedMemory shared_memory
;
23 ASSERT_TRUE(shared_memory
.CreateAndMapAnonymous(kTestLogSize
));
24 base::SharedMemoryHandle new_handle
;
25 ASSERT_TRUE(shared_memory
.ShareToProcess(base::GetCurrentProcessHandle(),
27 log_message_delegate
->OnLogOpened(new_handle
, kTestLogSize
);
29 log_message_delegate
->LogMessage(kTestString
);
30 log_message_delegate
->LogMessage(kTestString
);
32 PartialCircularBuffer
read_pcb(
33 reinterpret_cast<uint8
*>(shared_memory
.memory()), kTestLogSize
);
35 // Size is calculated as (sizeof(kTestString) - 1 for terminating null
36 // + 1 for eol added for each log message in LogMessage) * 2 + 1 for
38 char read_buffer
[sizeof(kTestString
) * 2 + 1] = {0};
40 uint32 read
= read_pcb
.Read(read_buffer
, sizeof(read_buffer
));
41 EXPECT_EQ(sizeof(read_buffer
) - 1, read
);
42 std::string ref_output
= kTestString
;
43 ref_output
.append("\n");
44 ref_output
.append(kTestString
);
45 ref_output
.append("\n");
46 EXPECT_STREQ(ref_output
.c_str(), read_buffer
);