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

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

Issue 8769005: Don't use Singleton to cache JNI method IDs in Java Bridge (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments and added test Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/android/jni_android.h » ('j') | base/android/jni_android.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
joth 2011/12/02 17:35:36 IMO calling it jni_android_unittest.cc is consiste
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/android/jni_android.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace base {
10 namespace android {
11
12 namespace {
13
14 const char kJavaLangObject[] = "java/lang/Object";
15 const char kGetClass[] = "getClass";
16 const char kToString[] = "toString";
17 const char kReturningJavaLangClass[] = "()Ljava/lang/Class;";
18 const char kReturningJavaLangString[] = "()Ljava/lang/String;";
19
20 const char* g_last_method;
21 const char* g_last_jni_signature;
22 jmethodID g_last_method_id;
23
24 JNINativeInterface g_previous_functions = {0};
25
26 jmethodID GetMethodIDWrapper(JNIEnv* env, jclass clazz, const char* method,
27 const char* jni_signature) {
28 g_last_method = method;
29 g_last_jni_signature = jni_signature;
30 g_last_method_id = g_previous_functions.GetMethodID(env, clazz, method,
31 jni_signature);
32 return g_last_method_id;
33 }
34
35 } // namespace
36
37 class GetMethodIDFromClassNameTest : public testing::Test {
38 protected:
39 virtual void SetUp() {
40 JNIEnv* env = AttachCurrentThread();
41 g_previous_functions = *env->functions;
42 JNINativeInterface* native_interface =
43 const_cast<JNINativeInterface*>(env->functions);
44 native_interface->GetMethodID = &GetMethodIDWrapper;
45 }
46
47 virtual void TearDown() {
48 JNIEnv* env = AttachCurrentThread();
49 *(const_cast<JNINativeInterface*>(env->functions)) = g_previous_functions;
50 }
51
52 void Reset() {
53 g_last_method = 0;
54 g_last_jni_signature = 0;
55 g_last_method_id = NULL;
56 }
57 };
58
59 TEST_F(GetMethodIDFromClassNameTest, GeneralUse) {
60 JNIEnv* env = AttachCurrentThread();
61
62 Reset();
63 jmethodID id1 = GetMethodIDFromClassName(env, kJavaLangObject, kGetClass,
64 kReturningJavaLangClass);
65 EXPECT_STREQ(kGetClass, g_last_method);
66 EXPECT_STREQ(kReturningJavaLangClass, g_last_jni_signature);
67 EXPECT_EQ(g_last_method_id, id1);
68
69 Reset();
70 jmethodID id2 = GetMethodIDFromClassName(env, kJavaLangObject, kGetClass,
71 kReturningJavaLangClass);
72 EXPECT_STREQ(0, g_last_method);
73 EXPECT_STREQ(0, g_last_jni_signature);
74 EXPECT_EQ(NULL, g_last_method_id);
75 EXPECT_EQ(id1, id2);
76
77 Reset();
78 jmethodID id3 = GetMethodIDFromClassName(env, kJavaLangObject, kToString,
79 kReturningJavaLangString);
80 EXPECT_STREQ(kToString, g_last_method);
81 EXPECT_STREQ(kReturningJavaLangString, g_last_jni_signature);
82 EXPECT_EQ(g_last_method_id, id3);
83 }
84
85 } // namespace android
86 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/android/jni_android.h » ('j') | base/android/jni_android.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698