| // Copyright 2022 The Tint Authors. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| //////////////////////////////////////////////////////////////////////////////// |
| // File generated by tools/src/cmd/gen |
| // using the template: |
| // src/tint/ast/texel_format_test.cc.tmpl |
| // |
| // Do not modify this file directly |
| //////////////////////////////////////////////////////////////////////////////// |
| |
| #include "src/tint/ast/texel_format.h" |
| |
| #include <string> |
| |
| #include "src/tint/ast/test_helper.h" |
| #include "src/tint/utils/string.h" |
| |
| namespace tint::ast { |
| namespace { |
| |
| namespace parse_print_tests { |
| |
| struct Case { |
| const char* string; |
| TexelFormat value; |
| }; |
| |
| inline std::ostream& operator<<(std::ostream& out, Case c) { |
| return out << "'" << std::string(c.string) << "'"; |
| } |
| |
| static constexpr Case kValidCases[] = { |
| {"r32float", TexelFormat::kR32Float}, {"r32sint", TexelFormat::kR32Sint}, |
| {"r32uint", TexelFormat::kR32Uint}, {"rg32float", TexelFormat::kRg32Float}, |
| {"rg32sint", TexelFormat::kRg32Sint}, {"rg32uint", TexelFormat::kRg32Uint}, |
| {"rgba16float", TexelFormat::kRgba16Float}, {"rgba16sint", TexelFormat::kRgba16Sint}, |
| {"rgba16uint", TexelFormat::kRgba16Uint}, {"rgba32float", TexelFormat::kRgba32Float}, |
| {"rgba32sint", TexelFormat::kRgba32Sint}, {"rgba32uint", TexelFormat::kRgba32Uint}, |
| {"rgba8sint", TexelFormat::kRgba8Sint}, {"rgba8snorm", TexelFormat::kRgba8Snorm}, |
| {"rgba8uint", TexelFormat::kRgba8Uint}, {"rgba8unorm", TexelFormat::kRgba8Unorm}, |
| }; |
| |
| static constexpr Case kInvalidCases[] = { |
| {"rcc2flot", TexelFormat::kInvalid}, {"3flo3", TexelFormat::kInvalid}, |
| {"r32flVat", TexelFormat::kInvalid}, {"r32s1nt", TexelFormat::kInvalid}, |
| {"rq2Jint", TexelFormat::kInvalid}, {"r32sin7ll", TexelFormat::kInvalid}, |
| {"ppqq2unHH", TexelFormat::kInvalid}, {"r3cv", TexelFormat::kInvalid}, |
| {"b2uiGt", TexelFormat::kInvalid}, {"rgvi2float", TexelFormat::kInvalid}, |
| {"rg328WWoat", TexelFormat::kInvalid}, {"rg32lxxMt", TexelFormat::kInvalid}, |
| {"rgXggsnt", TexelFormat::kInvalid}, {"rgXsnu", TexelFormat::kInvalid}, |
| {"rg32s3nt", TexelFormat::kInvalid}, {"rg3Euint", TexelFormat::kInvalid}, |
| {"PP32TTint", TexelFormat::kInvalid}, {"xxg32ddnt", TexelFormat::kInvalid}, |
| {"rgba446float", TexelFormat::kInvalid}, {"SSVVba16float", TexelFormat::kInvalid}, |
| {"rgbRR6float", TexelFormat::kInvalid}, {"rga16Fint", TexelFormat::kInvalid}, |
| {"rgb16sint", TexelFormat::kInvalid}, {"ORVHa16sint", TexelFormat::kInvalid}, |
| {"ryba1uint", TexelFormat::kInvalid}, {"r77ba1nnullrrt", TexelFormat::kInvalid}, |
| {"rgb4006uint", TexelFormat::kInvalid}, {"rboofloat", TexelFormat::kInvalid}, |
| {"rgbaz2loat", TexelFormat::kInvalid}, {"ppga3ii1floa", TexelFormat::kInvalid}, |
| {"XXgba32sint", TexelFormat::kInvalid}, {"IIgb9932nni55t", TexelFormat::kInvalid}, |
| {"rYbaSSrrsiHHat", TexelFormat::kInvalid}, {"rbkk2Hit", TexelFormat::kInvalid}, |
| {"jgba3ugRR", TexelFormat::kInvalid}, {"rgbab2ui", TexelFormat::kInvalid}, |
| {"rgba8sijt", TexelFormat::kInvalid}, {"rba8sint", TexelFormat::kInvalid}, |
| {"rba8sqt", TexelFormat::kInvalid}, {"rgba8NNnom", TexelFormat::kInvalid}, |
| {"rga8vvorm", TexelFormat::kInvalid}, {"rgba8snorQ", TexelFormat::kInvalid}, |
| {"rgbauirf", TexelFormat::kInvalid}, {"rgbajuint", TexelFormat::kInvalid}, |
| {"wNNgbauin2", TexelFormat::kInvalid}, {"rgba8unrm", TexelFormat::kInvalid}, |
| {"rgba8urrorm", TexelFormat::kInvalid}, {"rgba8Gnorm", TexelFormat::kInvalid}, |
| }; |
| |
| using TexelFormatParseTest = testing::TestWithParam<Case>; |
| |
| TEST_P(TexelFormatParseTest, Parse) { |
| const char* string = GetParam().string; |
| TexelFormat expect = GetParam().value; |
| EXPECT_EQ(expect, ParseTexelFormat(string)); |
| } |
| |
| INSTANTIATE_TEST_SUITE_P(ValidCases, TexelFormatParseTest, testing::ValuesIn(kValidCases)); |
| INSTANTIATE_TEST_SUITE_P(InvalidCases, TexelFormatParseTest, testing::ValuesIn(kInvalidCases)); |
| |
| using TexelFormatPrintTest = testing::TestWithParam<Case>; |
| |
| TEST_P(TexelFormatPrintTest, Print) { |
| TexelFormat value = GetParam().value; |
| const char* expect = GetParam().string; |
| EXPECT_EQ(expect, utils::ToString(value)); |
| } |
| |
| INSTANTIATE_TEST_SUITE_P(ValidCases, TexelFormatPrintTest, testing::ValuesIn(kValidCases)); |
| |
| } // namespace parse_print_tests |
| |
| } // namespace |
| } // namespace tint::ast |