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

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

Issue 12253057: Implement WebStorage API methods (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits Created 7 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 | Annotate | Revision Log
« no previous file with comments | « base/android/jni_array.cc ('k') | no next file » | 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 EXPECT_EQ(std::vector<uint8>(kBytes, kBytes + kLen), vec);
25 25
26 AppendJavaByteArrayToByteVector(env, bytes.obj(), &vec); 26 AppendJavaByteArrayToByteVector(env, bytes.obj(), &vec);
27 EXPECT_EQ(8U, vec.size()); 27 EXPECT_EQ(8U, vec.size());
28 } 28 }
29 29
30 void CheckLongConversion(
31 JNIEnv* env,
32 const int64* long_array,
33 const size_t len,
34 const ScopedJavaLocalRef<jlongArray>& longs) {
35 ASSERT_TRUE(longs.obj());
36
37 jsize java_array_len = env->GetArrayLength(longs.obj());
38 ASSERT_EQ(static_cast<int>(len), java_array_len);
39
40 jlong value;
41 for (size_t i = 0; i < len; ++i) {
42 env->GetLongArrayRegion(longs.obj(), i, 1, &value);
43 ASSERT_EQ(long_array[i], value);
44 }
45 }
46
47 TEST(JniArray, LongConversions) {
48 const int64 kLongs[] = { 0, 1, -1, kint64min, kint64max};
49 const size_t kLen = arraysize(kLongs);
50
51 JNIEnv* env = AttachCurrentThread();
52 CheckLongConversion(env, kLongs, kLen, ToJavaLongArray(env, kLongs, kLen));
53
54 const std::vector<int64> vec(kLongs, kLongs + kLen);
55 CheckLongConversion(env, kLongs, kLen, ToJavaLongArray(env, vec));
56 }
57
30 TEST(JniArray, JavaArrayOfByteArrayToStringVector) { 58 TEST(JniArray, JavaArrayOfByteArrayToStringVector) {
31 const int kMaxItems = 50; 59 const int kMaxItems = 50;
32 JNIEnv* env = AttachCurrentThread(); 60 JNIEnv* env = AttachCurrentThread();
33 61
34 // Create a byte[][] object. 62 // Create a byte[][] object.
35 ScopedJavaLocalRef<jclass> byte_array_clazz(env, env->FindClass("[B")); 63 ScopedJavaLocalRef<jclass> byte_array_clazz(env, env->FindClass("[B"));
36 ASSERT_TRUE(byte_array_clazz.obj()); 64 ASSERT_TRUE(byte_array_clazz.obj());
37 65
38 ScopedJavaLocalRef<jobjectArray> array( 66 ScopedJavaLocalRef<jobjectArray> array(
39 env, env->NewObjectArray(kMaxItems, byte_array_clazz.obj(), NULL)); 67 env, env->NewObjectArray(kMaxItems, byte_array_clazz.obj(), NULL));
(...skipping 18 matching lines...) Expand all
58 86
59 EXPECT_EQ(static_cast<size_t>(kMaxItems), vec.size()); 87 EXPECT_EQ(static_cast<size_t>(kMaxItems), vec.size());
60 for (int i = 0; i < kMaxItems; ++i) { 88 for (int i = 0; i < kMaxItems; ++i) {
61 snprintf(text, sizeof text, "%d", i); 89 snprintf(text, sizeof text, "%d", i);
62 EXPECT_STREQ(text, vec[i].c_str()); 90 EXPECT_STREQ(text, vec[i].c_str());
63 } 91 }
64 } 92 }
65 93
66 } // namespace android 94 } // namespace android
67 } // namespace base 95 } // namespace base
OLDNEW
« no previous file with comments | « base/android/jni_array.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698