/gpu/command_buffer/tests/es3_misc_functions_unittest.cc

http://github.com/chromium/chromium · C++ · 111 lines · 91 code · 13 blank · 7 comment · 3 complexity · fef124e0916a9dfa295eb840ec752ef1 MD5 · raw file

  1. // Copyright 2015 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. #include <GLES2/gl2.h>
  5. #include <GLES2/gl2ext.h>
  6. #include <GLES2/gl2extchromium.h>
  7. #include <GLES3/gl3.h>
  8. #include "base/strings/string_split.h"
  9. #include "base/strings/string_util.h"
  10. #include "gpu/command_buffer/tests/gl_manager.h"
  11. #include "gpu/command_buffer/tests/gl_test_utils.h"
  12. #include "testing/gmock/include/gmock/gmock.h"
  13. #include "testing/gtest/include/gtest/gtest.h"
  14. #include "ui/gl/gl_switches.h"
  15. #define SHADER_VERSION_300(Src) "#version 300 es\n" #Src
  16. namespace gpu {
  17. class OpenGLES3FunctionTest : public testing::Test {
  18. protected:
  19. void SetUp() override {
  20. GLManager::Options options;
  21. options.context_type = CONTEXT_TYPE_OPENGLES3;
  22. gl_.Initialize(options);
  23. }
  24. void TearDown() override { gl_.Destroy(); }
  25. bool IsApplicable() const { return gl_.IsInitialized(); }
  26. GLManager gl_;
  27. };
  28. #if defined(OS_ANDROID)
  29. // Test is failing for Lollipop 64 bit Tester.
  30. // See crbug/550292.
  31. #define MAYBE_GetFragDataLocationInvalid DISABLED_GetFragDataLocationInvalid
  32. #else
  33. #define MAYBE_GetFragDataLocationInvalid GetFragDataLocationInvalid
  34. #endif
  35. TEST_F(OpenGLES3FunctionTest, MAYBE_GetFragDataLocationInvalid) {
  36. if (!IsApplicable()) {
  37. return;
  38. }
  39. // clang-format off
  40. static const char* kVertexShader =
  41. SHADER_VERSION_300(
  42. in vec4 position;
  43. void main() {
  44. gl_Position = position;
  45. });
  46. static const char* kFragColorShader =
  47. SHADER_VERSION_300(
  48. precision mediump float;
  49. uniform vec4 src;
  50. out vec4 FragColor;
  51. void main() {
  52. FragColor = src;
  53. });
  54. // clang-format on
  55. GLuint vsid = GLTestHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader);
  56. GLuint fsid = GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, kFragColorShader);
  57. GLuint program = glCreateProgram();
  58. glAttachShader(program, vsid);
  59. glAttachShader(program, fsid);
  60. glDeleteShader(vsid);
  61. glDeleteShader(fsid);
  62. GLint location = glGetFragDataLocation(program, "FragColor");
  63. EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
  64. EXPECT_EQ(-1, location);
  65. location = glGetFragDataLocation(program, "Unknown");
  66. EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
  67. EXPECT_EQ(-1, location);
  68. glLinkProgram(program);
  69. location = glGetFragDataLocation(program, "FragColor");
  70. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  71. EXPECT_EQ(0, location);
  72. location = glGetFragDataLocation(program, "Unknown");
  73. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  74. EXPECT_EQ(-1, location);
  75. glDeleteProgram(program);
  76. }
  77. TEST_F(OpenGLES3FunctionTest, GetStringiTest) {
  78. if (!IsApplicable()) {
  79. return;
  80. }
  81. std::string extensionString =
  82. reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
  83. std::vector<std::string> extensions =
  84. base::SplitString(extensionString, base::kWhitespaceASCII,
  85. base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
  86. int num_extensions = 0;
  87. glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
  88. EXPECT_EQ(extensions.size(), static_cast<size_t>(num_extensions));
  89. std::set<std::string> extensions_from_string(extensions.begin(),
  90. extensions.end());
  91. std::set<std::string> extensions_from_stringi;
  92. for (int i = 0; i < num_extensions; ++i) {
  93. extensions_from_stringi.insert(
  94. reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i)));
  95. }
  96. EXPECT_EQ(extensions_from_string, extensions_from_stringi);
  97. }
  98. } // namespace gpu