forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mobile: Add initial unit tests for jni_utility.(h|cc) (envoyproxy#30849)
This PR sets up an initial infrastructure for writing unit tests for `jni_utility.(h|cc)`. Signed-off-by: Fredy Wijaya <fredyw@google.com> Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
- Loading branch information
1 parent
795f514
commit 24e84cd
Showing
7 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
mobile/test/java/io/envoyproxy/envoymobile/jni/JniUtilityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters