From 06a62108a4c76a6457ea245a1c88100edac6908e Mon Sep 17 00:00:00 2001 From: "gman@chromium.org" Date: Thu, 8 Sep 2011 07:34:43 +0000 Subject: Fix GPU cmd tests so they pass ASAN TEST=unit tests BUG=95115 R=apatrick@chromium.org Review URL: http://codereview.chromium.org/7789021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100116 0039d316-1c4b-4281-b951-d872f2087c98 --- gpu/command_buffer/common/gles2_cmd_format_test.cc | 43 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'gpu/command_buffer/common/gles2_cmd_format_test.cc') diff --git a/gpu/command_buffer/common/gles2_cmd_format_test.cc b/gpu/command_buffer/common/gles2_cmd_format_test.cc index 78817a5..396ccb3 100644 --- a/gpu/command_buffer/common/gles2_cmd_format_test.cc +++ b/gpu/command_buffer/common/gles2_cmd_format_test.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -10,6 +10,47 @@ namespace gpu { namespace gles2 { +class GLES2FormatTest : public testing::Test { + protected: + static const unsigned char kInitialValue = 0xBD; + + virtual void SetUp() { + memset(buffer_, kInitialValue, sizeof(buffer_)); + } + + virtual void TearDown() { + } + + template + T* GetBufferAs() { + return static_cast(static_cast(&buffer_)); + } + + void CheckBytesWritten( + const void* end, size_t expected_size, size_t written_size) { + size_t actual_size = static_cast(end) - + GetBufferAs(); + EXPECT_LT(actual_size, sizeof(buffer_)); + EXPECT_GT(actual_size, 0u); + EXPECT_EQ(expected_size, actual_size); + EXPECT_EQ(kInitialValue, buffer_[written_size]); + EXPECT_NE(kInitialValue, buffer_[written_size - 1]); + } + + void CheckBytesWrittenMatchesExpectedSize( + const void* end, size_t expected_size) { + CheckBytesWritten(end, expected_size, expected_size); + } + + private: + unsigned char buffer_[1024]; +}; + +// GCC requires these declarations, but MSVC requires they not be present +#ifndef _MSC_VER +const unsigned char GLES2FormatTest::kInitialValue; +#endif + #include "gpu/command_buffer/common/gles2_cmd_format_test_autogen.h" } // namespace gles2 -- cgit v1.1