Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/libshaderc_util/src/version_profile_test.cc
1560 views
1
// Copyright 2017 The Shaderc Authors. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include "libshaderc_util/version_profile.h"
16
17
#include "gmock/gmock.h"
18
19
namespace {
20
21
using shaderc_util::IsKnownVersion;
22
using shaderc_util::ParseVersionProfile;
23
using ::testing::Eq;
24
using ::testing::ValuesIn;
25
26
27
TEST(IsKnownVersionTest, Samples) {
28
EXPECT_TRUE(IsKnownVersion(100));
29
EXPECT_TRUE(IsKnownVersion(110));
30
EXPECT_TRUE(IsKnownVersion(120));
31
EXPECT_TRUE(IsKnownVersion(130));
32
EXPECT_TRUE(IsKnownVersion(140));
33
EXPECT_TRUE(IsKnownVersion(150));
34
EXPECT_TRUE(IsKnownVersion(300));
35
EXPECT_TRUE(IsKnownVersion(330));
36
EXPECT_TRUE(IsKnownVersion(310));
37
EXPECT_TRUE(IsKnownVersion(400));
38
EXPECT_TRUE(IsKnownVersion(410));
39
EXPECT_TRUE(IsKnownVersion(420));
40
EXPECT_TRUE(IsKnownVersion(430));
41
EXPECT_TRUE(IsKnownVersion(440));
42
EXPECT_TRUE(IsKnownVersion(450));
43
EXPECT_TRUE(IsKnownVersion(460));
44
EXPECT_FALSE(IsKnownVersion(101));
45
EXPECT_FALSE(IsKnownVersion(470));
46
}
47
48
49
struct ParseVersionProfileCase {
50
std::string input;
51
bool success;
52
// The following are only used when success is true.
53
int expected_version;
54
EProfile expected_profile;
55
};
56
57
using ParseVersionProfileTest = ::testing::TestWithParam<ParseVersionProfileCase>;
58
59
TEST_P(ParseVersionProfileTest, Sample) {
60
int version = 0;
61
EProfile profile = EBadProfile;
62
const bool result = ParseVersionProfile(GetParam().input, &version, &profile);
63
EXPECT_THAT(result, GetParam().success);
64
if (result) {
65
EXPECT_THAT(version, GetParam().expected_version);
66
EXPECT_THAT(profile, GetParam().expected_profile);
67
}
68
}
69
70
71
// For OpenGL ES GLSL (ESSL) versions, see
72
// https://www.khronos.org/registry/OpenGL/index_e.php
73
74
INSTANTIATE_TEST_SUITE_P(OpenGLESCases, ParseVersionProfileTest,
75
ValuesIn(std::vector<ParseVersionProfileCase>{
76
{"100es", true, 100, EEsProfile},
77
{"300es", true, 300, EEsProfile},
78
{"310es", true, 310, EEsProfile},
79
{"320es", true, 320, EEsProfile},
80
{"99es", false, 0, EBadProfile},
81
{"500es", false, 0, EBadProfile},
82
}));
83
84
// For OpenGL GLSL versions, see
85
// https://www.khronos.org/registry/OpenGL/index_gl.php
86
87
INSTANTIATE_TEST_SUITE_P(OpenGLBlankCases, ParseVersionProfileTest,
88
ValuesIn(std::vector<ParseVersionProfileCase>{
89
{"110", true, 110, ENoProfile},
90
{"120", true, 120, ENoProfile},
91
{"130", true, 130, ENoProfile},
92
{"140", true, 140, ENoProfile},
93
{"150", true, 150, ENoProfile},
94
{"330", true, 330, ENoProfile},
95
{"400", true, 400, ENoProfile},
96
{"410", true, 410, ENoProfile},
97
{"420", true, 420, ENoProfile},
98
{"430", true, 430, ENoProfile},
99
{"440", true, 440, ENoProfile},
100
{"450", true, 450, ENoProfile},
101
{"460", true, 460, ENoProfile},
102
{"99", false, 0, EBadProfile},
103
{"500", false, 0, EBadProfile},
104
}));
105
106
INSTANTIATE_TEST_SUITE_P(OpenGLCoreCases, ParseVersionProfileTest,
107
ValuesIn(std::vector<ParseVersionProfileCase>{
108
{"320core", true, 320, ECoreProfile},
109
{"330core", true, 330, ECoreProfile},
110
{"400core", true, 400, ECoreProfile},
111
{"410core", true, 410, ECoreProfile},
112
{"420core", true, 420, ECoreProfile},
113
{"430core", true, 430, ECoreProfile},
114
{"440core", true, 440, ECoreProfile},
115
{"450core", true, 450, ECoreProfile},
116
{"460core", true, 460, ECoreProfile},
117
}));
118
119
INSTANTIATE_TEST_SUITE_P(
120
OpenGLCompatibilityCases, ParseVersionProfileTest,
121
ValuesIn(std::vector<ParseVersionProfileCase>{
122
{"320compatibility", true, 320, ECompatibilityProfile},
123
{"330compatibility", true, 330, ECompatibilityProfile},
124
{"400compatibility", true, 400, ECompatibilityProfile},
125
{"410compatibility", true, 410, ECompatibilityProfile},
126
{"420compatibility", true, 420, ECompatibilityProfile},
127
{"430compatibility", true, 430, ECompatibilityProfile},
128
{"440compatibility", true, 440, ECompatibilityProfile},
129
{"450compatibility", true, 450, ECompatibilityProfile},
130
{"460compatibility", true, 460, ECompatibilityProfile},
131
}));
132
133
} // anonymous namespace
134
135