Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: base/event_trace_provider_unittest.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/event_trace_provider.cc ('k') | base/exception_barrier.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2010 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15 //
16 // Unit tests for event trace provider.
17 #include "omaha/base/event_trace_provider.h"
18 #include <new>
19 #include "omaha/testing/unit_test.h"
20 #include <initguid.h> // NOLINT - has to be last
21
22 namespace omaha {
23
24 // {7F0FD37F-FA3C-4cd6-9242-DF60967A2CB2}
25 DEFINE_GUID(kTestProvider,
26 0x7f0fd37f, 0xfa3c, 0x4cd6, 0x92, 0x42, 0xdf, 0x60, 0x96, 0x7a, 0x2c, 0xb2);
27
28 // {7F0FD37F-FA3C-4cd6-9242-DF60967A2CB2}
29 DEFINE_GUID(kTestEventClass,
30 0x7f0fd37f, 0xfa3c, 0x4cd6, 0x92, 0x42, 0xdf, 0x60, 0x96, 0x7a, 0x2c, 0xb2);
31
32 TEST(EtwTraceProviderTest, ToleratesPreCreateInvocations) {
33 // Because the trace provider is used in logging, it's important that
34 // it be possible to use static provider instances without regard to
35 // whether they've been constructed or destructed.
36 // The interface of the class is designed to tolerate this usage.
37 char buf[sizeof(EtwTraceProvider)] = {0};
38 EtwTraceProvider& provider = reinterpret_cast<EtwTraceProvider&>(buf);
39
40 EXPECT_EQ(NULL, provider.registration_handle());
41 EXPECT_EQ(NULL, provider.session_handle());
42 EXPECT_EQ(0, provider.enable_flags());
43 EXPECT_EQ(0, provider.enable_level());
44
45 EXPECT_FALSE(provider.ShouldLog(TRACE_LEVEL_FATAL, 0xfffffff));
46
47 // We expect these not to crash.
48 provider.Log(kTestEventClass, 0, TRACE_LEVEL_FATAL, "foo");
49 provider.Log(kTestEventClass, 0, TRACE_LEVEL_FATAL, L"foo");
50
51 EtwMofEvent<1> dummy(kTestEventClass, 0, TRACE_LEVEL_FATAL);
52 DWORD data = 0;
53 dummy.SetField(0, sizeof(data), &data);
54 provider.Log(dummy.get());
55
56 // Placement-new the provider into our buffer.
57 new (buf) EtwTraceProvider(kTestProvider); // NOLINT
58
59 // Registration is now safe.
60 EXPECT_EQ(ERROR_SUCCESS, provider.Register());
61
62 // Destruct the instance, this should unregister it.
63 provider.EtwTraceProvider::~EtwTraceProvider();
64
65 // And post-destruction, all of the above should still be safe.
66 EXPECT_EQ(NULL, provider.registration_handle());
67 EXPECT_EQ(NULL, provider.session_handle());
68 EXPECT_EQ(0, provider.enable_flags());
69 EXPECT_EQ(0, provider.enable_level());
70
71 EXPECT_FALSE(provider.ShouldLog(TRACE_LEVEL_FATAL, 0xfffffff));
72
73 // We expect these not to crash.
74 provider.Log(kTestEventClass, 0, TRACE_LEVEL_FATAL, "foo");
75 provider.Log(kTestEventClass, 0, TRACE_LEVEL_FATAL, L"foo");
76 provider.Log(dummy.get());
77 }
78
79 TEST(EtwTraceProviderTest, Initialize) {
80 EtwTraceProvider provider(kTestProvider);
81
82 EXPECT_EQ(NULL, provider.registration_handle());
83 EXPECT_EQ(NULL, provider.session_handle());
84 EXPECT_EQ(0, provider.enable_flags());
85 EXPECT_EQ(0, provider.enable_level());
86 }
87
88 TEST(EtwTraceProviderTest, Register) {
89 EtwTraceProvider provider(kTestProvider);
90
91 EXPECT_EQ(ERROR_SUCCESS, provider.Register());
92 EXPECT_NE(NULL, provider.registration_handle());
93 EXPECT_EQ(ERROR_SUCCESS, provider.Unregister());
94 EXPECT_EQ(NULL, provider.registration_handle());
95 }
96
97 TEST(EtwTraceProviderTest, RegisterWithNoNameFails) {
98 EtwTraceProvider provider;
99
100 EXPECT_TRUE(provider.Register() != ERROR_SUCCESS);
101 }
102
103 TEST(EtwTraceProviderTest, Enable) {
104 EtwTraceProvider provider(kTestProvider);
105
106 EXPECT_EQ(ERROR_SUCCESS, provider.Register());
107 EXPECT_NE(NULL, provider.registration_handle());
108
109 // No session so far.
110 EXPECT_EQ(NULL, provider.session_handle());
111 EXPECT_EQ(0, provider.enable_flags());
112 EXPECT_EQ(0, provider.enable_level());
113
114 EXPECT_EQ(ERROR_SUCCESS, provider.Unregister());
115 EXPECT_EQ(NULL, provider.registration_handle());
116 }
117
118 } // namespace omaha
OLDNEW
« no previous file with comments | « base/event_trace_provider.cc ('k') | base/exception_barrier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698