summaryrefslogtreecommitdiff
path: root/tests/java_api/RSUnitTests/supportlibsrc_gen/com/android/rs/unittest/struct_field.rs
blob: 0d345fa6387387d31ed5267fc744a1220a4e40cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// This file is automatically generated from
// frameworks/rs/tests/java_api/RSUnitTests/RSUnitTests.py
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * 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.
 */

#include "shared.rsh"

// Ensure that we can reflect correct Java code for a struct with
// multiple fields of type struct.  Java sets the script global
// variable "outer", and then calls a verification invokable
// "checkOuter()", passing the expected field values as scalar
// arguments.

struct InnerOne {
    int x;
    int y;
    float f;
};

typedef struct InnerOne s_innerOne;

struct InnerTwo {
    int8_t z;
    struct InnerOne innerOne;
};

struct Outer {
    struct InnerOne innerOneA;
    long l;  // to induce padding
    struct InnerOne innerOneB;
    struct InnerTwo innerTwo3[3];
    struct InnerTwo innerTwo2[2];
    struct InnerOne innerOne4[4];
    s_innerOne      innerOneC;  // does a typedef confuse reflection?
};

struct Outer outer;

// Fragment of incoming argument list: Fields for struct InnerOne.
// Arguments are named argPrefix"_x", argPrefix"_y", argPrefix"_f".
#define ARGS_INNERONE_(argPrefix) \
    int argPrefix ## _x, int argPrefix ## _y, float argPrefix ## _f

// Fragment of incoming argument list: Fields for struct InnerOne
// within struct Outer.
// Arguments are named outerFieldName"_x", outerFieldName"_y", outerFieldName"_f".
#define ARGS_INNERONE_SCALAR(outerFieldName) \
    ARGS_INNERONE_(outerFieldName)

// Fragment of incoming argument list: Fields for element of array of
// struct InnerOne within struct Outer.
// Arguments are named outerFieldName"_"index"_x", outerFieldName"_"index"_y",
// and outerFieldName"_"index"_f".
#define ARGS_INNERONE_ARRAY(outerFieldName, index) \
    ARGS_INNERONE_(outerFieldName ## _ ## index)

// Fragment of incoming argument list: Fields for element of array of
// struct InnerTwo (with nested InnerOne flattened out) within struct Outer.
// Arguments are named outerFieldName"_"index"_z", outerFieldName"_"index"_innerOne_x", etc.
#define ARGS_INNERTWO_ARRAY(outerFieldName, index) \
    int8_t outerFieldName ## _ ## index ## _z, ARGS_INNERONE_(outerFieldName ## _ ## index ## _innerOne)

// #define TRACE(...) rsDebug(__VA_ARGS__)
#define TRACE(...) (void)0

void checkOuter(ARGS_INNERONE_SCALAR(innerOneA),
                long l,
                ARGS_INNERONE_SCALAR(innerOneB),
                ARGS_INNERTWO_ARRAY(innerTwo3, 0),
                ARGS_INNERTWO_ARRAY(innerTwo3, 1),
                ARGS_INNERTWO_ARRAY(innerTwo3, 2),
                ARGS_INNERTWO_ARRAY(innerTwo2, 0),
                ARGS_INNERTWO_ARRAY(innerTwo2, 1),
                ARGS_INNERONE_ARRAY(innerOne4, 0),
                ARGS_INNERONE_ARRAY(innerOne4, 1),
                ARGS_INNERONE_ARRAY(innerOne4, 2),
                ARGS_INNERONE_ARRAY(innerOne4, 3),
                ARGS_INNERONE_SCALAR(innerOneC)) {
    bool failed = false;

    // Compare contents of a struct InnerOne instance against incoming argument values.
    // Compares instanceName".x" to argPrefix"_x", etc.
#define CHECK_INNERONE_(instanceName, argPrefix)       \
    do {                                               \
       TRACE(# instanceName, instanceName.x);          \
        _RS_ASSERT(instanceName.x == argPrefix ## _x); \
       TRACE(# instanceName, instanceName.y);          \
        _RS_ASSERT(instanceName.y == argPrefix ## _y); \
       TRACE(# instanceName, instanceName.f);          \
        _RS_ASSERT(instanceName.f == argPrefix ## _f); \
    } while(false)

    // Compare contents of a struct InnerOne instance within global
    // variable "outer" against incoming argument values.
    // Compares "outer."outerFieldName".x" to outerFieldName"_x", etc.
#define CHECK_INNERONE_SCALAR(outerFieldName) \
    CHECK_INNERONE_(outer.outerFieldName, outerFieldName)

    // Compare contents of element of array of struct InnerOne
    // instance within global variable "outer" against incoming argument values.
    // Compares "outer"outerFieldName"["index"].x" to outerFieldName"_"index"_x", etc.
#define CHECK_INNERONE_ARRAY(outerFieldName, index) \
    CHECK_INNERONE_(outer.outerFieldName[index], outerFieldName ## _ ## index)

    // Compare contents of element of array of struct InnerTwo
    // instance within global variable "outer" against incoming argument values.
    // Compares "outer."outerFieldName"["index"].z" to outerFieldName"_"index"_z",
    // "outer."outerFieldName"["index"].innerOne.x" to outerFieldName""index"_innerOne_x",
    // etc.
#define CHECK_INNERTWO_ARRAY(outerFieldName, index)                                                 \
    do {                                                                                            \
        TRACE(# index, outer.outerFieldName[index].z);                \
        _RS_ASSERT(outer.outerFieldName[index].z == outerFieldName ## _ ## index ## _z); \
        CHECK_INNERONE_(outer.outerFieldName[index].innerOne, outerFieldName ## _ ## index ## _innerOne); \
    } while (false);

    CHECK_INNERONE_SCALAR(innerOneA);
    TRACE("l", outer.l);
    _RS_ASSERT(outer.l == l);
    CHECK_INNERONE_SCALAR(innerOneB);
    CHECK_INNERTWO_ARRAY(innerTwo3, 0);
    CHECK_INNERTWO_ARRAY(innerTwo3, 1);
    CHECK_INNERTWO_ARRAY(innerTwo3, 2);
    CHECK_INNERTWO_ARRAY(innerTwo2, 0);
    CHECK_INNERTWO_ARRAY(innerTwo2, 1);
    CHECK_INNERONE_ARRAY(innerOne4, 0);
    CHECK_INNERONE_ARRAY(innerOne4, 1);
    CHECK_INNERONE_ARRAY(innerOne4, 2);
    CHECK_INNERONE_ARRAY(innerOne4, 3);
    CHECK_INNERONE_SCALAR(innerOneC);

    if (failed) {
        rsDebug("struct_field FAILED", 0);
        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
    }
    else {
        rsDebug("struct_field PASSED", 0);
        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
    }
}