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