| Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
| Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 17 | #include "java/AnnotationProcessor.h" |
| Adam Lesinski | ce5e56e2 | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 18 | |
| Adam Lesinski | 626b3db | 2016-04-07 13:24:59 -0700 | [diff] [blame] | 19 | #include "test/Test.h" |
| Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 20 | |
| 21 | namespace aapt { |
| 22 | |
| Adam Lesinski | 626b3db | 2016-04-07 13:24:59 -0700 | [diff] [blame] | 23 | TEST(AnnotationProcessorTest, EmitsDeprecated) { |
| Adam Lesinski | ce5e56e2 | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 24 | const char* comment = |
| 25 | "Some comment, and it should contain a marker word, " |
| 26 | "something that marks this resource as nor needed. " |
| 27 | "{@deprecated That's the marker! }"; |
| Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 28 | |
| Adam Lesinski | ce5e56e2 | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 29 | AnnotationProcessor processor; |
| 30 | processor.AppendComment(comment); |
| Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 31 | |
| Adam Lesinski | ce5e56e2 | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 32 | std::stringstream result; |
| 33 | processor.WriteToStream(&result, ""); |
| 34 | std::string annotations = result.str(); |
| Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 35 | |
| Adam Lesinski | ce5e56e2 | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 36 | EXPECT_NE(std::string::npos, annotations.find("@Deprecated")); |
| Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| Adam Lesinski | 626b3db | 2016-04-07 13:24:59 -0700 | [diff] [blame] | 39 | TEST(AnnotationProcessorTest, EmitsSystemApiAnnotationAndRemovesFromComment) { |
| Adam Lesinski | ce5e56e2 | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 40 | AnnotationProcessor processor; |
| 41 | processor.AppendComment("@SystemApi This is a system API"); |
| Adam Lesinski | 626b3db | 2016-04-07 13:24:59 -0700 | [diff] [blame] | 42 | |
| Adam Lesinski | ce5e56e2 | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 43 | std::stringstream result; |
| 44 | processor.WriteToStream(&result, ""); |
| 45 | std::string annotations = result.str(); |
| Adam Lesinski | 626b3db | 2016-04-07 13:24:59 -0700 | [diff] [blame] | 46 | |
| Adam Lesinski | ce5e56e2 | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 47 | EXPECT_NE(std::string::npos, |
| 48 | annotations.find("@android.annotation.SystemApi")); |
| 49 | EXPECT_EQ(std::string::npos, annotations.find("@SystemApi")); |
| 50 | EXPECT_NE(std::string::npos, annotations.find("This is a system API")); |
| Adam Lesinski | 626b3db | 2016-04-07 13:24:59 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| Adam Lesinski | ce5e56e2 | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 53 | } // namespace aapt |