Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: base/android/jni_array_unittest.cc

Issue 1589953005: Support InputMethodManager#updateCursorAnchorInfo for Android 5.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Findbugs warning / Simplify the state transition. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/android/jni_array.h" 5 #include "base/android/jni_array.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 ScopedJavaLocalRef<jintArray> jints, 106 ScopedJavaLocalRef<jintArray> jints,
107 std::vector<int> int_vector, 107 std::vector<int> int_vector,
108 const size_t len) { 108 const size_t len) {
109 jint value; 109 jint value;
110 for (size_t i = 0; i < len; ++i) { 110 for (size_t i = 0; i < len; ++i) {
111 env->GetIntArrayRegion(jints.obj(), i, 1, &value); 111 env->GetIntArrayRegion(jints.obj(), i, 1, &value);
112 ASSERT_EQ(int_vector[i], value); 112 ASSERT_EQ(int_vector[i], value);
113 } 113 }
114 } 114 }
115 115
116 void CheckFloatConversion(
117 JNIEnv* env,
118 const float* float_array,
119 const size_t len,
120 const ScopedJavaLocalRef<jfloatArray>& floats) {
121 ASSERT_TRUE(floats.obj());
122
123 jsize java_array_len = env->GetArrayLength(floats.obj());
124 ASSERT_EQ(static_cast<jsize>(len), java_array_len);
125
126 jfloat value;
127 for (size_t i = 0; i < len; ++i) {
128 env->GetFloatArrayRegion(floats.obj(), i, 1, &value);
129 ASSERT_EQ(float_array[i], value);
130 }
131 }
132
133 TEST(JniArray, FloatConversions) {
134 const float kFloats[] = { 0.0f, 1.0f, -10.0f};
135 const size_t kLen = arraysize(kFloats);
136
137 JNIEnv* env = AttachCurrentThread();
138 CheckFloatConversion(env, kFloats, kLen,
139 ToJavaFloatArray(env, kFloats, kLen));
140 }
141
116 TEST(JniArray, JavaIntArrayToIntVector) { 142 TEST(JniArray, JavaIntArrayToIntVector) {
117 const int kInts[] = {0, 1, -1}; 143 const int kInts[] = {0, 1, -1};
118 const size_t kLen = arraysize(kInts); 144 const size_t kLen = arraysize(kInts);
119 145
120 JNIEnv* env = AttachCurrentThread(); 146 JNIEnv* env = AttachCurrentThread();
121 ScopedJavaLocalRef<jintArray> jints(env, env->NewIntArray(kLen)); 147 ScopedJavaLocalRef<jintArray> jints(env, env->NewIntArray(kLen));
122 ASSERT_TRUE(jints.obj()); 148 ASSERT_TRUE(jints.obj());
123 149
124 for (size_t i = 0; i < kLen; ++i) { 150 for (size_t i = 0; i < kLen; ++i) {
125 jint j = static_cast<jint>(kInts[i]); 151 jint j = static_cast<jint>(kInts[i]);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 319
294 EXPECT_EQ(kNumItems, out.size()); 320 EXPECT_EQ(kNumItems, out.size());
295 CheckIntArrayConversion(env, int_array0, out[0], kLen0); 321 CheckIntArrayConversion(env, int_array0, out[0], kLen0);
296 CheckIntArrayConversion(env, int_array1, out[1], kLen1); 322 CheckIntArrayConversion(env, int_array1, out[1], kLen1);
297 CheckIntArrayConversion(env, int_array2, out[2], kLen2); 323 CheckIntArrayConversion(env, int_array2, out[2], kLen2);
298 CheckIntArrayConversion(env, int_array3, out[3], kLen3); 324 CheckIntArrayConversion(env, int_array3, out[3], kLen3);
299 } 325 }
300 326
301 } // namespace android 327 } // namespace android
302 } // namespace base 328 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698