Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "hidden_api.h" |
| 18 | |
| 19 | #include "common_runtime_test.h" |
| 20 | #include "jni_internal.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 24 | using hiddenapi::detail::MemberSignature; |
Mathew Inwood | a8503d9 | 2018-04-05 16:10:25 +0100 | [diff] [blame^] | 25 | using hiddenapi::GetActionFromAccessFlags; |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 26 | |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 27 | class HiddenApiTest : public CommonRuntimeTest { |
| 28 | protected: |
| 29 | void SetUp() OVERRIDE { |
| 30 | // Do the normal setup. |
| 31 | CommonRuntimeTest::SetUp(); |
| 32 | self_ = Thread::Current(); |
| 33 | self_->TransitionFromSuspendedToRunnable(); |
| 34 | LoadDex("HiddenApiSignatures"); |
| 35 | bool started = runtime_->Start(); |
| 36 | CHECK(started); |
| 37 | |
| 38 | class1_field1_ = getArtField("mypackage/packagea/Class1", "field1", "I"); |
| 39 | class1_field12_ = getArtField("mypackage/packagea/Class1", "field12", "I"); |
| 40 | class1_init_ = getArtMethod("mypackage/packagea/Class1", "<init>", "()V"); |
| 41 | class1_method1_ = getArtMethod("mypackage/packagea/Class1", "method1", "()V"); |
| 42 | class1_method1_i_ = getArtMethod("mypackage/packagea/Class1", "method1", "(I)V"); |
| 43 | class1_method12_ = getArtMethod("mypackage/packagea/Class1", "method12", "()V"); |
| 44 | class12_field1_ = getArtField("mypackage/packagea/Class12", "field1", "I"); |
| 45 | class12_method1_ = getArtMethod("mypackage/packagea/Class12", "method1", "()V"); |
| 46 | class2_field1_ = getArtField("mypackage/packagea/Class2", "field1", "I"); |
| 47 | class2_method1_ = getArtMethod("mypackage/packagea/Class2", "method1", "()V"); |
| 48 | class2_method1_i_ = getArtMethod("mypackage/packagea/Class2", "method1", "(I)V"); |
| 49 | class3_field1_ = getArtField("mypackage/packageb/Class3", "field1", "I"); |
| 50 | class3_method1_ = getArtMethod("mypackage/packageb/Class3", "method1", "()V"); |
| 51 | class3_method1_i_ = getArtMethod("mypackage/packageb/Class3", "method1", "(I)V"); |
| 52 | } |
| 53 | |
| 54 | ArtMethod* getArtMethod(const char* class_name, const char* name, const char* signature) { |
| 55 | JNIEnv* env = Thread::Current()->GetJniEnv(); |
| 56 | jclass klass = env->FindClass(class_name); |
| 57 | jmethodID method_id = env->GetMethodID(klass, name, signature); |
| 58 | ArtMethod* art_method = jni::DecodeArtMethod(method_id); |
| 59 | return art_method; |
| 60 | } |
| 61 | |
| 62 | ArtField* getArtField(const char* class_name, const char* name, const char* signature) { |
| 63 | JNIEnv* env = Thread::Current()->GetJniEnv(); |
| 64 | jclass klass = env->FindClass(class_name); |
| 65 | jfieldID field_id = env->GetFieldID(klass, name, signature); |
| 66 | ArtField* art_field = jni::DecodeArtField(field_id); |
| 67 | return art_field; |
| 68 | } |
| 69 | |
| 70 | protected: |
| 71 | Thread* self_; |
| 72 | ArtField* class1_field1_; |
| 73 | ArtField* class1_field12_; |
| 74 | ArtMethod* class1_init_; |
| 75 | ArtMethod* class1_method1_; |
| 76 | ArtMethod* class1_method1_i_; |
| 77 | ArtMethod* class1_method12_; |
| 78 | ArtField* class12_field1_; |
| 79 | ArtMethod* class12_method1_; |
| 80 | ArtField* class2_field1_; |
| 81 | ArtMethod* class2_method1_; |
| 82 | ArtMethod* class2_method1_i_; |
| 83 | ArtField* class3_field1_; |
| 84 | ArtMethod* class3_method1_; |
| 85 | ArtMethod* class3_method1_i_; |
| 86 | }; |
| 87 | |
Mathew Inwood | a8503d9 | 2018-04-05 16:10:25 +0100 | [diff] [blame^] | 88 | TEST_F(HiddenApiTest, CheckGetActionFromRuntimeFlags) { |
| 89 | uint32_t whitelist = HiddenApiAccessFlags::EncodeForRuntime(0, HiddenApiAccessFlags::kWhitelist); |
| 90 | uint32_t lightgreylist = |
| 91 | HiddenApiAccessFlags::EncodeForRuntime(0, HiddenApiAccessFlags::kLightGreylist); |
| 92 | uint32_t darkgreylist = |
| 93 | HiddenApiAccessFlags::EncodeForRuntime(0, HiddenApiAccessFlags::kDarkGreylist); |
| 94 | uint32_t blacklist = HiddenApiAccessFlags::EncodeForRuntime(0, HiddenApiAccessFlags::kBlacklist); |
| 95 | |
| 96 | runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kNoChecks); |
| 97 | ASSERT_EQ(GetActionFromAccessFlags(whitelist), hiddenapi::kAllow); |
| 98 | ASSERT_EQ(GetActionFromAccessFlags(lightgreylist), hiddenapi::kAllow); |
| 99 | ASSERT_EQ(GetActionFromAccessFlags(darkgreylist), hiddenapi::kAllow); |
| 100 | ASSERT_EQ(GetActionFromAccessFlags(blacklist), hiddenapi::kAllow); |
| 101 | |
| 102 | runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kJustWarn); |
| 103 | ASSERT_EQ(GetActionFromAccessFlags(whitelist), hiddenapi::kAllow); |
| 104 | ASSERT_EQ(GetActionFromAccessFlags(lightgreylist), hiddenapi::kAllowButWarn); |
| 105 | ASSERT_EQ(GetActionFromAccessFlags(darkgreylist), hiddenapi::kAllowButWarn); |
| 106 | ASSERT_EQ(GetActionFromAccessFlags(blacklist), hiddenapi::kAllowButWarn); |
| 107 | |
| 108 | runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kDarkGreyAndBlackList); |
| 109 | ASSERT_EQ(GetActionFromAccessFlags(whitelist), hiddenapi::kAllow); |
| 110 | ASSERT_EQ(GetActionFromAccessFlags(lightgreylist), hiddenapi::kAllowButWarn); |
| 111 | ASSERT_EQ(GetActionFromAccessFlags(darkgreylist), hiddenapi::kDeny); |
| 112 | ASSERT_EQ(GetActionFromAccessFlags(blacklist), hiddenapi::kDeny); |
| 113 | |
| 114 | runtime_->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kBlacklistOnly); |
| 115 | ASSERT_EQ(GetActionFromAccessFlags(whitelist), hiddenapi::kAllow); |
| 116 | ASSERT_EQ(GetActionFromAccessFlags(lightgreylist), hiddenapi::kAllowButWarn); |
| 117 | ASSERT_EQ(GetActionFromAccessFlags(darkgreylist), hiddenapi::kAllowButWarnAndToast); |
| 118 | ASSERT_EQ(GetActionFromAccessFlags(blacklist), hiddenapi::kDeny); |
| 119 | } |
| 120 | |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 121 | TEST_F(HiddenApiTest, CheckMembersRead) { |
| 122 | ASSERT_NE(nullptr, class1_field1_); |
| 123 | ASSERT_NE(nullptr, class1_field12_); |
| 124 | ASSERT_NE(nullptr, class1_init_); |
| 125 | ASSERT_NE(nullptr, class1_method1_); |
| 126 | ASSERT_NE(nullptr, class1_method1_i_); |
| 127 | ASSERT_NE(nullptr, class1_method12_); |
| 128 | ASSERT_NE(nullptr, class12_field1_); |
| 129 | ASSERT_NE(nullptr, class12_method1_); |
| 130 | ASSERT_NE(nullptr, class2_field1_); |
| 131 | ASSERT_NE(nullptr, class2_method1_); |
| 132 | ASSERT_NE(nullptr, class2_method1_i_); |
| 133 | ASSERT_NE(nullptr, class3_field1_); |
| 134 | ASSERT_NE(nullptr, class3_method1_); |
| 135 | ASSERT_NE(nullptr, class3_method1_i_); |
| 136 | } |
| 137 | |
| 138 | TEST_F(HiddenApiTest, CheckEverythingMatchesL) { |
| 139 | ScopedObjectAccess soa(self_); |
| 140 | std::string prefix("L"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 141 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 142 | ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 143 | ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 144 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 145 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 146 | ASSERT_TRUE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix)); |
| 147 | ASSERT_TRUE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix)); |
| 148 | ASSERT_TRUE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
| 149 | ASSERT_TRUE(MemberSignature(class2_field1_).DoesPrefixMatch(prefix)); |
| 150 | ASSERT_TRUE(MemberSignature(class2_method1_).DoesPrefixMatch(prefix)); |
| 151 | ASSERT_TRUE(MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix)); |
| 152 | ASSERT_TRUE(MemberSignature(class3_field1_).DoesPrefixMatch(prefix)); |
| 153 | ASSERT_TRUE(MemberSignature(class3_method1_).DoesPrefixMatch(prefix)); |
| 154 | ASSERT_TRUE(MemberSignature(class3_method1_i_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | TEST_F(HiddenApiTest, CheckPackageMatch) { |
| 158 | ScopedObjectAccess soa(self_); |
| 159 | std::string prefix("Lmypackage/packagea/"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 160 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 161 | ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 162 | ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 163 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 164 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 165 | ASSERT_TRUE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
| 166 | ASSERT_TRUE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix)); |
| 167 | ASSERT_TRUE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix)); |
| 168 | ASSERT_TRUE(MemberSignature(class2_field1_).DoesPrefixMatch(prefix)); |
| 169 | ASSERT_TRUE(MemberSignature(class2_method1_).DoesPrefixMatch(prefix)); |
| 170 | ASSERT_TRUE(MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix)); |
| 171 | ASSERT_FALSE(MemberSignature(class3_field1_).DoesPrefixMatch(prefix)); |
| 172 | ASSERT_FALSE(MemberSignature(class3_method1_).DoesPrefixMatch(prefix)); |
| 173 | ASSERT_FALSE(MemberSignature(class3_method1_i_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | TEST_F(HiddenApiTest, CheckClassMatch) { |
| 177 | ScopedObjectAccess soa(self_); |
| 178 | std::string prefix("Lmypackage/packagea/Class1"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 179 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 180 | ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 181 | ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 182 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 183 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 184 | ASSERT_TRUE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
| 185 | ASSERT_TRUE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix)); |
| 186 | ASSERT_TRUE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix)); |
| 187 | ASSERT_FALSE(MemberSignature(class2_field1_).DoesPrefixMatch(prefix)); |
| 188 | ASSERT_FALSE(MemberSignature(class2_method1_).DoesPrefixMatch(prefix)); |
| 189 | ASSERT_FALSE(MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | TEST_F(HiddenApiTest, CheckClassExactMatch) { |
| 193 | ScopedObjectAccess soa(self_); |
| 194 | std::string prefix("Lmypackage/packagea/Class1;"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 195 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 196 | ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 197 | ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 198 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 199 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 200 | ASSERT_FALSE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix)); |
| 201 | ASSERT_FALSE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix)); |
| 202 | ASSERT_FALSE(MemberSignature(class2_field1_).DoesPrefixMatch(prefix)); |
| 203 | ASSERT_FALSE(MemberSignature(class2_method1_).DoesPrefixMatch(prefix)); |
| 204 | ASSERT_FALSE(MemberSignature(class2_method1_i_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | TEST_F(HiddenApiTest, CheckMethodMatch) { |
| 208 | ScopedObjectAccess soa(self_); |
| 209 | std::string prefix("Lmypackage/packagea/Class1;->method1"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 210 | ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 211 | ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 212 | ASSERT_FALSE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 213 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 214 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 215 | ASSERT_TRUE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
| 216 | ASSERT_FALSE(MemberSignature(class12_field1_).DoesPrefixMatch(prefix)); |
| 217 | ASSERT_FALSE(MemberSignature(class12_method1_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | TEST_F(HiddenApiTest, CheckMethodExactMatch) { |
| 221 | ScopedObjectAccess soa(self_); |
| 222 | std::string prefix("Lmypackage/packagea/Class1;->method1("); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 223 | ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 224 | ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 225 | ASSERT_FALSE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 226 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 227 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 228 | ASSERT_FALSE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | TEST_F(HiddenApiTest, CheckMethodSignatureMatch) { |
| 232 | ScopedObjectAccess soa(self_); |
| 233 | std::string prefix("Lmypackage/packagea/Class1;->method1(I)"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 234 | ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 235 | ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 236 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 237 | ASSERT_TRUE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 238 | ASSERT_FALSE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | TEST_F(HiddenApiTest, CheckMethodSignatureAndReturnMatch) { |
| 242 | ScopedObjectAccess soa(self_); |
| 243 | std::string prefix("Lmypackage/packagea/Class1;->method1()V"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 244 | ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 245 | ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 246 | ASSERT_TRUE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 247 | ASSERT_FALSE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 248 | ASSERT_FALSE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | TEST_F(HiddenApiTest, CheckFieldMatch) { |
| 252 | ScopedObjectAccess soa(self_); |
| 253 | std::string prefix("Lmypackage/packagea/Class1;->field1"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 254 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 255 | ASSERT_TRUE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 256 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
| 257 | ASSERT_FALSE(MemberSignature(class1_method1_i_).DoesPrefixMatch(prefix)); |
| 258 | ASSERT_FALSE(MemberSignature(class1_method12_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | TEST_F(HiddenApiTest, CheckFieldExactMatch) { |
| 262 | ScopedObjectAccess soa(self_); |
| 263 | std::string prefix("Lmypackage/packagea/Class1;->field1:"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 264 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 265 | ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 266 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | TEST_F(HiddenApiTest, CheckFieldTypeMatch) { |
| 270 | ScopedObjectAccess soa(self_); |
| 271 | std::string prefix("Lmypackage/packagea/Class1;->field1:I"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 272 | ASSERT_TRUE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
| 273 | ASSERT_FALSE(MemberSignature(class1_field12_).DoesPrefixMatch(prefix)); |
| 274 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | TEST_F(HiddenApiTest, CheckConstructorMatch) { |
| 278 | ScopedObjectAccess soa(self_); |
| 279 | std::string prefix("Lmypackage/packagea/Class1;-><init>"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 280 | ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 281 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | TEST_F(HiddenApiTest, CheckConstructorExactMatch) { |
| 285 | ScopedObjectAccess soa(self_); |
| 286 | std::string prefix("Lmypackage/packagea/Class1;-><init>()V"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 287 | ASSERT_TRUE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
| 288 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | TEST_F(HiddenApiTest, CheckMethodSignatureTrailingCharsNoMatch) { |
| 292 | ScopedObjectAccess soa(self_); |
| 293 | std::string prefix("Lmypackage/packagea/Class1;->method1()Vfoo"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 294 | ASSERT_FALSE(MemberSignature(class1_method1_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | TEST_F(HiddenApiTest, CheckConstructorTrailingCharsNoMatch) { |
| 298 | ScopedObjectAccess soa(self_); |
| 299 | std::string prefix("Lmypackage/packagea/Class1;-><init>()Vfoo"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 300 | ASSERT_FALSE(MemberSignature(class1_init_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | TEST_F(HiddenApiTest, CheckFieldTrailingCharsNoMatch) { |
| 304 | ScopedObjectAccess soa(self_); |
| 305 | std::string prefix("Lmypackage/packagea/Class1;->field1:Ifoo"); |
Andreas Gampe | aa12001 | 2018-03-28 16:23:24 -0700 | [diff] [blame] | 306 | ASSERT_FALSE(MemberSignature(class1_field1_).DoesPrefixMatch(prefix)); |
Mathew Inwood | 7d74ef5 | 2018-03-16 14:18:33 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | } // namespace art |