Flutter Engine
The Flutter Engine
mock_gles.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_TEST_MOCK_GLES_H_
6#define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_TEST_MOCK_GLES_H_
7
8#include <memory>
9#include <optional>
10
12
13namespace impeller {
14namespace testing {
15
17
18/// @brief Provides a mocked version of the |ProcTableGLES| class.
19///
20/// Typically, Open GLES at runtime will be provided the host's GLES bindings
21/// (as function pointers). This class maintains a set of function pointers that
22/// appear to be GLES functions, but are actually just stubs that record
23/// invocations.
24///
25/// See `README.md` for more information.
26class MockGLES final {
27 public:
28 /// @brief Returns an initialized |MockGLES| instance.
29 ///
30 /// This method overwrites mocked global GLES function pointers to record
31 /// invocations on this instance of |MockGLES|. As such, it should only be
32 /// called once per test.
33 static std::shared_ptr<MockGLES> Init(
34 const std::optional<std::vector<const unsigned char*>>& extensions =
35 std::nullopt,
36 const char* version_string = "OpenGL ES 3.0",
38
39 /// @brief Returns a configured |ProcTableGLES| instance.
40 const ProcTableGLES& GetProcTable() const { return proc_table_; }
41
42 /// @brief Returns a vector of the names of all recorded calls.
43 ///
44 /// Calls are cleared after this method is called.
45 std::vector<std::string> GetCapturedCalls() {
46 std::vector<std::string> calls = captured_calls_;
47 captured_calls_.clear();
48 return calls;
49 }
50
51 ~MockGLES();
52
53 private:
54 friend void RecordGLCall(const char* name);
55
57
58 void RecordCall(const char* name) { captured_calls_.emplace_back(name); }
59
60 ProcTableGLES proc_table_;
61 std::vector<std::string> captured_calls_;
62
63 MockGLES(const MockGLES&) = delete;
64
65 MockGLES& operator=(const MockGLES&) = delete;
66};
67
68} // namespace testing
69} // namespace impeller
70
71#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_TEST_MOCK_GLES_H_
std::function< void *(const char *function_name)> Resolver
Provides a mocked version of the |ProcTableGLES| class.
Definition: mock_gles.h:26
static std::shared_ptr< MockGLES > Init(const std::optional< std::vector< const unsigned char * > > &extensions=std::nullopt, const char *version_string="OpenGL ES 3.0", ProcTableGLES::Resolver resolver=kMockResolverGLES)
Returns an initialized |MockGLES| instance.
Definition: mock_gles.cc:166
friend void RecordGLCall(const char *name)
Definition: mock_gles.cc:29
std::vector< std::string > GetCapturedCalls()
Returns a vector of the names of all recorded calls.
Definition: mock_gles.h:45
const ProcTableGLES & GetProcTable() const
Returns a configured |ProcTableGLES| instance.
Definition: mock_gles.h:40
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
const ProcTableGLES::Resolver kMockResolverGLES
Definition: mock_gles.cc:180