blob: 184d68acbf94d6c6e1575a1ce03cea4634a8bfba [file] [log] [blame]
Austin Engcc2516a2023-10-17 20:57:54 +00001// Copyright 2022 The Dawn & Tint Authors
Ben Claytonfe8e6ee2022-07-27 22:21:30 +00002//
Austin Engcc2516a2023-10-17 20:57:54 +00003// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are met:
Ben Claytonfe8e6ee2022-07-27 22:21:30 +00005//
Austin Engcc2516a2023-10-17 20:57:54 +00006// 1. Redistributions of source code must retain the above copyright notice, this
7// list of conditions and the following disclaimer.
Ben Claytonfe8e6ee2022-07-27 22:21:30 +00008//
Austin Engcc2516a2023-10-17 20:57:54 +00009// 2. Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12//
13// 3. Neither the name of the copyright holder nor the names of its
14// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Ben Claytonfe8e6ee2022-07-27 22:21:30 +000027
28////////////////////////////////////////////////////////////////////////////////
Ben Clayton57ded6a2023-08-22 13:22:22 +000029// File generated by 'tools/src/cmd/gen' using the template:
Ben Claytoncd52f382023-08-07 13:11:08 +000030// src/tint/lang/core/builtin_value_test.cc.tmpl
Ben Claytonfe8e6ee2022-07-27 22:21:30 +000031//
Ben Clayton57ded6a2023-08-22 13:22:22 +000032// To regenerate run: './tools/run gen'
33//
34// Do not modify this file directly
Ben Claytonfe8e6ee2022-07-27 22:21:30 +000035////////////////////////////////////////////////////////////////////////////////
36
Ben Claytoncd52f382023-08-07 13:11:08 +000037#include "src/tint/lang/core/builtin_value.h"
dan sinclair63925792023-02-17 21:56:35 +000038
39#include <gtest/gtest.h>
Ben Claytonfe8e6ee2022-07-27 22:21:30 +000040
41#include <string>
42
dan sinclair22b4dd22023-07-21 00:40:07 +000043#include "src/tint/utils/text/string.h"
Ben Claytonfe8e6ee2022-07-27 22:21:30 +000044
Ben Claytoncd52f382023-08-07 13:11:08 +000045namespace tint::core {
Ben Claytonfe8e6ee2022-07-27 22:21:30 +000046namespace {
47
48namespace parse_print_tests {
49
50struct Case {
51 const char* string;
52 BuiltinValue value;
53};
54
55inline std::ostream& operator<<(std::ostream& out, Case c) {
56 return out << "'" << std::string(c.string) << "'";
57}
58
59static constexpr Case kValidCases[] = {
Ben Clayton4d3ff972023-02-21 17:33:54 +000060 {"__point_size", BuiltinValue::kPointSize},
Jiawei Shao2918c422024-08-15 00:55:19 +000061 {"clip_distances", BuiltinValue::kClipDistances},
Ben Claytonfe8e6ee2022-07-27 22:21:30 +000062 {"frag_depth", BuiltinValue::kFragDepth},
Ben Claytondb368f12022-10-11 18:26:18 +000063 {"front_facing", BuiltinValue::kFrontFacing},
64 {"global_invocation_id", BuiltinValue::kGlobalInvocationId},
65 {"instance_index", BuiltinValue::kInstanceIndex},
Ben Claytonfe8e6ee2022-07-27 22:21:30 +000066 {"local_invocation_id", BuiltinValue::kLocalInvocationId},
67 {"local_invocation_index", BuiltinValue::kLocalInvocationIndex},
Ben Claytonfe8e6ee2022-07-27 22:21:30 +000068 {"num_workgroups", BuiltinValue::kNumWorkgroups},
Ben Claytondb368f12022-10-11 18:26:18 +000069 {"position", BuiltinValue::kPosition},
Ben Claytonfe8e6ee2022-07-27 22:21:30 +000070 {"sample_index", BuiltinValue::kSampleIndex},
71 {"sample_mask", BuiltinValue::kSampleMask},
James Priceae32ef42023-08-01 15:01:32 +000072 {"subgroup_invocation_id", BuiltinValue::kSubgroupInvocationId},
73 {"subgroup_size", BuiltinValue::kSubgroupSize},
Ben Claytondb368f12022-10-11 18:26:18 +000074 {"vertex_index", BuiltinValue::kVertexIndex},
75 {"workgroup_id", BuiltinValue::kWorkgroupId},
Ben Claytonfe8e6ee2022-07-27 22:21:30 +000076};
77
78static constexpr Case kInvalidCases[] = {
Ben Clayton4d3ff972023-02-21 17:33:54 +000079 {"_ccpoint_siz", BuiltinValue::kUndefined},
80 {"_3poi_ile", BuiltinValue::kUndefined},
81 {"__poiVt_size", BuiltinValue::kUndefined},
Jiawei Shao2918c422024-08-15 00:55:19 +000082 {"clip1distances", BuiltinValue::kUndefined},
83 {"cqqiJ_distanes", BuiltinValue::kUndefined},
84 {"clip_dllstance77", BuiltinValue::kUndefined},
85 {"frqqgppepHHh", BuiltinValue::kUndefined},
86 {"fv_dcpt", BuiltinValue::kUndefined},
87 {"frabGdeth", BuiltinValue::kUndefined},
88 {"front_facvnii", BuiltinValue::kUndefined},
89 {"frWWnt_faci8g", BuiltinValue::kUndefined},
90 {"fxxonM_facig", BuiltinValue::kUndefined},
91 {"gXobalgginvocationid", BuiltinValue::kUndefined},
92 {"goVal_uvocatioX_id", BuiltinValue::kUndefined},
93 {"global_in3ocation_id", BuiltinValue::kUndefined},
94 {"instancE_index", BuiltinValue::kUndefined},
95 {"nsTTance_PPndex", BuiltinValue::kUndefined},
96 {"nstancxx_indddx", BuiltinValue::kUndefined},
97 {"local_invocation_i44", BuiltinValue::kUndefined},
98 {"local_invoVVatSSon_id", BuiltinValue::kUndefined},
99 {"local_inRoctionR2id", BuiltinValue::kUndefined},
100 {"local_in9oation_iFdex", BuiltinValue::kUndefined},
101 {"local_invocation_inde", BuiltinValue::kUndefined},
102 {"local_OOnvoVtiRRn_index", BuiltinValue::kUndefined},
103 {"num_workgyups", BuiltinValue::kUndefined},
104 {"num_Glr77rnngroups", BuiltinValue::kUndefined},
105 {"num_wo04kgroups", BuiltinValue::kUndefined},
106 {"osooon", BuiltinValue::kUndefined},
107 {"posizzn", BuiltinValue::kUndefined},
108 {"poiippt1o", BuiltinValue::kUndefined},
109 {"sample_iXXdex", BuiltinValue::kUndefined},
110 {"5nnample_99IIdex", BuiltinValue::kUndefined},
111 {"samYlaaHHrrndeSS", BuiltinValue::kUndefined},
112 {"aHkk_mask", BuiltinValue::kUndefined},
113 {"jRRmpl_gsk", BuiltinValue::kUndefined},
114 {"smple_mbk", BuiltinValue::kUndefined},
115 {"subgroupjinvocation_id", BuiltinValue::kUndefined},
116 {"subgroup_invocaion_id", BuiltinValue::kUndefined},
117 {"subroup_inqocatin_id", BuiltinValue::kUndefined},
118 {"subNNoup_size", BuiltinValue::kUndefined},
119 {"subgrupsizvv", BuiltinValue::kUndefined},
120 {"sugroup_sizQQ", BuiltinValue::kUndefined},
121 {"vrtexinderf", BuiltinValue::kUndefined},
122 {"vertex_indjx", BuiltinValue::kUndefined},
123 {"v82wNNex_idex", BuiltinValue::kUndefined},
124 {"wrkgroup_id", BuiltinValue::kUndefined},
125 {"workgrrrup_id", BuiltinValue::kUndefined},
126 {"wGrkgroup_id", BuiltinValue::kUndefined},
Ben Claytonfe8e6ee2022-07-27 22:21:30 +0000127};
128
129using BuiltinValueParseTest = testing::TestWithParam<Case>;
130
131TEST_P(BuiltinValueParseTest, Parse) {
132 const char* string = GetParam().string;
133 BuiltinValue expect = GetParam().value;
134 EXPECT_EQ(expect, ParseBuiltinValue(string));
135}
136
137INSTANTIATE_TEST_SUITE_P(ValidCases, BuiltinValueParseTest, testing::ValuesIn(kValidCases));
138INSTANTIATE_TEST_SUITE_P(InvalidCases, BuiltinValueParseTest, testing::ValuesIn(kInvalidCases));
139
140using BuiltinValuePrintTest = testing::TestWithParam<Case>;
141
142TEST_P(BuiltinValuePrintTest, Print) {
143 BuiltinValue value = GetParam().value;
144 const char* expect = GetParam().string;
Ben Clayton3c54ba52023-11-28 21:36:08 +0000145 EXPECT_EQ(expect, ToString(value));
Ben Claytonfe8e6ee2022-07-27 22:21:30 +0000146}
147
148INSTANTIATE_TEST_SUITE_P(ValidCases, BuiltinValuePrintTest, testing::ValuesIn(kValidCases));
149
150} // namespace parse_print_tests
151
152} // namespace
Ben Claytoncd52f382023-08-07 13:11:08 +0000153} // namespace tint::core