Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump actions/dependency-review-action from 3.1.0 to 3.1.3 #861

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/_precheck_deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ jobs:
ref: ${{ inputs.repo-ref }}
persist-credentials: false
- name: Dependency Review
uses: actions/dependency-review-action@6c5ccdad469c9f8a2996bfecaec55a631a347034
uses: actions/dependency-review-action@7bbfa034e752445ea40215fff1c3bf9597993d3f
13 changes: 11 additions & 2 deletions mobile/library/common/jni/jni_utility.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "library/common/jni/jni_utility.h"

#include <stdlib.h>
#include <string.h>
#include <cstdlib>
#include <cstring>

#include "source/common/common/assert.h"

Expand Down Expand Up @@ -355,6 +355,15 @@ void javaByteArrayToProto(JniHelper& jni_helper, jbyteArray source,
RELEASE_ASSERT(success, "Failed to parse protobuf message.");
}

LocalRefUniquePtr<jbyteArray> protoToJavaByteArray(JniHelper& jni_helper,
const Envoy::Protobuf::MessageLite& source) {
size_t size = source.ByteSizeLong();
LocalRefUniquePtr<jbyteArray> byte_array = jni_helper.newByteArray(size);
auto bytes = jni_helper.getByteArrayElements(byte_array.get(), nullptr);
source.SerializeToArray(bytes.get(), size);
return byte_array;
}

std::string javaStringToString(JniHelper& jni_helper, jstring java_string) {
if (!java_string) {
return "";
Expand Down
4 changes: 4 additions & 0 deletions mobile/library/common/jni/jni_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ void javaByteArrayToString(JniHelper& jni_helper, jbyteArray jbytes, std::string
void javaByteArrayToProto(JniHelper& jni_helper, jbyteArray source,
Envoy::Protobuf::MessageLite* dest);

/** Converts from Proto to Java byte array. */
LocalRefUniquePtr<jbyteArray> protoToJavaByteArray(JniHelper& jni_helper,
const Envoy::Protobuf::MessageLite& source);

/** Converts from Java `String` to C++ string. */
std::string javaStringToString(JniHelper& jni_helper, jstring java_string);

Expand Down
20 changes: 20 additions & 0 deletions mobile/test/common/jni/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,23 @@ cc_binary(
":jni_helper_test_lib",
],
)

cc_library(
name = "jni_utility_test_lib",
srcs = [
"jni_utility_test.cc",
],
deps = [
"//library/common/jni:jni_utility_lib",
],
alwayslink = True,
)

cc_binary(
name = "libenvoy_jni_utility_test.so",
testonly = True,
linkshared = True,
deps = [
":jni_utility_test_lib",
],
)
17 changes: 17 additions & 0 deletions mobile/test/common/jni/jni_utility_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <jni.h>

#include "library/common/jni/jni_utility.h"

// NOLINT(namespace-envoy)

// This file contains JNI implementation used by
// `test/java/io/envoyproxy/envoymobile/jni/JniUtilityTest.java` unit tests.

extern "C" JNIEXPORT jbyteArray JNICALL
Java_io_envoyproxy_envoymobile_jni_JniUtilityTest_protoJavaByteArrayConversion(JNIEnv* env, jclass,
jbyteArray source) {
Envoy::JNI::JniHelper jni_helper(env);
Envoy::ProtobufWkt::Struct s;
Envoy::JNI::javaByteArrayToProto(jni_helper, source, &s);
return Envoy::JNI::protoToJavaByteArray(jni_helper, s).release();
}
14 changes: 14 additions & 0 deletions mobile/test/java/io/envoyproxy/envoymobile/jni/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,17 @@ envoy_mobile_android_test(
],
native_lib_name = "envoy_jni_helper_test",
)

envoy_mobile_android_test(
name = "jni_utility_test",
srcs = [
"JniUtilityTest.java",
],
native_deps = [
"//test/common/jni:libenvoy_jni_utility_test.so",
],
native_lib_name = "envoy_jni_utility_test",
deps = [
"@maven//:com_google_protobuf_protobuf_javalite",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.envoyproxy.envoymobile.jni;

import static org.assertj.core.api.Assertions.assertThat;

import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class JniUtilityTest {
public JniUtilityTest() { System.loadLibrary("envoy_jni_utility_test"); }

//================================================================================
// Native methods for testing.
//================================================================================
public static native byte[] protoJavaByteArrayConversion(byte[] source);

@Test
public void testProtoJavaByteArrayConversion() throws Exception {
Struct source =
Struct.newBuilder()
.putFields("string_key", Value.newBuilder().setStringValue("string_value").build())
.putFields("num_key", Value.newBuilder().setNumberValue(123).build())
.putFields("bool_key", Value.newBuilder().setBoolValue(true).build())
.build();
Struct dest = Struct.parseFrom(protoJavaByteArrayConversion(source.toByteArray()));
assertThat(source).isEqualTo(dest);
}
}