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

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

Issue 1471693006: Remove kint32min. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint3
Patch Set: rebase Created 5 years 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
« no previous file with comments | « no previous file | base/basictypes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdint.h>
8
9 #include <limits>
10
7 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
8 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
9 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
10 14
11 namespace base { 15 namespace base {
12 namespace android { 16 namespace android {
13 17
14 TEST(JniArray, BasicConversions) { 18 TEST(JniArray, BasicConversions) {
15 const uint8_t kBytes[] = {0, 1, 2, 3}; 19 const uint8_t kBytes[] = {0, 1, 2, 3};
16 const size_t kLen = arraysize(kBytes); 20 const size_t kLen = arraysize(kBytes);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 ASSERT_EQ(static_cast<jsize>(len), java_array_len); 54 ASSERT_EQ(static_cast<jsize>(len), java_array_len);
51 55
52 jint value; 56 jint value;
53 for (size_t i = 0; i < len; ++i) { 57 for (size_t i = 0; i < len; ++i) {
54 env->GetIntArrayRegion(ints.obj(), i, 1, &value); 58 env->GetIntArrayRegion(ints.obj(), i, 1, &value);
55 ASSERT_EQ(int_array[i], value); 59 ASSERT_EQ(int_array[i], value);
56 } 60 }
57 } 61 }
58 62
59 TEST(JniArray, IntConversions) { 63 TEST(JniArray, IntConversions) {
60 const int kInts[] = { 0, 1, -1, kint32min, kint32max}; 64 const int kInts[] = {0, 1, -1, std::numeric_limits<int32_t>::min(),
65 std::numeric_limits<int32_t>::max()};
61 const size_t kLen = arraysize(kInts); 66 const size_t kLen = arraysize(kInts);
62 67
63 JNIEnv* env = AttachCurrentThread(); 68 JNIEnv* env = AttachCurrentThread();
64 CheckIntConversion(env, kInts, kLen, ToJavaIntArray(env, kInts, kLen)); 69 CheckIntConversion(env, kInts, kLen, ToJavaIntArray(env, kInts, kLen));
65 70
66 const std::vector<int> vec(kInts, kInts + kLen); 71 const std::vector<int> vec(kInts, kInts + kLen);
67 CheckIntConversion(env, kInts, kLen, ToJavaIntArray(env, vec)); 72 CheckIntConversion(env, kInts, kLen, ToJavaIntArray(env, vec));
68 } 73 }
69 74
70 void CheckLongConversion(JNIEnv* env, 75 void CheckLongConversion(JNIEnv* env,
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 256
252 // Create an int[][] object. 257 // Create an int[][] object.
253 ScopedJavaLocalRef<jclass> int_array_clazz(env, env->FindClass("[I")); 258 ScopedJavaLocalRef<jclass> int_array_clazz(env, env->FindClass("[I"));
254 ASSERT_TRUE(int_array_clazz.obj()); 259 ASSERT_TRUE(int_array_clazz.obj());
255 260
256 ScopedJavaLocalRef<jobjectArray> array( 261 ScopedJavaLocalRef<jobjectArray> array(
257 env, env->NewObjectArray(kNumItems, int_array_clazz.obj(), nullptr)); 262 env, env->NewObjectArray(kNumItems, int_array_clazz.obj(), nullptr));
258 ASSERT_TRUE(array.obj()); 263 ASSERT_TRUE(array.obj());
259 264
260 // Populate int[][] object. 265 // Populate int[][] object.
261 const int kInts0[] = {0, 1, -1, kint32min, kint32max}; 266 const int kInts0[] = {0, 1, -1, std::numeric_limits<int32_t>::min(),
267 std::numeric_limits<int32_t>::max()};
262 const size_t kLen0 = arraysize(kInts0); 268 const size_t kLen0 = arraysize(kInts0);
263 ScopedJavaLocalRef<jintArray> int_array0 = ToJavaIntArray(env, kInts0, kLen0); 269 ScopedJavaLocalRef<jintArray> int_array0 = ToJavaIntArray(env, kInts0, kLen0);
264 env->SetObjectArrayElement(array.obj(), 0, int_array0.obj()); 270 env->SetObjectArrayElement(array.obj(), 0, int_array0.obj());
265 271
266 const int kInts1[] = {3, 4, 5}; 272 const int kInts1[] = {3, 4, 5};
267 const size_t kLen1 = arraysize(kInts1); 273 const size_t kLen1 = arraysize(kInts1);
268 ScopedJavaLocalRef<jintArray> int_array1 = ToJavaIntArray(env, kInts1, kLen1); 274 ScopedJavaLocalRef<jintArray> int_array1 = ToJavaIntArray(env, kInts1, kLen1);
269 env->SetObjectArrayElement(array.obj(), 1, int_array1.obj()); 275 env->SetObjectArrayElement(array.obj(), 1, int_array1.obj());
270 276
271 const int kInts2[] = {}; 277 const int kInts2[] = {};
(...skipping 12 matching lines...) Expand all
284 290
285 EXPECT_EQ(kNumItems, out.size()); 291 EXPECT_EQ(kNumItems, out.size());
286 CheckIntArrayConversion(env, int_array0, out[0], kLen0); 292 CheckIntArrayConversion(env, int_array0, out[0], kLen0);
287 CheckIntArrayConversion(env, int_array1, out[1], kLen1); 293 CheckIntArrayConversion(env, int_array1, out[1], kLen1);
288 CheckIntArrayConversion(env, int_array2, out[2], kLen2); 294 CheckIntArrayConversion(env, int_array2, out[2], kLen2);
289 CheckIntArrayConversion(env, int_array3, out[3], kLen3); 295 CheckIntArrayConversion(env, int_array3, out[3], kLen3);
290 } 296 }
291 297
292 } // namespace android 298 } // namespace android
293 } // namespace base 299 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/basictypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698