-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split signature test into method and field.
Field tests are under exercised for these signatures. While they're exercised indirectly elsewhere, it's helpful to have these tests for debugging. Also, multi-dimensional field arrays aren't working (#40) so this ought help fix it. PiperOrigin-RevId: 584098520
- Loading branch information
1 parent
db5ecf9
commit 829989e
Showing
3 changed files
with
183 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* 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 <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
#include "jni_bind.h" | ||
|
||
namespace { | ||
|
||
using ::jni::Array; | ||
using ::jni::Class; | ||
using ::jni::Constructor; | ||
using ::jni::Field; | ||
using ::jni::Id; | ||
using ::jni::IdType; | ||
using ::jni::JniT; | ||
using ::jni::JniTSelector; | ||
using ::jni::kNoIdx; | ||
using ::jni::Method; | ||
using ::jni::Overload; | ||
using ::jni::Params; | ||
using ::jni::Rank; | ||
using ::jni::Return; | ||
using ::jni::SelectorStaticInfo; | ||
using ::jni::Self; | ||
using ::jni::Signature_v; | ||
|
||
// clang-format off | ||
static constexpr Class kClass1{ | ||
"kClass1", | ||
|
||
// Rank 0. | ||
Field{"f0", jboolean{}}, | ||
Field{"f1", jbyte{}}, | ||
Field{"f2", jchar{}}, | ||
Field{"f3", jshort{}}, | ||
Field{"f4", jint{}}, | ||
Field{"f5", jfloat{}}, | ||
Field{"f6", jdouble{}}, | ||
Field{"f7", jlong{}}, | ||
Field{"f8", Class{"kClass2"}}, | ||
|
||
// Rank 1. | ||
Field{"f9", Array<jboolean>{}}, | ||
Field{"f10", Array<jbyte>{}}, | ||
Field{"f11", Array<jchar>{}}, | ||
Field{"f12", Array<jshort>{}}, | ||
Field{"f13", Array<jint>{}}, | ||
Field{"f14", Array<jfloat>{}}, | ||
Field{"f15", Array<jdouble>{}}, | ||
Field{"f16", Array<jlong>{}}, | ||
Field{"f17", Array{Class{"kClass2"}}}, | ||
|
||
// Rank 2. | ||
Field{"f18", Array{jboolean{}, Rank<2>{}}}, | ||
Field{"f19", Array{jbyte{}, Rank<2>{}}}, | ||
Field{"f20", Array{jchar{}, Rank<2>{}}}, | ||
Field{"f21", Array{jshort{}, Rank<2>{}}}, | ||
Field{"f22", Array{jint{}, Rank<2>{}}}, | ||
Field{"f23", Array{jfloat{}, Rank<2>{}}}, | ||
Field{"f24", Array{jdouble{}, Rank<2>{}}}, | ||
Field{"f25", Array{jlong{}, Rank<2>{}}}, | ||
Field{"f26", Array{Class{"kClass2"}, Rank<2>{}}} | ||
}; | ||
// clang-format on | ||
|
||
using JT = JniT<jobject, kClass1>; | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Class (i.e. self). | ||
//////////////////////////////////////////////////////////////////////////////// | ||
using kSelf1 = Id<JT, IdType::CLASS, kNoIdx, 0>; | ||
using JniSelfT = JniTSelector<jni::LocalArray<jobject, 3, kClass1>::JniT_, -1>; | ||
using StaticSelectorInfoSelf = SelectorStaticInfo<JniSelfT>; | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Rank 0. | ||
//////////////////////////////////////////////////////////////////////////////// | ||
static_assert(std::string_view{"Z"} == Signature_v<Id<JT, IdType::FIELD, 0>>); | ||
static_assert(std::string_view{"B"} == Signature_v<Id<JT, IdType::FIELD, 1>>); | ||
static_assert(std::string_view{"C"} == Signature_v<Id<JT, IdType::FIELD, 2>>); | ||
static_assert(std::string_view{"S"} == Signature_v<Id<JT, IdType::FIELD, 3>>); | ||
static_assert(std::string_view{"I"} == Signature_v<Id<JT, IdType::FIELD, 4>>); | ||
static_assert(std::string_view{"F"} == Signature_v<Id<JT, IdType::FIELD, 5>>); | ||
static_assert(std::string_view{"D"} == Signature_v<Id<JT, IdType::FIELD, 6>>); | ||
static_assert(std::string_view{"J"} == Signature_v<Id<JT, IdType::FIELD, 7>>); | ||
static_assert(std::string_view{"LkClass2;"} == | ||
Signature_v<Id<JT, IdType::FIELD, 8>>); | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Rank 1. | ||
//////////////////////////////////////////////////////////////////////////////// | ||
static_assert(std::string_view{"[Z"} == Signature_v<Id<JT, IdType::FIELD, 9>>); | ||
static_assert(std::string_view{"[B"} == Signature_v<Id<JT, IdType::FIELD, 10>>); | ||
static_assert(std::string_view{"[C"} == Signature_v<Id<JT, IdType::FIELD, 11>>); | ||
static_assert(std::string_view{"[S"} == Signature_v<Id<JT, IdType::FIELD, 12>>); | ||
static_assert(std::string_view{"[I"} == Signature_v<Id<JT, IdType::FIELD, 13>>); | ||
static_assert(std::string_view{"[F"} == Signature_v<Id<JT, IdType::FIELD, 14>>); | ||
static_assert(std::string_view{"[D"} == Signature_v<Id<JT, IdType::FIELD, 15>>); | ||
static_assert(std::string_view{"[J"} == Signature_v<Id<JT, IdType::FIELD, 16>>); | ||
static_assert(std::string_view{"[LkClass2;"} == | ||
Signature_v<Id<JT, IdType::FIELD, 17>>); | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Rank 2. | ||
//////////////////////////////////////////////////////////////////////////////// | ||
static_assert(std::string_view{"[[Z"} == | ||
Signature_v<Id<JT, IdType::FIELD, 18>>); | ||
static_assert(std::string_view{"[[B"} == | ||
Signature_v<Id<JT, IdType::FIELD, 19>>); | ||
static_assert(std::string_view{"[[C"} == | ||
Signature_v<Id<JT, IdType::FIELD, 20>>); | ||
static_assert(std::string_view{"[[S"} == | ||
Signature_v<Id<JT, IdType::FIELD, 21>>); | ||
static_assert(std::string_view{"[[I"} == | ||
Signature_v<Id<JT, IdType::FIELD, 22>>); | ||
static_assert(std::string_view{"[[F"} == | ||
Signature_v<Id<JT, IdType::FIELD, 23>>); | ||
static_assert(std::string_view{"[[D"} == | ||
Signature_v<Id<JT, IdType::FIELD, 24>>); | ||
static_assert(std::string_view{"[[J"} == | ||
Signature_v<Id<JT, IdType::FIELD, 25>>); | ||
static_assert(std::string_view{"[[LkClass2;"} == | ||
Signature_v<Id<JT, IdType::FIELD, 26>>); | ||
|
||
} // namespace |
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