Implements JavaToNativeStringMap and adds tests for native API.
Implements JavaToNativeStringMap that is a replacement for JavaToStdMapStrings. It uses a new template method JavaToNativeMap. Also adds testing support for native API and a test for JavaToNativeStringMap. Bug: webrtc:8769 Change-Id: I580d4992a899ebe02da39af450fa51d52ee9b88b Reviewed-on: https://webrtc-review.googlesource.com/48060 Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Patrik Höglund <phoglund@webrtc.org> Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#21967}
This commit is contained in:

committed by
Commit Bot

parent
1bc1ec43a3
commit
78498cf5ee
35
sdk/android/native_unittests/java_types_unittest.cc
Normal file
35
sdk/android/native_unittests/java_types_unittest.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "sdk/android/generated_native_unittests_jni/jni/JavaTypesTestHelper_jni.h"
|
||||
#include "sdk/android/native_api/jni/java_types.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
namespace {
|
||||
TEST(JavaTypesTest, TestJavaToNativeStringMap) {
|
||||
JNIEnv* env = AttachCurrentThreadIfNeeded();
|
||||
ScopedJavaLocalRef<jobject> j_map =
|
||||
Java_JavaTypesTestHelper_createTestStringMap(env);
|
||||
|
||||
std::map<std::string, std::string> output = JavaToNativeStringMap(env, j_map);
|
||||
|
||||
std::map<std::string, std::string> expected{
|
||||
{"one", "1"}, {"two", "2"}, {"three", "3"},
|
||||
};
|
||||
EXPECT_EQ(expected, output);
|
||||
}
|
||||
} // namespace
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
package org.webrtc;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class JavaTypesTestHelper {
|
||||
@CalledByNative
|
||||
public static Map createTestStringMap() {
|
||||
Map<String, String> testMap = new HashMap<String, String>();
|
||||
testMap.put("one", "1");
|
||||
testMap.put("two", "2");
|
||||
testMap.put("three", "3");
|
||||
return testMap;
|
||||
}
|
||||
}
|
23
sdk/android/native_unittests/test_jni_onload.cc
Normal file
23
sdk/android/native_unittests/test_jni_onload.cc
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
#undef JNIEXPORT
|
||||
#define JNIEXPORT __attribute__((visibility("default")))
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "sdk/android/native_api/base/init.h"
|
||||
#include "sdk/android/native_api/jni/java_types.h"
|
||||
|
||||
// This is called by the VM when the shared library is first loaded.
|
||||
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
webrtc::InitAndroid(vm);
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
Reference in New Issue
Block a user