blob: 9ccac8888426258413a72579dd317be89dc0850e [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 Lesinski18dc03a2017-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;
37 processor.WriteToStream(&result, "");
38 std::string annotations = result.str();
Adam Lesinskib274e352015-11-06 15:14:35 -080039
Adam Lesinski18dc03a2017-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;
48 processor.WriteToStream(&result, "");
49 std::string annotations = result.str();
Adam Lesinski626b3db2016-04-07 13:24:59 -070050
Adam Lesinski18dc03a2017-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
56TEST(AnnotationProcessor, ExtractsFirstSentence) {
57 EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence("This is the only sentence"),
58 Eq("This is the only sentence"));
59 EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence(
60 "This is the\n first sentence. This is the rest of the paragraph."),
61 Eq("This is the\n first sentence."));
62 EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence(
63 "This is the first sentence with a {@link android.R.styleable.Theme}."),
64 Eq("This is the first sentence with a {@link android.R.styleable.Theme}."));
Adam Lesinski626b3db2016-04-07 13:24:59 -070065}
66
Adam Lesinskice5e56e2016-10-21 17:56:45 -070067} // namespace aapt