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

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

Issue 851503003: Update from https://crrev.com/311076 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « base/android/jni_array.cc ('k') | base/android/jni_generator/jni_generator.py » ('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 "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
11 namespace base { 11 namespace base {
12 namespace android { 12 namespace android {
13 13
14 TEST(JniArray, BasicConversions) { 14 TEST(JniArray, BasicConversions) {
15 const uint8 kBytes[] = { 0, 1, 2, 3 }; 15 const uint8 kBytes[] = { 0, 1, 2, 3 };
16 const size_t kLen = arraysize(kBytes); 16 const size_t kLen = arraysize(kBytes);
17 JNIEnv* env = AttachCurrentThread(); 17 JNIEnv* env = AttachCurrentThread();
18 ScopedJavaLocalRef<jbyteArray> bytes = ToJavaByteArray(env, kBytes, kLen); 18 ScopedJavaLocalRef<jbyteArray> bytes = ToJavaByteArray(env, kBytes, kLen);
19 ASSERT_TRUE(bytes.obj()); 19 ASSERT_TRUE(bytes.obj());
20 20
21 std::vector<uint8> vec(5); 21 std::vector<uint8> vec(5);
22 JavaByteArrayToByteVector(env, bytes.obj(), &vec); 22 JavaByteArrayToByteVector(env, bytes.obj(), &vec);
23 EXPECT_EQ(4U, vec.size()); 23 EXPECT_EQ(4U, vec.size());
24 EXPECT_EQ(std::vector<uint8>(kBytes, kBytes + kLen), vec); 24 std::vector<uint8> expected_vec(kBytes, kBytes + kLen);
25 EXPECT_EQ(expected_vec, vec);
25 26
26 AppendJavaByteArrayToByteVector(env, bytes.obj(), &vec); 27 AppendJavaByteArrayToByteVector(env, bytes.obj(), &vec);
27 EXPECT_EQ(8U, vec.size()); 28 EXPECT_EQ(8U, vec.size());
29 expected_vec.insert(expected_vec.end(), kBytes, kBytes + kLen);
30 EXPECT_EQ(expected_vec, vec);
28 } 31 }
29 32
30 void CheckIntConversion( 33 void CheckIntConversion(
31 JNIEnv* env, 34 JNIEnv* env,
32 const int* int_array, 35 const int* int_array,
33 const size_t len, 36 const size_t len,
34 const ScopedJavaLocalRef<jintArray>& ints) { 37 const ScopedJavaLocalRef<jintArray>& ints) {
35 ASSERT_TRUE(ints.obj()); 38 ASSERT_TRUE(ints.obj());
36 39
37 jsize java_array_len = env->GetArrayLength(ints.obj()); 40 jsize java_array_len = env->GetArrayLength(ints.obj());
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 170
168 EXPECT_EQ(static_cast<size_t>(kMaxItems), vec.size()); 171 EXPECT_EQ(static_cast<size_t>(kMaxItems), vec.size());
169 for (int i = 0; i < kMaxItems; ++i) { 172 for (int i = 0; i < kMaxItems; ++i) {
170 snprintf(text, sizeof text, "%d", i); 173 snprintf(text, sizeof text, "%d", i);
171 EXPECT_STREQ(text, vec[i].c_str()); 174 EXPECT_STREQ(text, vec[i].c_str());
172 } 175 }
173 } 176 }
174 177
175 } // namespace android 178 } // namespace android
176 } // namespace base 179 } // namespace base
OLDNEW
« no previous file with comments | « base/android/jni_array.cc ('k') | base/android/jni_generator/jni_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698