1{{- /*
2 * CompMethod generates comparison method constant from a RequiredMeasurement
3 */}}
4{{- define "CompMethod" -}}
5    {{- $c :=.GetComparison }}
6    {{- $mt :=.GetMeasurementType }}
7    {{- if eq $mt.String "MEASUREMENT_TYPE_BOOL" -}}BOOLEAN
8    {{- else if eq $mt.String "MEASUREMENT_TYPE_DOUBLE" -}}DOUBLE
9    {{- else if eq $mt.String "MEASUREMENT_TYPE_INT" -}}INTEGER
10    {{- else if eq $mt.String "MEASUREMENT_TYPE_STRING" -}}STRING
11    {{- else if eq $mt.String "MEASUREMENT_TYPE_LONG" -}}LONG
12    {{- else }}{{$mt}}
13    {{- end }}_
14    {{- if eq $c.String "COMPARISON_EQUAL" -}}EQ
15    {{- else if eq $c.String "COMPARISON_LESS_THAN" -}}LT
16    {{- else if eq $c.String "COMPARISON_LESS_THAN_OR_EQUAL" -}}LTE
17    {{- else if eq $c.String "COMPARISON_GREATER_THAN" -}}GTE
18    {{- else if eq $c.String "COMPARISON_GREATER_THAN_OR_EQUAL" -}}GTE
19    {{- else if eq $c.String "COMPARISON_INFO_ONLY" -}}INFO
20    {{- else }}{{$c}}
21    {{- end }}
22{{- end -}}
23
24
25{{- /*
26 * JavaClass generates Java class name from a MeasurementType
27 */}}
28{{- define "JavaClass" -}}
29    {{- if eq .String "MEASUREMENT_TYPE_BOOL" -}}Boolean
30    {{- else if eq .String "MEASUREMENT_TYPE_DOUBLE" -}}Double
31    {{- else if eq .String "MEASUREMENT_TYPE_INT" -}}Integer
32    {{- else if eq .String "MEASUREMENT_TYPE_STRING" -}}String
33    {{- else if eq .String "MEASUREMENT_TYPE_LONG" -}}Long
34    {{- else }}{{.}}
35    {{- end }}
36{{- end -}}
37
38{{- /*
39 * JavaClass generates Java type from a MeasurementType
40 */}}
41{{- define "JavaType" -}}
42    {{- if eq .String "MEASUREMENT_TYPE_BOOL" -}}boolean
43    {{- else if eq .String "MEASUREMENT_TYPE_DOUBLE" -}}double
44    {{- else if eq .String "MEASUREMENT_TYPE_INT" -}}int
45    {{- else if eq .String "MEASUREMENT_TYPE_STRING" -}}String
46    {{- else if eq .String "MEASUREMENT_TYPE_LONG" -}}long
47    {{- else }}{{.}}
48    {{- end }}
49{{- end -}}
50
51{{- /*
52 * VersionCode generates the android.Build VersionCode constant from an mpc value.
53 * It is an error if the mpc value listed here.
54 */}}
55{{- define "VersionCode" -}}
56    VERSION_CODES.
57    {{- if  eq . 30}}R
58    {{- else if eq . 31}}S
59    {{- else if eq . 33}}TIRAMISU
60    {{- else if eq . 34}}UPSIDE_DOWN_CAKE
61    {{- else if eq . 35}}VANILLA_ICE_CREAM
62    {{- else }}{{.}}
63    {{- end }}
64{{- end -}}
65
66
67{{- /*
68 * MeasurementValue gets value from RequiredValue base on the MeasurementType
69 * It is an error if the MeasurementType is not listed here.
70 */}}
71{{- define "MeasurementValue" -}}
72    {{- if eq .MeasurementType.String "MEASUREMENT_TYPE_BOOL" -}}{{.RequiredValue.GetBoolValue}}
73    {{- else if eq .MeasurementType.String "MEASUREMENT_TYPE_DOUBLE" -}}{{printf "%f" .RequiredValue.GetDoubleValue}}
74    {{- else if eq .MeasurementType.String "MEASUREMENT_TYPE_INT" -}}{{.RequiredValue.GetIntValue}}
75    {{- else if eq .MeasurementType.String "MEASUREMENT_TYPE_STRING" -}}"{{.RequiredValue.GetStringValue}}"
76    {{- else if eq .MeasurementType.String "MEASUREMENT_TYPE_LONG" -}}{{.RequiredValue.GetLongValue}}L
77    {{- else }}{{.MeasurementType}}
78    {{- end }}
79{{- end -}}
80
81/*
82 * Copyright (C) 2024 The Android Open Source Project
83 *
84 * Licensed under the Apache License, Version 2.0 (the "License");
85 * you may not use this file except in compliance with the License.
86 * You may obtain a copy of the License at
87 *
88 *      http://www.apache.org/licenses/LICENSE-2.0
89 *
90 * Unless required by applicable law or agreed to in writing, software
91 * distributed under the License is distributed on an "AS IS" BASIS,
92 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
93 * See the License for the specific language governing permissions and
94 * limitations under the License.
95 */
96
97package android.mediapc.cts.common;
98
99import android.os.Build.VERSION_CODES;
100
101/**
102 * Requirements Classes.
103 */
104public final class Requirements {
105
106{{- range $r := .ReqList.GetRequirements }}
107{{- if $r.GetName }}
108    /**
109      * Add a new {{UpperCamelCase $r.GetName}}Requirement for requirement {{ $r.GetId }} to a
110      * {@code PerformanceClassEvaluator} instance.
111      {{- with $r.GetDescription}}
112      *
113      * {{.}}{{end}}
114      */
115    public static {{UpperCamelCase $r.GetName}}Requirement add{{ SafeReqID $r.GetId | UpperCase}}(
116           PerformanceClassEvaluator pce) {
117        return pce.addRequirement({{UpperCamelCase $r.GetName}}Requirement.create());
118    }
119
120    {{- range $v_id, $v := $r.GetVariants }}
121
122    /**
123      * Add a new {{UpperCamelCase $r.GetName}}Requirement for requirement {{ $r.GetId }}
124      * to a {@code PerformanceClassEvaluator} instance
125      * {{$v.GetDescription}}.
126      {{- with $r.GetDescription}}
127      *
128      * {{.}}{{end}}
129      */
130    public static {{UpperCamelCase $r.GetName}}Requirement add{{ SafeReqID $r.GetId | UpperCase}}
131              {{- UpperCamelCase $v_id}}(
132           PerformanceClassEvaluator pce) {
133        return pce.addRequirement({{UpperCamelCase $r.GetName}}Requirement.create
134            {{- UpperCamelCase $v_id}}());
135    }
136    {{- end }}{{/* range $v_id, $v */}}
137
138    /**
139      * {{ $r.GetId }} {{$r.GetName}}
140      {{- with $r.GetDescription}}
141      *
142      * {{.}}{{end}}
143      */
144    public static final class {{UpperCamelCase $r.GetName}}Requirement extends Requirement {
145
146        /**
147          * {{ $r.GetId }} {{$r.GetName}}
148          {{- with $r.GetDescription}}
149          *
150          * {{.}}{{end}}
151          */
152        private static {{UpperCamelCase $r.GetName}}Requirement create() {
153            {{- range $m_id, $m := $r.GetMeasurements }}
154            {{- $mt := $m.GetMeasurementType}}
155            {{- $c := $m.GetComparison}}
156            var {{LowerCamelCase $m_id}} = RequiredMeasurement
157                    .<{{template "JavaClass" $mt}}>builder()
158                    .setId("{{$m_id}}")
159                    .setPredicate(RequirementConstants.{{template "CompMethod" $m}})
160                    {{- range $mpc, $s := $r.GetSpecs }}
161                    {{- with index $s.GetRequiredValues $m_id}}
162                    .addRequiredValue({{template "VersionCode" $mpc}}, {{template
163                         "MeasurementValue" Dict "RequiredValue" . "MeasurementType" $mt}})
164                    {{- end}}
165                    {{- end}}
166                    .build();
167            {{- end }}
168            return new {{UpperCamelCase $r.GetName}}Requirement(
169                    "{{SafeReqID $r.GetId }}"
170                    {{- range $m_id, $m := $r.GetMeasurements }},
171                    {{LowerCamelCase $m_id}}
172                    {{- end}});
173        }
174
175        {{- range $v_id, $v := $r.GetVariants }}
176        /**
177          * {{ $r.GetId }} {{$r.GetName}}{{- with $v.GetDescription}} {{.}}{{end}}
178          {{- with $r.GetDescription}}
179          *
180          * {{.}}{{end}}
181          */
182        private static {{UpperCamelCase $r.GetName}}Requirement create{{UpperCamelCase $v_id}}() {
183            {{- range $m_id, $m := $r.GetMeasurements }}
184            {{- $mt := $m.GetMeasurementType}}
185            {{- $c := $m.GetComparison}}
186            var {{LowerCamelCase $m_id}} = RequiredMeasurement
187                    .<{{template "JavaClass" $mt}}>builder()
188                    .setId("{{$m_id}}")
189                    .setPredicate(RequirementConstants.{{template "CompMethod" $m}})
190                    {{- range $mpc, $s := $r.GetSpecs }}
191                    {{- $vs := index $s.GetVariantSpecs $v_id}}
192                    {{- if $vs }}
193                    {{- with index $vs.GetRequiredValues $m_id}}
194                    .addRequiredValue({{template "VersionCode" $mpc}}, {{template
195                         "MeasurementValue" Dict "RequiredValue" . "MeasurementType" $mt}})
196                    {{- end}}{{/* if $vs */}}
197                    {{- end}}{{/* with rv */}}
198                    {{- end}}{{/* range $mpc, $s */}}
199                    .build();
200            {{- end}}{{/* range $m_id, $m */}}
201            return new {{UpperCamelCase $r.GetName}}Requirement(
202                    "{{SafeReqID $r.GetId }}"
203                    {{- range $m_id, $m := $r.GetMeasurements }},
204                    {{LowerCamelCase $m_id}}
205                    {{- end}});
206        }
207        {{- end }}{{/* range $v_id, $v */}}
208
209        {{- range $m_id, $m := $r.GetMeasurements }}
210        {{- $mt := $m.GetMeasurementType}}
211        /** {{$m.GetDescription}} */
212        public void set{{UpperCamelCase $m_id}}({{template "JavaType" $mt}} v) {
213            this.setMeasuredValue("{{$m_id}}", v);
214        }
215        {{- end }}{{/* range $m_id, $m */}}
216
217        private {{UpperCamelCase $r.GetName}}Requirement(String id, RequiredMeasurement<?>... reqs) {
218            super(id, reqs);
219        }
220    }
221{{- end }} {{/* if $r.GetName */}}
222{{- end }} {{/* range $r */}}
223
224    private Requirements () {}
225}
226