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

Unified Diff: chrome/test/base/mof_data_parser_win.h

Issue 9584017: New test infrastructure for producing verbose logs in failing tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed robert's comments Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/base/mof_data_parser_win.h
diff --git a/chrome/test/base/mof_data_parser_win.h b/chrome/test/base/mof_data_parser_win.h
new file mode 100644
index 0000000000000000000000000000000000000000..7356a65df019f129eee95e051b31382bbb643e7a
--- /dev/null
+++ b/chrome/test/base/mof_data_parser_win.h
@@ -0,0 +1,91 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_TEST_BASE_MOF_DATA_PARSER_WIN_H_
+#define CHROME_TEST_BASE_MOF_DATA_PARSER_WIN_H_
+#pragma once
+
+#include <stddef.h>
+#include <windows.h>
+#include <wmistr.h>
+#include <evntrace.h>
+
+#include "base/basictypes.h"
+#include "base/string_piece.h"
+
+namespace logging_win {
+
+// A parser for Mof data found in an EVENT_TRACE object as formatted by
+// Chromium-related classes. Instances have an implicit cursor that scans the
+// data. Callers invoke Read* methods to extract primitive data types values or
+// pointers to complex data types (arrays and strings). In the latter case, the
+// pointers are only valid for the lifetime of the underlying event.
+class MofDataParser {
+ public:
+ explicit MofDataParser(const EVENT_TRACE* event);
+
+ bool ReadDWORD(DWORD* value) {
+ return ReadPrimitive(value);
+ }
+
+ bool ReadInt(int* value) {
+ return ReadPrimitive(value);
+ }
+
+ bool ReadPointer(intptr_t* value) {
+ return ReadPrimitive(value);
+ }
+
+ // Populates |values| with a pointer to an array of |size| pointer-sized
+ // values in the data.
+ bool ReadPointerArray(DWORD size, const intptr_t** values) {
+ return ReadPrimitiveArray(size, values);
+ }
+
+ // Populates |value| with a pointer to an arbitrary data structure at the
+ // current position.
+ template<typename T> bool ReadStructure(const T** value) {
+ if (length_ < sizeof(**value))
+ return false;
+ *value = reinterpret_cast<const T*>(scan_);
+ Advance(sizeof(**value));
+ return true;
+ }
+
+ // Sets |value| such that it points to a string in the data. Although the
+ // string in the data must be null-terminated, the returned piece may not,
+ // as trailing newlines are removed.
+ bool ReadString(base::StringPiece* value);
+
+ bool empty() { return length_ == 0; }
+
+ private:
+ void Advance(size_t num_bytes) {
+ scan_ += num_bytes;
+ length_ -= num_bytes;
+ }
+
+ template<typename T> bool ReadPrimitive(T* value) {
+ if (length_ < sizeof(*value))
+ return false;
+ *value = *reinterpret_cast<const T*>(scan_);
+ Advance(sizeof(*value));
+ return true;
+ }
+
+ template<typename T> bool ReadPrimitiveArray(DWORD size, const T** values) {
+ if (length_ < sizeof(**values) * size)
+ return false;
+ *values = reinterpret_cast<const T*>(scan_);
+ Advance(sizeof(**values) * size);
+ return true;
+ }
+
+ const uint8* scan_;
+ uint32 length_;
+};
+
+} // namespace logging_win
+
+#endif // CHROME_TEST_BASE_MOF_DATA_PARSER_WIN_H_

Powered by Google App Engine
This is Rietveld 408576698