Debian Codegraph @

test/enum_string_mapping_test.cpp

raw
1 // Copyright (c) 2017 Google Inc.
2 // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
3 // reserved.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 // Tests for OpExtension validator rules.
18
19 #include <string>
20 #include <utility>
21 #include <vector>
22
23 #include "gtest/gtest.h"
24 #include "source/table2.h"
25
26 namespace spvtools {
27 namespace {
28
29 using ::testing::Values;
30 using ::testing::ValuesIn;
31
32 using ExtensionTest =
33 ::testing::TestWithParam<std::pair<Extension, std::string>>;
34 using UnknownExtensionTest = ::testing::TestWithParam<std::string>;
35
36 TEST_P(ExtensionTest, TestExtensionFromString) {
37 const std::pair<Extension, std::string>& param = GetParam();
38 const Extension extension = param.first;
39 const std::string extension_str = param.second;
40 Extension result_extension;
41 ASSERT_TRUE(GetExtensionFromString(extension_str.c_str(), &result_extension));
42 EXPECT_EQ(extension, result_extension);
43 }
44
45 TEST_P(ExtensionTest, TestExtensionToString) {
46 const std::pair<Extension, std::string>& param = GetParam();
47 const Extension extension = param.first;
48 const std::string extension_str = param.second;
49 const std::string result_str = ExtensionToString(extension);
50 EXPECT_EQ(extension_str, result_str);
51 }
52
53 TEST_P(UnknownExtensionTest, TestExtensionFromStringFails) {
54 Extension result_extension;
55 ASSERT_FALSE(GetExtensionFromString(GetParam().c_str(), &result_extension));
56 }
57
58 INSTANTIATE_TEST_SUITE_P(
59 AllExtensions, ExtensionTest,
60 ValuesIn(std::vector<std::pair<Extension, std::string>>({
61 {Extension::kSPV_KHR_16bit_storage, "SPV_KHR_16bit_storage"},
62 {Extension::kSPV_KHR_device_group, "SPV_KHR_device_group"},
63 {Extension::kSPV_KHR_multiview, "SPV_KHR_multiview"},
64 {Extension::kSPV_KHR_shader_ballot, "SPV_KHR_shader_ballot"},
65 {Extension::kSPV_KHR_shader_draw_parameters,
66 "SPV_KHR_shader_draw_parameters"},
67 {Extension::kSPV_KHR_subgroup_vote, "SPV_KHR_subgroup_vote"},
68 {Extension::kSPV_NVX_multiview_per_view_attributes,
69 "SPV_NVX_multiview_per_view_attributes"},
70 {Extension::kSPV_NV_geometry_shader_passthrough,
71 "SPV_NV_geometry_shader_passthrough"},
72 {Extension::kSPV_NV_sample_mask_override_coverage,
73 "SPV_NV_sample_mask_override_coverage"},
74 {Extension::kSPV_NV_stereo_view_rendering,
75 "SPV_NV_stereo_view_rendering"},
76 {Extension::kSPV_NV_viewport_array2, "SPV_NV_viewport_array2"},
77 {Extension::kSPV_GOOGLE_decorate_string, "SPV_GOOGLE_decorate_string"},
78 {Extension::kSPV_GOOGLE_hlsl_functionality1,
79 "SPV_GOOGLE_hlsl_functionality1"},
80 {Extension::kSPV_KHR_8bit_storage, "SPV_KHR_8bit_storage"},
81 })));
82
83 INSTANTIATE_TEST_SUITE_P(UnknownExtensions, UnknownExtensionTest,
84 Values("", "SPV_KHR_", "SPV_KHR_device_group_ERROR",
85 /*alphabetically before all extensions*/ "A",
86 /*alphabetically after all extensions*/ "Z",
87 "SPV_ERROR_random_string_hfsdklhlktherh"));
88
89 } // namespace
90 } // namespace spvtools