tree: e1eae7acd197a0766cfe16f357878407d681160c [path history] [tgz]
  1. capabilities_unittests.cc
  2. formats_gles_unittests.cc
  3. gpu_tracer_gles_unittests.cc
  4. mock_gles.cc
  5. mock_gles.h
  6. mock_gles_unittests.cc
  7. proc_table_gles_unittests.cc
  8. README.md
  9. specialization_constants_unittests.cc
impeller/renderer/backend/gles/test/README.md

MockGLES

This directory contains a mock implementation of the GLES backend.

Most functions are implemented as no-ops, have a default implementation that is not configurable, or just record the call. The latter is useful for testing:

TEST(MockGLES, Example) {
  // Creates a mock GLES implementation and sets it as the current one.
  auto mock_gles = MockGLES::Init();
  auto& gl = mock_gles->GetProcTable();

  // Call the proc table methods as usual, or pass the proc table to a class
  // that needs it.
  gl.PushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION_KHR, 0, -1, "test");
  gl.PopDebugGroupKHR();

  // Method names are recorded and can be inspected.
  //
  // Note that many built-ins, like glGetString, are not recorded (otherwise the // logs would be much bigger and less useful).
  auto calls = mock_gles->GetCapturedCalls();
  EXPECT_EQ(calls, std::vector<std::string>(
                       {"PushDebugGroupKHR", "PopDebugGroupKHR"}));
}

To add a new function, do the following:

  1. Add a new top-level method to mock_gles.cc:

    void glFooBar() {
      recordCall("glFooBar");
    }
    
  2. Edit the kMockResolver, and add a new else if clause:

    + else if (strcmp(name, "glFooBar") == 0) {
    +  return reinterpret_cast<void*>(&glFooBar);
      } else {
       return reinterpret_cast<void*>(&glDoNothing);
      }
    

It‘s possible we’ll want to add a more sophisticated mechanism for mocking besides capturing calls, but this is a good start. PRs welcome!