[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / base / android / jni_generator / sample_for_tests.cc
blob6707742ed01a7087be83cc9c38aa5fe77ce9931f
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
3 // found in the LICENSE file.
5 #include "base/android/jni_generator/sample_for_tests.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "jni/SampleForTests_jni.h"
13 using base::android::AttachCurrentThread;
14 using base::android::ScopedJavaLocalRef;
16 namespace base {
17 namespace android {
19 jdouble CPPClass::InnerClass::MethodOtherP0(JNIEnv* env, jobject obj) {
20 return 0.0;
23 CPPClass::CPPClass() {
26 CPPClass::~CPPClass() {
29 void CPPClass::Destroy(JNIEnv* env, jobject obj) {
30 delete this;
33 jint CPPClass::Method(JNIEnv* env, jobject obj) {
34 return 0;
37 void CPPClass::AddStructB(JNIEnv* env, jobject obj, jobject structb) {
38 long key = Java_InnerStructB_getKey(env, structb);
39 std::string value = ConvertJavaStringToUTF8(
40 env, Java_InnerStructB_getValue(env, structb).obj());
41 map_[key] = value;
44 void CPPClass::IterateAndDoSomethingWithStructB(JNIEnv* env, jobject obj) {
45 // Iterate over the elements and do something with them.
46 for (std::map<long, std::string>::const_iterator it = map_.begin();
47 it != map_.end(); ++it) {
48 long key = it->first;
49 std::string value = it->second;
51 map_.clear();
54 base::android::ScopedJavaLocalRef<jstring> CPPClass::ReturnAString(
55 JNIEnv* env, jobject obj) {
56 base::android::ScopedJavaLocalRef<jstring> ret = ConvertUTF8ToJavaString(
57 env, "test");
58 return ret;
61 // Static free functions declared and called directly from java.
62 static jlong Init(JNIEnv* env, jobject obj, jstring param) {
63 return 0;
66 static jdouble GetDoubleFunction(JNIEnv*, jobject) {
67 return 0;
70 static jfloat GetFloatFunction(JNIEnv*, jclass) {
71 return 0;
74 static void SetNonPODDatatype(JNIEnv*, jobject, jobject) {
77 static jobject GetNonPODDatatype(JNIEnv*, jobject) {
78 return NULL;
81 static jint InnerFunction(JNIEnv*, jclass) {
82 return 0;
85 } // namespace android
86 } // namespace base
88 int main() {
89 // On a regular application, you'd call AttachCurrentThread(). This sample is
90 // not yet linking with all the libraries.
91 JNIEnv* env = /* AttachCurrentThread() */ NULL;
93 // This is how you call a java static method from C++.
94 bool foo = base::android::Java_SampleForTests_staticJavaMethod(env);
96 // This is how you call a java method from C++. Note that you must have
97 // obtained the jobject somehow.
98 jobject my_java_object = NULL;
99 int bar = base::android::Java_SampleForTests_javaMethod(
100 env, my_java_object, 1, 2);
102 for (int i = 0; i < 10; ++i) {
103 // Creates a "struct" that will then be used by the java side.
104 ScopedJavaLocalRef<jobject> struct_a =
105 base::android::Java_InnerStructA_create(
106 env, 0, 1,
107 base::android::ConvertUTF8ToJavaString(env, "test").obj());
108 base::android::Java_SampleForTests_addStructA(
109 env, my_java_object, struct_a.obj());
111 base::android::Java_SampleForTests_iterateAndDoSomething(env, my_java_object);
112 return 0;