Home | History | Annotate | Download | only in common
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // This file contains unit tests for gles2 commmands
      6 
      7 #include "testing/gtest/include/gtest/gtest.h"
      8 #include "gpu/command_buffer/common/gles2_cmd_format.h"
      9 
     10 namespace gpu {
     11 namespace gles2 {
     12 
     13 class GLES2FormatTest : public testing::Test {
     14  protected:
     15   static const unsigned char kInitialValue = 0xBD;
     16 
     17   virtual void SetUp() {
     18     memset(buffer_, kInitialValue, sizeof(buffer_));
     19   }
     20 
     21   virtual void TearDown() {
     22   }
     23 
     24   template <typename T>
     25   T* GetBufferAs() {
     26     return static_cast<T*>(static_cast<void*>(&buffer_));
     27   }
     28 
     29   void CheckBytesWritten(
     30       const void* end, size_t expected_size, size_t written_size) {
     31     size_t actual_size = static_cast<const unsigned char*>(end) -
     32         GetBufferAs<const unsigned char>();
     33     EXPECT_LT(actual_size, sizeof(buffer_));
     34     EXPECT_GT(actual_size, 0u);
     35     EXPECT_EQ(expected_size, actual_size);
     36     EXPECT_EQ(kInitialValue, buffer_[written_size]);
     37     EXPECT_NE(kInitialValue, buffer_[written_size - 1]);
     38   }
     39 
     40   void CheckBytesWrittenMatchesExpectedSize(
     41       const void* end, size_t expected_size) {
     42     CheckBytesWritten(end, expected_size, expected_size);
     43   }
     44 
     45  private:
     46   unsigned char buffer_[1024];
     47 };
     48 
     49 // GCC requires these declarations, but MSVC requires they not be present
     50 #ifndef _MSC_VER
     51 const unsigned char GLES2FormatTest::kInitialValue;
     52 #endif
     53 
     54 #include "gpu/command_buffer/common/gles2_cmd_format_test_autogen.h"
     55 
     56 }  // namespace gles2
     57 }  // namespace gpu
     58 
     59