OLD | NEW |
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 "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 TEST(JniArray, LongConversions) { | 78 TEST(JniArray, LongConversions) { |
79 const int64 kLongs[] = { 0, 1, -1, kint64min, kint64max}; | 79 const int64 kLongs[] = { 0, 1, -1, kint64min, kint64max}; |
80 const size_t kLen = arraysize(kLongs); | 80 const size_t kLen = arraysize(kLongs); |
81 | 81 |
82 JNIEnv* env = AttachCurrentThread(); | 82 JNIEnv* env = AttachCurrentThread(); |
83 CheckLongConversion(env, kLongs, kLen, ToJavaLongArray(env, kLongs, kLen)); | 83 CheckLongConversion(env, kLongs, kLen, ToJavaLongArray(env, kLongs, kLen)); |
84 | 84 |
85 const std::vector<int64> vec(kLongs, kLongs + kLen); | 85 const std::vector<int64> vec(kLongs, kLongs + kLen); |
86 CheckLongConversion(env, kLongs, kLen, ToJavaLongArray(env, vec)); | 86 CheckLongConversion(env, kLongs, kLen, ToJavaLongArray(env, vec)); |
| 87 |
| 88 std::vector<int64_t> longs; |
| 89 ScopedJavaLocalRef<jlongArray> jlongs = ToJavaLongArray(env, vec); |
| 90 AppendJavaLongArrayToLongVector(env, jlongs.obj(), &longs); |
| 91 for (size_t i = 0; i < kLen; ++i) { |
| 92 ASSERT_EQ(vec[i], longs[i]); |
| 93 } |
87 } | 94 } |
88 | 95 |
89 TEST(JniArray, JavaIntArrayToIntVector) { | 96 TEST(JniArray, JavaIntArrayToIntVector) { |
90 const int kInts[] = {0, 1, -1}; | 97 const int kInts[] = {0, 1, -1}; |
91 const size_t kLen = arraysize(kInts); | 98 const size_t kLen = arraysize(kInts); |
92 | 99 |
93 JNIEnv* env = AttachCurrentThread(); | 100 JNIEnv* env = AttachCurrentThread(); |
94 ScopedJavaLocalRef<jintArray> jints(env, env->NewIntArray(kLen)); | 101 ScopedJavaLocalRef<jintArray> jints(env, env->NewIntArray(kLen)); |
95 ASSERT_TRUE(jints.obj()); | 102 ASSERT_TRUE(jints.obj()); |
96 | 103 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 177 |
171 EXPECT_EQ(static_cast<size_t>(kMaxItems), vec.size()); | 178 EXPECT_EQ(static_cast<size_t>(kMaxItems), vec.size()); |
172 for (int i = 0; i < kMaxItems; ++i) { | 179 for (int i = 0; i < kMaxItems; ++i) { |
173 snprintf(text, sizeof text, "%d", i); | 180 snprintf(text, sizeof text, "%d", i); |
174 EXPECT_STREQ(text, vec[i].c_str()); | 181 EXPECT_STREQ(text, vec[i].c_str()); |
175 } | 182 } |
176 } | 183 } |
177 | 184 |
178 } // namespace android | 185 } // namespace android |
179 } // namespace base | 186 } // namespace base |
OLD | NEW |