Path: blob/main/libshaderc_util/src/version_profile_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 "libshaderc_util/version_profile.h"1516#include "gmock/gmock.h"1718namespace {1920using shaderc_util::IsKnownVersion;21using shaderc_util::ParseVersionProfile;22using ::testing::Eq;23using ::testing::ValuesIn;242526TEST(IsKnownVersionTest, Samples) {27EXPECT_TRUE(IsKnownVersion(100));28EXPECT_TRUE(IsKnownVersion(110));29EXPECT_TRUE(IsKnownVersion(120));30EXPECT_TRUE(IsKnownVersion(130));31EXPECT_TRUE(IsKnownVersion(140));32EXPECT_TRUE(IsKnownVersion(150));33EXPECT_TRUE(IsKnownVersion(300));34EXPECT_TRUE(IsKnownVersion(330));35EXPECT_TRUE(IsKnownVersion(310));36EXPECT_TRUE(IsKnownVersion(400));37EXPECT_TRUE(IsKnownVersion(410));38EXPECT_TRUE(IsKnownVersion(420));39EXPECT_TRUE(IsKnownVersion(430));40EXPECT_TRUE(IsKnownVersion(440));41EXPECT_TRUE(IsKnownVersion(450));42EXPECT_TRUE(IsKnownVersion(460));43EXPECT_FALSE(IsKnownVersion(101));44EXPECT_FALSE(IsKnownVersion(470));45}464748struct ParseVersionProfileCase {49std::string input;50bool success;51// The following are only used when success is true.52int expected_version;53EProfile expected_profile;54};5556using ParseVersionProfileTest = ::testing::TestWithParam<ParseVersionProfileCase>;5758TEST_P(ParseVersionProfileTest, Sample) {59int version = 0;60EProfile profile = EBadProfile;61const bool result = ParseVersionProfile(GetParam().input, &version, &profile);62EXPECT_THAT(result, GetParam().success);63if (result) {64EXPECT_THAT(version, GetParam().expected_version);65EXPECT_THAT(profile, GetParam().expected_profile);66}67}686970// For OpenGL ES GLSL (ESSL) versions, see71// https://www.khronos.org/registry/OpenGL/index_e.php7273INSTANTIATE_TEST_SUITE_P(OpenGLESCases, ParseVersionProfileTest,74ValuesIn(std::vector<ParseVersionProfileCase>{75{"100es", true, 100, EEsProfile},76{"300es", true, 300, EEsProfile},77{"310es", true, 310, EEsProfile},78{"320es", true, 320, EEsProfile},79{"99es", false, 0, EBadProfile},80{"500es", false, 0, EBadProfile},81}));8283// For OpenGL GLSL versions, see84// https://www.khronos.org/registry/OpenGL/index_gl.php8586INSTANTIATE_TEST_SUITE_P(OpenGLBlankCases, ParseVersionProfileTest,87ValuesIn(std::vector<ParseVersionProfileCase>{88{"110", true, 110, ENoProfile},89{"120", true, 120, ENoProfile},90{"130", true, 130, ENoProfile},91{"140", true, 140, ENoProfile},92{"150", true, 150, ENoProfile},93{"330", true, 330, ENoProfile},94{"400", true, 400, ENoProfile},95{"410", true, 410, ENoProfile},96{"420", true, 420, ENoProfile},97{"430", true, 430, ENoProfile},98{"440", true, 440, ENoProfile},99{"450", true, 450, ENoProfile},100{"460", true, 460, ENoProfile},101{"99", false, 0, EBadProfile},102{"500", false, 0, EBadProfile},103}));104105INSTANTIATE_TEST_SUITE_P(OpenGLCoreCases, ParseVersionProfileTest,106ValuesIn(std::vector<ParseVersionProfileCase>{107{"320core", true, 320, ECoreProfile},108{"330core", true, 330, ECoreProfile},109{"400core", true, 400, ECoreProfile},110{"410core", true, 410, ECoreProfile},111{"420core", true, 420, ECoreProfile},112{"430core", true, 430, ECoreProfile},113{"440core", true, 440, ECoreProfile},114{"450core", true, 450, ECoreProfile},115{"460core", true, 460, ECoreProfile},116}));117118INSTANTIATE_TEST_SUITE_P(119OpenGLCompatibilityCases, ParseVersionProfileTest,120ValuesIn(std::vector<ParseVersionProfileCase>{121{"320compatibility", true, 320, ECompatibilityProfile},122{"330compatibility", true, 330, ECompatibilityProfile},123{"400compatibility", true, 400, ECompatibilityProfile},124{"410compatibility", true, 410, ECompatibilityProfile},125{"420compatibility", true, 420, ECompatibilityProfile},126{"430compatibility", true, 430, ECompatibilityProfile},127{"440compatibility", true, 440, ECompatibilityProfile},128{"450compatibility", true, 450, ECompatibilityProfile},129{"460compatibility", true, 460, ECompatibilityProfile},130}));131132} // anonymous namespace133134135