ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / sync / test / fake_server / android / fake_server_helper_android.cc
blob8491474b82cdfe3205a2047367310cef86cb2bff
1 // Copyright 2014 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 "sync/test/fake_server/android/fake_server_helper_android.h"
7 #include <jni.h>
9 #include "base/android/jni_string.h"
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "jni/FakeServerHelper_jni.h"
14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/network_resources.h"
16 #include "sync/test/fake_server/fake_server.h"
17 #include "sync/test/fake_server/fake_server_network_resources.h"
18 #include "sync/test/fake_server/fake_server_verifier.h"
19 #include "testing/gtest/include/gtest/gtest.h"
21 FakeServerHelperAndroid::FakeServerHelperAndroid(JNIEnv* env, jobject obj) {
24 FakeServerHelperAndroid::~FakeServerHelperAndroid() { }
26 static jlong Init(JNIEnv* env, jobject obj) {
27 FakeServerHelperAndroid* fake_server_android =
28 new FakeServerHelperAndroid(env, obj);
29 return reinterpret_cast<intptr_t>(fake_server_android);
32 jlong FakeServerHelperAndroid::CreateFakeServer(JNIEnv* env, jobject obj) {
33 fake_server::FakeServer* fake_server = new fake_server::FakeServer();
34 return reinterpret_cast<intptr_t>(fake_server);
37 jlong FakeServerHelperAndroid::CreateNetworkResources(JNIEnv* env,
38 jobject obj,
39 jlong fake_server) {
40 fake_server::FakeServer* fake_server_ptr =
41 reinterpret_cast<fake_server::FakeServer*>(fake_server);
42 syncer::NetworkResources* resources =
43 new fake_server::FakeServerNetworkResources(fake_server_ptr);
44 return reinterpret_cast<intptr_t>(resources);
47 void FakeServerHelperAndroid::DeleteFakeServer(JNIEnv* env,
48 jobject obj,
49 jlong fake_server) {
50 fake_server::FakeServer* fake_server_ptr =
51 reinterpret_cast<fake_server::FakeServer*>(fake_server);
52 delete fake_server_ptr;
55 jboolean FakeServerHelperAndroid::VerifyEntityCountByTypeAndName(
56 JNIEnv* env,
57 jobject obj,
58 jlong fake_server,
59 jlong count,
60 jstring model_type_string,
61 jstring name) {
62 syncer::ModelType model_type;
63 if (!NotificationTypeToRealModelType(base::android::ConvertJavaStringToUTF8(
64 env, model_type_string), &model_type)) {
65 LOG(WARNING) << "Invalid ModelType string.";
66 return false;
68 fake_server::FakeServer* fake_server_ptr =
69 reinterpret_cast<fake_server::FakeServer*>(fake_server);
70 fake_server::FakeServerVerifier fake_server_verifier(fake_server_ptr);
71 testing::AssertionResult result =
72 fake_server_verifier.VerifyEntityCountByTypeAndName(
73 count, model_type, base::android::ConvertJavaStringToUTF8(env, name));
75 if (!result)
76 LOG(WARNING) << result.message();
78 return result;
81 // static
82 bool FakeServerHelperAndroid::Register(JNIEnv* env) {
83 return RegisterNativesImpl(env);