summaryrefslogtreecommitdiff
path: root/stream-servers/tests/GLSnapshotRasterization_unittest.cpp
blob: 3f016af5bb60adda0a49aeeba71a0ef937ee9920 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (C) 2018 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "GLSnapshotTesting.h"
#include "OpenGLTestContext.h"

#include <gtest/gtest.h>

namespace emugl {

// Line width settings to attempt
static const GLfloat kGLES2TestLineWidths[] = {2.0f};

class SnapshotGlLineWidthTest : public SnapshotSetValueTest<GLfloat>,
                                public ::testing::WithParamInterface<GLfloat> {
    void stateCheck(GLfloat expected) override {
        GLfloat lineWidthRange[2];
        gl->glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, lineWidthRange);

        GLfloat lineWidth;
        gl->glGetFloatv(GL_LINE_WIDTH, &lineWidth);

        if (expected <= lineWidthRange[1]) {
            EXPECT_EQ(expected, lineWidth);
        }
    }
    void stateChange() override { gl->glLineWidth(GetParam()); }
};

TEST_P(SnapshotGlLineWidthTest, SetLineWidth) {
    setExpectedValues(1.0f, GetParam());
    doCheckedSnapshot();
}

INSTANTIATE_TEST_SUITE_P(GLES2SnapshotRasterization,
                         SnapshotGlLineWidthTest,
                         ::testing::ValuesIn(kGLES2TestLineWidths));

class SnapshotGlCullFaceTest : public SnapshotSetValueTest<GLenum>,
                               public ::testing::WithParamInterface<GLenum> {
    void stateCheck(GLenum expected) override {
        EXPECT_TRUE(compareGlobalGlInt(gl, GL_CULL_FACE_MODE, expected));
    }
    void stateChange() override { gl->glCullFace(GetParam()); }
};

TEST_P(SnapshotGlCullFaceTest, SetCullFaceMode) {
    setExpectedValues(GL_BACK, GetParam());
    doCheckedSnapshot();
}

INSTANTIATE_TEST_SUITE_P(GLES2SnapshotRasterization,
                         SnapshotGlCullFaceTest,
                         ::testing::ValuesIn(kGLES2CullFaceModes));

class SnapshotGlFrontFaceTest : public SnapshotSetValueTest<GLenum>,
                                public ::testing::WithParamInterface<GLenum> {
    void stateCheck(GLenum expected) override {
        EXPECT_TRUE(compareGlobalGlInt(gl, GL_FRONT_FACE, expected));
    }
    void stateChange() override { gl->glFrontFace(GetParam()); }
};

TEST_P(SnapshotGlFrontFaceTest, SetFrontFaceMode) {
    setExpectedValues(GL_CCW, GetParam());
    doCheckedSnapshot();
}

INSTANTIATE_TEST_SUITE_P(GLES2SnapshotRasterization,
                         SnapshotGlFrontFaceTest,
                         ::testing::ValuesIn(kGLES2FrontFaceModes));

class SnapshotGlPolygonOffsetTest
    : public SnapshotSetValueTest<GLfloat*> {
    void stateCheck(GLfloat* expected) override {
        EXPECT_TRUE(compareGlobalGlFloat(gl, GL_POLYGON_OFFSET_FACTOR,
                                         expected[0]));
        EXPECT_TRUE(
                compareGlobalGlFloat(gl, GL_POLYGON_OFFSET_UNITS, expected[1]));
    }
    void stateChange() override {
        gl->glPolygonOffset(0.5f, 0.5f);
    }
};

TEST_F(SnapshotGlPolygonOffsetTest, SetPolygonOffset) {
    GLfloat defaultOffset[2] = {0.0f, 0.0f};
    GLfloat testOffset[2] = {0.5f, 0.5f};
    setExpectedValues(defaultOffset, testOffset);
    doCheckedSnapshot();
}


}  // namespace emugl