Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
proc_table_gles_unittests.cc
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#include <optional>
6
7#include "flutter/testing/testing.h" // IWYU pragma: keep
8#include "gmock/gmock.h"
9#include "gtest/gtest.h"
12
13namespace impeller {
14namespace testing {
15
16using ::testing::_;
17
18#define EXPECT_AVAILABLE(proc_ivar) \
19 EXPECT_TRUE(mock_gles->GetProcTable().proc_ivar.IsAvailable());
20#define EXPECT_UNAVAILABLE(proc_ivar) \
21 EXPECT_FALSE(mock_gles->GetProcTable().proc_ivar.IsAvailable());
22
23TEST(ProcTableGLES, ResolvesCorrectClearDepthProcOnES) {
24 auto mock_gles = MockGLES::Init(std::nullopt, "OpenGL ES 3.0");
25 EXPECT_TRUE(mock_gles->GetProcTable().GetDescription()->IsES());
26
29}
30
31TEST(ProcTableGLES, ResolvesCorrectClearDepthProcOnDesktopGL) {
32 auto mock_gles = MockGLES::Init(std::nullopt, "OpenGL 4.0");
33 EXPECT_FALSE(mock_gles->GetProcTable().GetDescription()->IsES());
34
37}
38
39TEST(ProcTableGLES, CheckFrameBufferStatusDebugOnly) {
40 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
41#ifdef IMPELLER_DEBUG
42 EXPECT_CALL(*mock_gles_impl, CheckFramebufferStatus(_)).Times(1);
43#else
44 EXPECT_CALL(*mock_gles_impl, CheckFramebufferStatus(_)).Times(0);
45#endif
46 auto mock_gles = MockGLES::Init(std::move(mock_gles_impl));
47 mock_gles->GetProcTable().CheckFramebufferStatusDebug(0);
48}
49
50TEST(GLErrorToString, ReturnsCorrectStringForKnownErrors) {
51 EXPECT_EQ(GLErrorToString(GL_NO_ERROR), "GL_NO_ERROR");
52 EXPECT_EQ(GLErrorToString(GL_INVALID_ENUM), "GL_INVALID_ENUM");
53 EXPECT_EQ(GLErrorToString(GL_INVALID_VALUE), "GL_INVALID_VALUE");
54 EXPECT_EQ(GLErrorToString(GL_INVALID_OPERATION), "GL_INVALID_OPERATION");
55 EXPECT_EQ(GLErrorToString(GL_INVALID_FRAMEBUFFER_OPERATION),
56 "GL_INVALID_FRAMEBUFFER_OPERATION");
57 EXPECT_EQ(GLErrorToString(GL_FRAMEBUFFER_COMPLETE),
58 "GL_FRAMEBUFFER_COMPLETE");
59 EXPECT_EQ(GLErrorToString(GL_OUT_OF_MEMORY), "GL_OUT_OF_MEMORY");
60}
61
62TEST(GLErrorToString, ReturnsUnknownForInvalidError) {
63 // Test with an invalid error code
64 GLenum invalid_error = 0x9999;
65 EXPECT_EQ(GLErrorToString(invalid_error), "Unknown.");
66}
67
68TEST(GLErrorToString, ReturnValueIsValidStringView) {
69 // Test that the returned string_view is valid and non-empty
70 auto result = GLErrorToString(GL_NO_ERROR);
71 EXPECT_FALSE(result.empty());
72 EXPECT_NE(result.data(), nullptr);
73
74 // Test that we can compare with string literals
75 EXPECT_TRUE(result == "GL_NO_ERROR");
76}
77
78TEST(GLProc, NameFieldWorksWithStringView) {
79 GLProc<void()> proc;
80
81 // Test setting name with string literal
82 const char* literal = "glTestFunction";
83 proc.name = literal;
84
85 EXPECT_EQ(proc.name, "glTestFunction");
86 EXPECT_FALSE(proc.name.empty());
87
88 // Test that the string_view properly references the original data
89 EXPECT_EQ(proc.name.data(), literal);
90}
91
92} // namespace testing
93} // namespace impeller
static std::shared_ptr< MockGLES > Init(std::unique_ptr< MockGLESImpl > impl, const std::optional< std::vector< const char * > > &extensions=std::nullopt)
Definition mock_gles.cc:260
TEST(FrameTimingsRecorderTest, RecordVsync)
std::string_view GLErrorToString(GLenum value)
#define FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC(PROC)
#define FOR_EACH_IMPELLER_ES_ONLY_PROC(PROC)
#define EXPECT_AVAILABLE(proc_ivar)
#define EXPECT_UNAVAILABLE(proc_ivar)
std::string_view name