Debian Codegraph @

libs/bluegl/tests/test_bluegl.cpp

raw
1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <gtest/gtest.h>
18
19 #include <bluegl/BlueGL.h>
20
21 #include "OpenGLSupport.hpp"
22
23 namespace bluegl {
24
25 TEST(BlueGLTest, Initialization) {
26 EXPECT_EQ(0, bind());
27 unbind();
28 }
29
30 TEST(BlueGLTest, GetVersion) {
31 EXPECT_EQ(0, bind());
32 gl::OpenGLContext context = gl::createOpenGLContext();
33 gl::setCurrentOpenGLContext(context);
34
35 GLint major = 0, minor = 0;
36 glGetIntegerv(GL_MAJOR_VERSION, &major);
37 glGetIntegerv(GL_MINOR_VERSION, &minor);
38
39 printf("OpenGL v%d.%d\n", major, minor);
40 gl::destroyOpenGLContext(context);
41 unbind();
42 }
43
44 TEST(BlueGLTest, DoubleInitialization) {
45 int result = bind();
46 EXPECT_EQ(result, bind());
47 unbind();
48 unbind();
49 }
50
51 TEST(BlueGLTest, CallOpenGL) {
52 EXPECT_EQ(0, bind());
53
54 gl::OpenGLContext context = gl::createOpenGLContext();
55 EXPECT_TRUE(context != nullptr);
56
57 gl::setCurrentOpenGLContext(context);
58 EXPECT_TRUE(glGetString(GL_VENDOR) != nullptr);
59
60 gl::destroyOpenGLContext(context);
61 unbind();
62 }
63
64 TEST(BlueGLTest, CallOpenGLDoubleInit) {
65 int result = bind();
66 EXPECT_EQ(result, bind());
67 unbind();
68
69 gl::OpenGLContext context = gl::createOpenGLContext();
70 EXPECT_TRUE(context != nullptr);
71
72 gl::setCurrentOpenGLContext(context);
73 EXPECT_TRUE(glGetString(GL_VENDOR) != nullptr);
74
75 gl::destroyOpenGLContext(context);
76 unbind();
77 }
78
79 TEST(BlueGLTest, CallBindAndGetBound) {
80 EXPECT_EQ(0, bind());
81 gl::OpenGLContext context = gl::createOpenGLContext();
82 gl::setCurrentOpenGLContext(context);
83
84 GLuint texId = 0;
85 glGenTextures(1, &texId);
86 glBindTexture(GL_TEXTURE_2D, texId);
87
88 GLint boundTexId = -1; // different from texId, just to be sure
89 glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundTexId);
90 ASSERT_EQ(texId, boundTexId);
91
92 gl::destroyOpenGLContext(context);
93 unbind();
94 }
95
96 }; // namespace bluegl
97
98 int main(int argc, char** argv) {
99 ::testing::InitGoogleTest(&argc, argv);
100 return RUN_ALL_TESTS();
101 }