OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Unit tests for event trace consumer base class. | 5 // Unit tests for event trace consumer base class. |
6 #include "base/win/event_trace_consumer.h" | 6 #include "base/win/event_trace_consumer.h" |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include <objbase.h> | 10 #include <objbase.h> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/files/scoped_temp_dir.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/process.h" | 17 #include "base/process.h" |
17 #include "base/scoped_temp_dir.h" | |
18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
19 #include "base/win/event_trace_controller.h" | 19 #include "base/win/event_trace_controller.h" |
20 #include "base/win/event_trace_provider.h" | 20 #include "base/win/event_trace_provider.h" |
21 #include "base/win/scoped_handle.h" | 21 #include "base/win/scoped_handle.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 #include <initguid.h> // NOLINT - has to be last | 24 #include <initguid.h> // NOLINT - has to be last |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 349 |
350 // We should now have the event in the queue. | 350 // We should now have the event in the queue. |
351 if (events_.empty()) | 351 if (events_.empty()) |
352 return E_FAIL; | 352 return E_FAIL; |
353 | 353 |
354 *trace = &events_.back(); | 354 *trace = &events_.back(); |
355 return S_OK; | 355 return S_OK; |
356 } | 356 } |
357 | 357 |
358 EventQueue events_; | 358 EventQueue events_; |
359 ScopedTempDir temp_dir_; | 359 base::ScopedTempDir temp_dir_; |
360 FilePath temp_file_; | 360 FilePath temp_file_; |
361 }; | 361 }; |
362 | 362 |
363 } // namespace | 363 } // namespace |
364 | 364 |
365 | 365 |
366 TEST_F(EtwTraceConsumerDataTest, RoundTrip) { | 366 TEST_F(EtwTraceConsumerDataTest, RoundTrip) { |
367 EtwMofEvent<1> event(kTestEventType, 1, TRACE_LEVEL_ERROR); | 367 EtwMofEvent<1> event(kTestEventType, 1, TRACE_LEVEL_ERROR); |
368 | 368 |
369 static const char kData[] = "This is but test data"; | 369 static const char kData[] = "This is but test data"; |
370 event.fields[0].DataPtr = reinterpret_cast<ULONG64>(kData); | 370 event.fields[0].DataPtr = reinterpret_cast<ULONG64>(kData); |
371 event.fields[0].Length = sizeof(kData); | 371 event.fields[0].Length = sizeof(kData); |
372 | 372 |
373 PEVENT_TRACE trace = NULL; | 373 PEVENT_TRACE trace = NULL; |
374 HRESULT hr = RoundTripEvent(&event.header, &trace); | 374 HRESULT hr = RoundTripEvent(&event.header, &trace); |
375 if (hr == E_ACCESSDENIED) { | 375 if (hr == E_ACCESSDENIED) { |
376 VLOG(1) << "You must be an administrator to run this test on Vista"; | 376 VLOG(1) << "You must be an administrator to run this test on Vista"; |
377 return; | 377 return; |
378 } | 378 } |
379 ASSERT_HRESULT_SUCCEEDED(hr) << "RoundTripEvent failed"; | 379 ASSERT_HRESULT_SUCCEEDED(hr) << "RoundTripEvent failed"; |
380 ASSERT_TRUE(NULL != trace); | 380 ASSERT_TRUE(NULL != trace); |
381 ASSERT_EQ(sizeof(kData), trace->MofLength); | 381 ASSERT_EQ(sizeof(kData), trace->MofLength); |
382 ASSERT_STREQ(kData, reinterpret_cast<const char*>(trace->MofData)); | 382 ASSERT_STREQ(kData, reinterpret_cast<const char*>(trace->MofData)); |
383 } | 383 } |
OLD | NEW |