blob: 856f4ccbd7f08ac6b8d2a9348603e92d302c0850 [file] [log] [blame]
Adam Lesinskib274e352015-11-06 15:14:35 -08001/*
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 Lesinskib274e352015-11-06 15:14:35 -080017#include "java/AnnotationProcessor.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070018
Adam Lesinski626b3db2016-04-07 13:24:59 -070019#include "test/Test.h"
Adam Lesinskib274e352015-11-06 15:14:35 -080020
Adam Lesinskie967d3f2017-07-24 18:19:36 -070021using ::testing::Eq;
22using ::testing::HasSubstr;
23using ::testing::Not;
24
Adam Lesinskib274e352015-11-06 15:14:35 -080025namespace aapt {
26
Adam Lesinski626b3db2016-04-07 13:24:59 -070027TEST(AnnotationProcessorTest, EmitsDeprecated) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070028 const char* comment =
29 "Some comment, and it should contain a marker word, "
30 "something that marks this resource as nor needed. "
31 "{@deprecated That's the marker! }";
Adam Lesinskib274e352015-11-06 15:14:35 -080032
Adam Lesinskice5e56e2016-10-21 17:56:45 -070033 AnnotationProcessor processor;
34 processor.AppendComment(comment);
Adam Lesinskib274e352015-11-06 15:14:35 -080035
Adam Lesinskice5e56e2016-10-21 17:56:45 -070036 std::stringstream result;
Adam Lesinski09f4d702017-08-08 10:39:55 -070037 processor.WriteToStream("", &result);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070038 std::string annotations = result.str();
Adam Lesinskib274e352015-11-06 15:14:35 -080039
Adam Lesinskie967d3f2017-07-24 18:19:36 -070040 EXPECT_THAT(annotations, HasSubstr("@Deprecated"));
Adam Lesinskib274e352015-11-06 15:14:35 -080041}
42
Adam Lesinski626b3db2016-04-07 13:24:59 -070043TEST(AnnotationProcessorTest, EmitsSystemApiAnnotationAndRemovesFromComment) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070044 AnnotationProcessor processor;
45 processor.AppendComment("@SystemApi This is a system API");
Adam Lesinski626b3db2016-04-07 13:24:59 -070046
Adam Lesinskice5e56e2016-10-21 17:56:45 -070047 std::stringstream result;
Adam Lesinski09f4d702017-08-08 10:39:55 -070048 processor.WriteToStream("", &result);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070049 std::string annotations = result.str();
Adam Lesinski626b3db2016-04-07 13:24:59 -070050
Adam Lesinskie967d3f2017-07-24 18:19:36 -070051 EXPECT_THAT(annotations, HasSubstr("@android.annotation.SystemApi"));
52 EXPECT_THAT(annotations, Not(HasSubstr("@SystemApi")));
53 EXPECT_THAT(annotations, HasSubstr("This is a system API"));
54}
55
Adam Lesinski09f4d702017-08-08 10:39:55 -070056TEST(AnnotationProcessorTest, EmitsTestApiAnnotationAndRemovesFromComment) {
57 AnnotationProcessor processor;
58 processor.AppendComment("@TestApi This is a test API");
59
60 std::stringstream result;
61 processor.WriteToStream("", &result);
62 std::string annotations = result.str();
63
64 EXPECT_THAT(annotations, HasSubstr("@android.annotation.TestApi"));
65 EXPECT_THAT(annotations, Not(HasSubstr("@TestApi")));
66 EXPECT_THAT(annotations, HasSubstr("This is a test API"));
67}
68
Adam Lesinskie967d3f2017-07-24 18:19:36 -070069TEST(AnnotationProcessor, ExtractsFirstSentence) {
70 EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence("This is the only sentence"),
71 Eq("This is the only sentence"));
72 EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence(
73 "This is the\n first sentence. This is the rest of the paragraph."),
74 Eq("This is the\n first sentence."));
75 EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence(
76 "This is the first sentence with a {@link android.R.styleable.Theme}."),
77 Eq("This is the first sentence with a {@link android.R.styleable.Theme}."));
Adam Lesinski626b3db2016-04-07 13:24:59 -070078}
79
Adam Lesinskice5e56e2016-10-21 17:56:45 -070080} // namespace aapt