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

Unified Diff: base/android/jni_array_unittest.cc

Issue 1316243003: [Android] Adding tests for jlongArray conversions to vectors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/jni_array_unittest.cc
diff --git a/base/android/jni_array_unittest.cc b/base/android/jni_array_unittest.cc
index 7cb896ce9034fd159e044fdcb8a6f7ee7c2159df..58b244322a6c21ed7cb74ecb6caf733ddbfe32a4 100644
--- a/base/android/jni_array_unittest.cc
+++ b/base/android/jni_array_unittest.cc
@@ -112,6 +112,61 @@ TEST(JniArray, JavaIntArrayToIntVector) {
}
}
+TEST(JniArray, JavaLongArrayToInt64Vector) {
+ const int64 kInt64s[] = {0LL, 1LL, -1LL};
+ const size_t kLen = arraysize(kInt64s);
+
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jlongArray> jlongs(env, env->NewLongArray(kLen));
+ ASSERT_TRUE(jlongs.obj());
+
+ for (size_t i = 0; i < kLen; ++i) {
+ jlong j = static_cast<jlong>(kInt64s[i]);
+ env->SetLongArrayRegion(jlongs.obj(), i, 1, &j);
+ ASSERT_FALSE(HasException(env));
+ }
+
+ std::vector<int64> int64s;
+ JavaLongArrayToInt64Vector(env, jlongs.obj(), &int64s);
+
+ ASSERT_EQ(static_cast<jsize>(int64s.size()),
+ env->GetArrayLength(jlongs.obj()));
+
+ jlong value;
+ for (size_t i = 0; i < kLen; ++i) {
+ env->GetLongArrayRegion(jlongs.obj(), i, 1, &value);
+ ASSERT_EQ(int64s[i], value);
+ ASSERT_EQ(kInt64s[i], int64s[i]);
+ }
+}
+
+TEST(JniArray, JavaLongArrayToLongVector) {
+ const int64 kInt64s[] = {0LL, 1LL, -1LL};
+ const size_t kLen = arraysize(kInt64s);
+
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jlongArray> jlongs(env, env->NewLongArray(kLen));
+ ASSERT_TRUE(jlongs.obj());
+
+ for (size_t i = 0; i < kLen; ++i) {
+ jlong j = static_cast<jlong>(kInt64s[i]);
+ env->SetLongArrayRegion(jlongs.obj(), i, 1, &j);
+ ASSERT_FALSE(HasException(env));
+ }
+
+ std::vector<jlong> jlongs_vector;
+ JavaLongArrayToLongVector(env, jlongs.obj(), &jlongs_vector);
+
+ ASSERT_EQ(static_cast<jsize>(jlongs_vector.size()),
+ env->GetArrayLength(jlongs.obj()));
+
+ jlong value;
+ for (size_t i = 0; i < kLen; ++i) {
+ env->GetLongArrayRegion(jlongs.obj(), i, 1, &value);
+ ASSERT_EQ(jlongs_vector[i], value);
+ }
+}
+
TEST(JniArray, JavaFloatArrayToFloatVector) {
const float kFloats[] = {0.0, 0.5, -0.5};
const size_t kLen = arraysize(kFloats);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698