Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/src/resource_parse_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 "resource_parse.h"
16
17
#include <gmock/gmock.h>
18
19
namespace {
20
21
using glslc::ParseResourceSettings;
22
using glslc::ResourceSetting;
23
using testing::Eq;
24
25
struct ResourceSettingsCase {
26
std::string input;
27
bool success;
28
std::vector<ResourceSetting> settings;
29
std::string message;
30
};
31
32
using ParseResourceSettingsTest = ::testing::TestWithParam<ResourceSettingsCase>;
33
34
TEST_P(ParseResourceSettingsTest, Sample) {
35
std::vector<ResourceSetting> settings;
36
std::string err;
37
const bool succeeded = ParseResourceSettings(GetParam().input, &settings, &err);
38
EXPECT_THAT(succeeded, Eq(GetParam().success));
39
EXPECT_THAT(settings, Eq(GetParam().settings));
40
EXPECT_THAT(err, Eq(GetParam().message));
41
}
42
43
INSTANTIATE_TEST_SUITE_P(ParseResources, ParseResourceSettingsTest,
44
::testing::ValuesIn(std::vector<ResourceSettingsCase>{
45
{"", true, {}, ""},
46
{" \t \t \n ", true, {}, ""},
47
{" blorp blam", false, {}, "invalid resource limit: blorp"},
48
{"MaxLightsxyz", false, {}, "invalid resource limit: MaxLightsxyz"},
49
{"MaxLights", false, {}, "missing value after limit: MaxLights"},
50
{"MaxLights x", false, {}, "invalid integer: x"},
51
{"MaxLights 99x", false, {}, "invalid integer: 99x"},
52
{"MaxLights 12 blam", false, {}, "invalid resource limit: blam"},
53
{"MaxLights 12", true, {{shaderc_limit_max_lights, 12}}, ""},
54
// Test negative number
55
{"MinProgramTexelOffset -9", true, {{shaderc_limit_min_program_texel_offset, -9}}, ""},
56
// Test leading, intervening, and trailing whitespace
57
{" \tMaxLights \n 12 \t ", true, {{shaderc_limit_max_lights, 12}}, ""},
58
// Test more than one limit setting.
59
{"MinProgramTexelOffset -10 MaxLights 4", true, {{shaderc_limit_min_program_texel_offset, -10}, {shaderc_limit_max_lights, 4}}, ""},
60
// Check ignore cases.
61
{"nonInductiveForLoops", false, {}, "missing value after limit: nonInductiveForLoops"},
62
{"nonInductiveForLoops 1", true, {}, ""},
63
{"whileLoops 1", true, {}, ""},
64
{"doWhileLoops 1", true, {}, ""},
65
{"generalUniformIndexing 1", true, {}, ""},
66
{"generalAttributeMatrixVectorIndexing 1", true, {}, ""},
67
{"generalVaryingIndexing 1", true, {}, ""},
68
{"generalSamplerIndexing 1", true, {}, ""},
69
{"generalVariableIndexing 1", true, {}, ""},
70
{"generalConstantMatrixVectorIndexing 1", true, {}, ""},
71
// Check an ignore case with a regular case
72
{"whileLoops 1 MaxLights 99", true, {{shaderc_limit_max_lights, 99}}, ""},
73
}));
74
75
} // anonymous namespace
76
77