1// This file is automatically generated from
2// frameworks/rs/tests/java_api/RSUnitTests/RSUnitTests.py
3/*
4 * Copyright (C) 2017 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "shared.rsh"
20
21// Ensure that we can reflect correct Java code for a struct with
22// multiple fields of type struct.  Java sets the script global
23// variable "outer", and then calls a verification invokable
24// "checkOuter()", passing the expected field values as scalar
25// arguments.
26
27struct InnerOne {
28    int x;
29    int y;
30    float f;
31};
32
33typedef struct InnerOne s_innerOne;
34
35struct InnerTwo {
36    int8_t z;
37    struct InnerOne innerOne;
38};
39
40struct Outer {
41    struct InnerOne innerOneA;
42    long l;  // to induce padding
43    struct InnerOne innerOneB;
44    struct InnerTwo innerTwo3[3];
45    struct InnerTwo innerTwo2[2];
46    struct InnerOne innerOne4[4];
47    s_innerOne      innerOneC;  // does a typedef confuse reflection?
48};
49
50struct Outer outer;
51
52// Fragment of incoming argument list: Fields for struct InnerOne.
53// Arguments are named argPrefix"_x", argPrefix"_y", argPrefix"_f".
54#define ARGS_INNERONE_(argPrefix) \
55    int argPrefix ## _x, int argPrefix ## _y, float argPrefix ## _f
56
57// Fragment of incoming argument list: Fields for struct InnerOne
58// within struct Outer.
59// Arguments are named outerFieldName"_x", outerFieldName"_y", outerFieldName"_f".
60#define ARGS_INNERONE_SCALAR(outerFieldName) \
61    ARGS_INNERONE_(outerFieldName)
62
63// Fragment of incoming argument list: Fields for element of array of
64// struct InnerOne within struct Outer.
65// Arguments are named outerFieldName"_"index"_x", outerFieldName"_"index"_y",
66// and outerFieldName"_"index"_f".
67#define ARGS_INNERONE_ARRAY(outerFieldName, index) \
68    ARGS_INNERONE_(outerFieldName ## _ ## index)
69
70// Fragment of incoming argument list: Fields for element of array of
71// struct InnerTwo (with nested InnerOne flattened out) within struct Outer.
72// Arguments are named outerFieldName"_"index"_z", outerFieldName"_"index"_innerOne_x", etc.
73#define ARGS_INNERTWO_ARRAY(outerFieldName, index) \
74    int8_t outerFieldName ## _ ## index ## _z, ARGS_INNERONE_(outerFieldName ## _ ## index ## _innerOne)
75
76// #define TRACE(...) rsDebug(__VA_ARGS__)
77#define TRACE(...) (void)0
78
79void checkOuter(ARGS_INNERONE_SCALAR(innerOneA),
80                long l,
81                ARGS_INNERONE_SCALAR(innerOneB),
82                ARGS_INNERTWO_ARRAY(innerTwo3, 0),
83                ARGS_INNERTWO_ARRAY(innerTwo3, 1),
84                ARGS_INNERTWO_ARRAY(innerTwo3, 2),
85                ARGS_INNERTWO_ARRAY(innerTwo2, 0),
86                ARGS_INNERTWO_ARRAY(innerTwo2, 1),
87                ARGS_INNERONE_ARRAY(innerOne4, 0),
88                ARGS_INNERONE_ARRAY(innerOne4, 1),
89                ARGS_INNERONE_ARRAY(innerOne4, 2),
90                ARGS_INNERONE_ARRAY(innerOne4, 3),
91                ARGS_INNERONE_SCALAR(innerOneC)) {
92    bool failed = false;
93
94    // Compare contents of a struct InnerOne instance against incoming argument values.
95    // Compares instanceName".x" to argPrefix"_x", etc.
96#define CHECK_INNERONE_(instanceName, argPrefix)       \
97    do {                                               \
98       TRACE(# instanceName, instanceName.x);          \
99        _RS_ASSERT(instanceName.x == argPrefix ## _x); \
100       TRACE(# instanceName, instanceName.y);          \
101        _RS_ASSERT(instanceName.y == argPrefix ## _y); \
102       TRACE(# instanceName, instanceName.f);          \
103        _RS_ASSERT(instanceName.f == argPrefix ## _f); \
104    } while(false)
105
106    // Compare contents of a struct InnerOne instance within global
107    // variable "outer" against incoming argument values.
108    // Compares "outer."outerFieldName".x" to outerFieldName"_x", etc.
109#define CHECK_INNERONE_SCALAR(outerFieldName) \
110    CHECK_INNERONE_(outer.outerFieldName, outerFieldName)
111
112    // Compare contents of element of array of struct InnerOne
113    // instance within global variable "outer" against incoming argument values.
114    // Compares "outer"outerFieldName"["index"].x" to outerFieldName"_"index"_x", etc.
115#define CHECK_INNERONE_ARRAY(outerFieldName, index) \
116    CHECK_INNERONE_(outer.outerFieldName[index], outerFieldName ## _ ## index)
117
118    // Compare contents of element of array of struct InnerTwo
119    // instance within global variable "outer" against incoming argument values.
120    // Compares "outer."outerFieldName"["index"].z" to outerFieldName"_"index"_z",
121    // "outer."outerFieldName"["index"].innerOne.x" to outerFieldName""index"_innerOne_x",
122    // etc.
123#define CHECK_INNERTWO_ARRAY(outerFieldName, index)                                                 \
124    do {                                                                                            \
125        TRACE(# index, outer.outerFieldName[index].z);                \
126        _RS_ASSERT(outer.outerFieldName[index].z == outerFieldName ## _ ## index ## _z); \
127        CHECK_INNERONE_(outer.outerFieldName[index].innerOne, outerFieldName ## _ ## index ## _innerOne); \
128    } while (false);
129
130    CHECK_INNERONE_SCALAR(innerOneA);
131    TRACE("l", outer.l);
132    _RS_ASSERT(outer.l == l);
133    CHECK_INNERONE_SCALAR(innerOneB);
134    CHECK_INNERTWO_ARRAY(innerTwo3, 0);
135    CHECK_INNERTWO_ARRAY(innerTwo3, 1);
136    CHECK_INNERTWO_ARRAY(innerTwo3, 2);
137    CHECK_INNERTWO_ARRAY(innerTwo2, 0);
138    CHECK_INNERTWO_ARRAY(innerTwo2, 1);
139    CHECK_INNERONE_ARRAY(innerOne4, 0);
140    CHECK_INNERONE_ARRAY(innerOne4, 1);
141    CHECK_INNERONE_ARRAY(innerOne4, 2);
142    CHECK_INNERONE_ARRAY(innerOne4, 3);
143    CHECK_INNERONE_SCALAR(innerOneC);
144
145    if (failed) {
146        rsDebug("struct_field FAILED", 0);
147        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
148    }
149    else {
150        rsDebug("struct_field PASSED", 0);
151        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
152    }
153}
154