Path: blob/main/glslc/src/resource_parse_test.cc
1560 views
// Copyright 2017 The Shaderc Authors. All rights reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314#include "resource_parse.h"1516#include <gmock/gmock.h>1718namespace {1920using glslc::ParseResourceSettings;21using glslc::ResourceSetting;22using testing::Eq;2324struct ResourceSettingsCase {25std::string input;26bool success;27std::vector<ResourceSetting> settings;28std::string message;29};3031using ParseResourceSettingsTest = ::testing::TestWithParam<ResourceSettingsCase>;3233TEST_P(ParseResourceSettingsTest, Sample) {34std::vector<ResourceSetting> settings;35std::string err;36const bool succeeded = ParseResourceSettings(GetParam().input, &settings, &err);37EXPECT_THAT(succeeded, Eq(GetParam().success));38EXPECT_THAT(settings, Eq(GetParam().settings));39EXPECT_THAT(err, Eq(GetParam().message));40}4142INSTANTIATE_TEST_SUITE_P(ParseResources, ParseResourceSettingsTest,43::testing::ValuesIn(std::vector<ResourceSettingsCase>{44{"", true, {}, ""},45{" \t \t \n ", true, {}, ""},46{" blorp blam", false, {}, "invalid resource limit: blorp"},47{"MaxLightsxyz", false, {}, "invalid resource limit: MaxLightsxyz"},48{"MaxLights", false, {}, "missing value after limit: MaxLights"},49{"MaxLights x", false, {}, "invalid integer: x"},50{"MaxLights 99x", false, {}, "invalid integer: 99x"},51{"MaxLights 12 blam", false, {}, "invalid resource limit: blam"},52{"MaxLights 12", true, {{shaderc_limit_max_lights, 12}}, ""},53// Test negative number54{"MinProgramTexelOffset -9", true, {{shaderc_limit_min_program_texel_offset, -9}}, ""},55// Test leading, intervening, and trailing whitespace56{" \tMaxLights \n 12 \t ", true, {{shaderc_limit_max_lights, 12}}, ""},57// Test more than one limit setting.58{"MinProgramTexelOffset -10 MaxLights 4", true, {{shaderc_limit_min_program_texel_offset, -10}, {shaderc_limit_max_lights, 4}}, ""},59// Check ignore cases.60{"nonInductiveForLoops", false, {}, "missing value after limit: nonInductiveForLoops"},61{"nonInductiveForLoops 1", true, {}, ""},62{"whileLoops 1", true, {}, ""},63{"doWhileLoops 1", true, {}, ""},64{"generalUniformIndexing 1", true, {}, ""},65{"generalAttributeMatrixVectorIndexing 1", true, {}, ""},66{"generalVaryingIndexing 1", true, {}, ""},67{"generalSamplerIndexing 1", true, {}, ""},68{"generalVariableIndexing 1", true, {}, ""},69{"generalConstantMatrixVectorIndexing 1", true, {}, ""},70// Check an ignore case with a regular case71{"whileLoops 1 MaxLights 99", true, {{shaderc_limit_max_lights, 99}}, ""},72}));7374} // anonymous namespace757677