-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathlocal_array_multidimensional_test.cc
116 lines (96 loc) · 4.13 KB
/
local_array_multidimensional_test.cc
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
/*
* Copyright 2025 Google LLC
*
* 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 <cstddef>
#include <utility>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "implementation/jni_helper/fake_test_constants.h"
#include "jni_bind.h"
#include "jni_test.h"
namespace {
#if __clang__
using ::jni::AdoptLocal;
using ::jni::Class;
using ::jni::Fake;
using ::jni::LocalArray;
using ::jni::test::JniTest;
using ::testing::_;
using ::testing::StrEq;
static constexpr Class kClass{"kClass"};
////////////////////////////////////////////////////////////////////////////////
// Construction.
////////////////////////////////////////////////////////////////////////////////
TEST_F(JniTest, BuildsFromSizeForMultiDimensional_no_value) {
EXPECT_CALL(*env_, NewObjectArray(10, _, Fake<jintArray>()));
LocalArray<jint, 2>{std::size_t{10}, Fake<jintArray>()};
}
TEST_F(JniTest, BuildsFromSizeForMultiDimensional_primitive_xref) {
EXPECT_CALL(*env_, FindClass(StrEq("[I")));
EXPECT_CALL(*env_, NewObjectArray(10, _, Fake<jintArray>()));
LocalArray<jint, 2>{std::size_t{10},
LocalArray<jint>{AdoptLocal{}, Fake<jintArray>()}};
}
TEST_F(JniTest, BuildsFromSizeForMultiDimensional_primitive_lvalue) {
EXPECT_CALL(*env_, NewObjectArray(10, _, Fake<jintArray>()));
LocalArray<jint> arr{AdoptLocal{}, Fake<jintArray>()};
LocalArray<jint, 2>{std::size_t{10}, arr};
}
////////////////////////////////////////////////////////////////////////////////
// Getters.
////////////////////////////////////////////////////////////////////////////////
TEST_F(JniTest, GetsIntValues) {
EXPECT_CALL(*env_, GetObjectArrayElement(Fake<jobjectArray>(), 0))
.WillOnce(::testing::Return(Fake<jintArray>(0)));
EXPECT_CALL(*env_, GetObjectArrayElement(Fake<jobjectArray>(), 1))
.WillOnce(::testing::Return(Fake<jintArray>(1)));
EXPECT_CALL(*env_, GetObjectArrayElement(Fake<jobjectArray>(), 2))
.WillOnce(::testing::Return(Fake<jintArray>(2)));
LocalArray<jint, 2> arr{std::size_t{10}, Fake<jobjectArray>()};
EXPECT_EQ((static_cast<jintArray>(arr.Get(0))), (Fake<jintArray>(0)));
EXPECT_EQ((static_cast<jintArray>(arr.Get(1))), (Fake<jintArray>(1)));
EXPECT_EQ((static_cast<jintArray>(arr.Get(2))), (Fake<jintArray>(2)));
}
////////////////////////////////////////////////////////////////////////////////
// Setters.
////////////////////////////////////////////////////////////////////////////////
TEST_F(JniTest, SetsIntValues) {
EXPECT_CALL(
*env_, SetObjectArrayElement(Fake<jobjectArray>(), 0, Fake<jintArray>()));
EXPECT_CALL(
*env_, SetObjectArrayElement(Fake<jobjectArray>(), 1, Fake<jintArray>()));
EXPECT_CALL(
*env_, SetObjectArrayElement(Fake<jobjectArray>(), 2, Fake<jintArray>()));
LocalArray<jint, 1> array_arg{AdoptLocal{}, Fake<jintArray>()};
LocalArray<jint, 2> arr{std::size_t{10}, Fake<jobjectArray>()};
arr.Set(0, array_arg);
arr.Set(1, array_arg);
arr.Set(2, std::move(array_arg));
}
TEST_F(JniTest, SetsObjectValues) {
EXPECT_CALL(*env_, SetObjectArrayElement(Fake<jobjectArray>(1), 0,
Fake<jobjectArray>(2)));
EXPECT_CALL(*env_, SetObjectArrayElement(Fake<jobjectArray>(1), 1,
Fake<jobjectArray>(2)));
EXPECT_CALL(*env_, SetObjectArrayElement(Fake<jobjectArray>(1), 2,
Fake<jobjectArray>(2)));
LocalArray<jobject, 1, kClass> array_arg{AdoptLocal{}, Fake<jobjectArray>(2)};
LocalArray<jint, 2> arr{AdoptLocal{}, Fake<jobjectArray>(1)};
arr.Set(0, array_arg);
arr.Set(1, array_arg);
arr.Set(2, std::move(array_arg));
}
#endif // __clang__
} // namespace