diff options
Diffstat (limited to 'libandroid_net_lowpan/tests/jni')
10 files changed, 465 insertions, 0 deletions
diff --git a/libandroid_net_lowpan/tests/jni/LowpanBeaconInfoTest.cpp b/libandroid_net_lowpan/tests/jni/LowpanBeaconInfoTest.cpp new file mode 100644 index 0000000..efc5f18 --- /dev/null +++ b/libandroid_net_lowpan/tests/jni/LowpanBeaconInfoTest.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <memory> + +#include <binder/Parcel.h> + +#include "LowpanBeaconInfoTest.h" + +using android::net::lowpan::LowpanBeaconInfo; + +/** + * Reads exactly one LowpanBeaconInfo from 'parcelData' assuming that it is a Parcel. Any bytes afterward + * are ignored. + */ +static LowpanBeaconInfo unmarshall(JNIEnv* env, jbyteArray parcelData) { + const int length = env->GetArrayLength(parcelData); + + std::unique_ptr<uint8_t> bytes(new uint8_t[length]); + env->GetByteArrayRegion(parcelData, 0, length, reinterpret_cast<jbyte*>(bytes.get())); + + android::Parcel p; + p.setData(bytes.get(), length); + + LowpanBeaconInfo value; + value.readFromParcel(&p); + return value; +} + +/** + * Creates a Java byte[] array and writes the contents of 'addr' to it as a Parcel containing + * exactly one object. + * + * Every LowpanBeaconInfo maps to a unique parcel object, so both 'marshall(e, unmarshall(e, x))' and + * 'unmarshall(e, marshall(e, x))' should be fixed points. + */ +static jbyteArray marshall(JNIEnv* env, const LowpanBeaconInfo& addr) { + android::Parcel p; + addr.writeToParcel(&p); + const int length = p.dataSize(); + + jbyteArray parcelData = env->NewByteArray(length); + env->SetByteArrayRegion(parcelData, 0, length, reinterpret_cast<const jbyte*>(p.data())); + + return parcelData; +} + +extern "C" +JNIEXPORT jbyteArray Java_android_net_lowpan_LowpanBeaconInfoTest_readAndWriteNative(JNIEnv* env, jclass, + jbyteArray inParcel) { + const LowpanBeaconInfo value = unmarshall(env, inParcel); + return marshall(env, value); +} diff --git a/libandroid_net_lowpan/tests/jni/LowpanBeaconInfoTest.h b/libandroid_net_lowpan/tests/jni/LowpanBeaconInfoTest.h new file mode 100644 index 0000000..1ba8eaf --- /dev/null +++ b/libandroid_net_lowpan/tests/jni/LowpanBeaconInfoTest.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _ANDROID_NET_LOWPANBEACONINFOTEST_H_ +#define _ANDROID_NET_LOWPANBEACONINFOTEST_H_ + +#include <jni.h> +#include <android/net/lowpan/LowpanBeaconInfo.h> + +extern "C" +JNIEXPORT jbyteArray Java_android_net_lowpan_LowpanBeaconInfoTest_readAndWriteNative(JNIEnv* env, jclass, + jbyteArray inParcel); + +#endif // _ANDROID_NET_LOWPANBEACONINFOTEST_H_ diff --git a/libandroid_net_lowpan/tests/jni/LowpanChannelInfoTest.cpp b/libandroid_net_lowpan/tests/jni/LowpanChannelInfoTest.cpp new file mode 100644 index 0000000..03bb72a --- /dev/null +++ b/libandroid_net_lowpan/tests/jni/LowpanChannelInfoTest.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <memory> + +#include <binder/Parcel.h> + +#include "LowpanChannelInfoTest.h" + +using android::net::lowpan::LowpanChannelInfo; + +/** + * Reads exactly one LowpanChannelInfo from 'parcelData' assuming that it is a Parcel. Any bytes afterward + * are ignored. + */ +static LowpanChannelInfo unmarshall(JNIEnv* env, jbyteArray parcelData) { + const int length = env->GetArrayLength(parcelData); + + std::unique_ptr<uint8_t> bytes(new uint8_t[length]); + env->GetByteArrayRegion(parcelData, 0, length, reinterpret_cast<jbyte*>(bytes.get())); + + android::Parcel p; + p.setData(bytes.get(), length); + + LowpanChannelInfo value; + value.readFromParcel(&p); + return value; +} + +/** + * Creates a Java byte[] array and writes the contents of 'addr' to it as a Parcel containing + * exactly one object. + * + * Every LowpanChannelInfo maps to a unique parcel object, so both 'marshall(e, unmarshall(e, x))' and + * 'unmarshall(e, marshall(e, x))' should be fixed points. + */ +static jbyteArray marshall(JNIEnv* env, const LowpanChannelInfo& addr) { + android::Parcel p; + addr.writeToParcel(&p); + const int length = p.dataSize(); + + jbyteArray parcelData = env->NewByteArray(length); + env->SetByteArrayRegion(parcelData, 0, length, reinterpret_cast<const jbyte*>(p.data())); + + return parcelData; +} + +extern "C" +JNIEXPORT jbyteArray Java_android_net_lowpan_LowpanChannelInfoTest_readAndWriteNative(JNIEnv* env, jclass, + jbyteArray inParcel) { + const LowpanChannelInfo value = unmarshall(env, inParcel); + return marshall(env, value); +} diff --git a/libandroid_net_lowpan/tests/jni/LowpanChannelInfoTest.h b/libandroid_net_lowpan/tests/jni/LowpanChannelInfoTest.h new file mode 100644 index 0000000..3b29a90 --- /dev/null +++ b/libandroid_net_lowpan/tests/jni/LowpanChannelInfoTest.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _ANDROID_NET_LOWPANCHANNELINFOTEST_H_ +#define _ANDROID_NET_LOWPANCHANNELINFOTEST_H_ + +#include <jni.h> +#include <android/net/lowpan/LowpanChannelInfo.h> + +extern "C" +JNIEXPORT jbyteArray Java_android_net_lowpan_LowpanChannelInfoTest_readAndWriteNative(JNIEnv* env, jclass, + jbyteArray inParcel); + +#endif // _ANDROID_NET_LOWPANCHANNELINFOTEST_H_ diff --git a/libandroid_net_lowpan/tests/jni/LowpanCredentialTest.cpp b/libandroid_net_lowpan/tests/jni/LowpanCredentialTest.cpp new file mode 100644 index 0000000..fc860b2 --- /dev/null +++ b/libandroid_net_lowpan/tests/jni/LowpanCredentialTest.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <memory> + +#include <binder/Parcel.h> + +#include "LowpanCredentialTest.h" + +using android::net::lowpan::LowpanCredential; + +/** + * Reads exactly one LowpanCredential from 'parcelData' assuming that it is a Parcel. Any bytes afterward + * are ignored. + */ +static LowpanCredential unmarshall(JNIEnv* env, jbyteArray parcelData) { + const int length = env->GetArrayLength(parcelData); + + std::unique_ptr<uint8_t> bytes(new uint8_t[length]); + env->GetByteArrayRegion(parcelData, 0, length, reinterpret_cast<jbyte*>(bytes.get())); + + android::Parcel p; + p.setData(bytes.get(), length); + + LowpanCredential value; + value.readFromParcel(&p); + return value; +} + +/** + * Creates a Java byte[] array and writes the contents of 'addr' to it as a Parcel containing + * exactly one object. + * + * Every LowpanCredential maps to a unique parcel object, so both 'marshall(e, unmarshall(e, x))' and + * 'unmarshall(e, marshall(e, x))' should be fixed points. + */ +static jbyteArray marshall(JNIEnv* env, const LowpanCredential& addr) { + android::Parcel p; + addr.writeToParcel(&p); + const int length = p.dataSize(); + + jbyteArray parcelData = env->NewByteArray(length); + env->SetByteArrayRegion(parcelData, 0, length, reinterpret_cast<const jbyte*>(p.data())); + + return parcelData; +} + +extern "C" +JNIEXPORT jbyteArray Java_android_net_lowpan_LowpanCredentialTest_readAndWriteNative(JNIEnv* env, jclass, + jbyteArray inParcel) { + const LowpanCredential value = unmarshall(env, inParcel); + return marshall(env, value); +} diff --git a/libandroid_net_lowpan/tests/jni/LowpanCredentialTest.h b/libandroid_net_lowpan/tests/jni/LowpanCredentialTest.h new file mode 100644 index 0000000..9dd9889 --- /dev/null +++ b/libandroid_net_lowpan/tests/jni/LowpanCredentialTest.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _ANDROID_NET_LOWPANCREDENTIALTEST_H_ +#define _ANDROID_NET_LOWPANCREDENTIALTEST_H_ + +#include <jni.h> +#include <android/net/lowpan/LowpanCredential.h> + +extern "C" +JNIEXPORT jbyteArray Java_android_net_lowpan_LowpanCredentialTest_readAndWriteNative(JNIEnv* env, jclass, + jbyteArray inParcel); + +#endif // _ANDROID_NET_LOWPANCREDENTIALTEST_H_ diff --git a/libandroid_net_lowpan/tests/jni/LowpanIdentityTest.cpp b/libandroid_net_lowpan/tests/jni/LowpanIdentityTest.cpp new file mode 100644 index 0000000..1a9ad33 --- /dev/null +++ b/libandroid_net_lowpan/tests/jni/LowpanIdentityTest.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <memory> + +#include <binder/Parcel.h> + +#include "LowpanIdentityTest.h" + +using android::net::lowpan::LowpanIdentity; + +/** + * Reads exactly one LowpanIdentity from 'parcelData' assuming that it is a Parcel. Any bytes afterward + * are ignored. + */ +static LowpanIdentity unmarshall(JNIEnv* env, jbyteArray parcelData) { + const int length = env->GetArrayLength(parcelData); + + std::unique_ptr<uint8_t> bytes(new uint8_t[length]); + env->GetByteArrayRegion(parcelData, 0, length, reinterpret_cast<jbyte*>(bytes.get())); + + android::Parcel p; + p.setData(bytes.get(), length); + + LowpanIdentity value; + value.readFromParcel(&p); + return value; +} + +/** + * Creates a Java byte[] array and writes the contents of 'addr' to it as a Parcel containing + * exactly one object. + * + * Every LowpanIdentity maps to a unique parcel object, so both 'marshall(e, unmarshall(e, x))' and + * 'unmarshall(e, marshall(e, x))' should be fixed points. + */ +static jbyteArray marshall(JNIEnv* env, const LowpanIdentity& addr) { + android::Parcel p; + addr.writeToParcel(&p); + const int length = p.dataSize(); + + jbyteArray parcelData = env->NewByteArray(length); + env->SetByteArrayRegion(parcelData, 0, length, reinterpret_cast<const jbyte*>(p.data())); + + return parcelData; +} + +extern "C" +JNIEXPORT jbyteArray Java_android_net_lowpan_LowpanIdentityTest_readAndWriteNative(JNIEnv* env, jclass, + jbyteArray inParcel) { + const LowpanIdentity value = unmarshall(env, inParcel); + return marshall(env, value); +} diff --git a/libandroid_net_lowpan/tests/jni/LowpanIdentityTest.h b/libandroid_net_lowpan/tests/jni/LowpanIdentityTest.h new file mode 100644 index 0000000..1d2c465 --- /dev/null +++ b/libandroid_net_lowpan/tests/jni/LowpanIdentityTest.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _ANDROID_NET_LOWPANIDENTITYTEST_H_ +#define _ANDROID_NET_LOWPANIDENTITYTEST_H_ + +#include <jni.h> +#include <android/net/lowpan/LowpanIdentity.h> + +extern "C" +JNIEXPORT jbyteArray Java_android_net_lowpan_LowpanIdentityTest_readAndWriteNative(JNIEnv* env, jclass, + jbyteArray inParcel); + +#endif // _ANDROID_NET_LOWPANIDENTITYTEST_H_ diff --git a/libandroid_net_lowpan/tests/jni/LowpanProvisionTest.cpp b/libandroid_net_lowpan/tests/jni/LowpanProvisionTest.cpp new file mode 100644 index 0000000..95f64b6 --- /dev/null +++ b/libandroid_net_lowpan/tests/jni/LowpanProvisionTest.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <memory> + +#include <binder/Parcel.h> + +#include "LowpanProvisionTest.h" + +using android::net::lowpan::LowpanProvision; + +/** + * Reads exactly one LowpanProvision from 'parcelData' assuming that it is a Parcel. Any bytes afterward + * are ignored. + */ +static LowpanProvision unmarshall(JNIEnv* env, jbyteArray parcelData) { + const int length = env->GetArrayLength(parcelData); + + std::unique_ptr<uint8_t> bytes(new uint8_t[length]); + env->GetByteArrayRegion(parcelData, 0, length, reinterpret_cast<jbyte*>(bytes.get())); + + android::Parcel p; + p.setData(bytes.get(), length); + + LowpanProvision value; + value.readFromParcel(&p); + return value; +} + +/** + * Creates a Java byte[] array and writes the contents of 'addr' to it as a Parcel containing + * exactly one object. + * + * Every LowpanProvision maps to a unique parcel object, so both 'marshall(e, unmarshall(e, x))' and + * 'unmarshall(e, marshall(e, x))' should be fixed points. + */ +static jbyteArray marshall(JNIEnv* env, const LowpanProvision& addr) { + android::Parcel p; + addr.writeToParcel(&p); + const int length = p.dataSize(); + + jbyteArray parcelData = env->NewByteArray(length); + env->SetByteArrayRegion(parcelData, 0, length, reinterpret_cast<const jbyte*>(p.data())); + + return parcelData; +} + +extern "C" +JNIEXPORT jbyteArray Java_android_net_lowpan_LowpanProvisionTest_readAndWriteNative(JNIEnv* env, jclass, + jbyteArray inParcel) { + const LowpanProvision value = unmarshall(env, inParcel); + return marshall(env, value); +} diff --git a/libandroid_net_lowpan/tests/jni/LowpanProvisionTest.h b/libandroid_net_lowpan/tests/jni/LowpanProvisionTest.h new file mode 100644 index 0000000..49211b5 --- /dev/null +++ b/libandroid_net_lowpan/tests/jni/LowpanProvisionTest.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _ANDROID_NET_LOWPANPROVISIONTEST_H_ +#define _ANDROID_NET_LOWPANPROVISIONTEST_H_ + +#include <jni.h> +#include <android/net/lowpan/LowpanProvision.h> + +extern "C" +JNIEXPORT jbyteArray Java_android_net_lowpan_LowpanProvisionTest_readAndWriteNative(JNIEnv* env, jclass, + jbyteArray inParcel); + +#endif // _ANDROID_NET_LOWPANPROVISIONTEST_H_ |