blob: 3e43c4295c0780f69c88b5c63210ba6ec305a29c [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 Lesinskice5e56e22016-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
21namespace aapt {
22
Adam Lesinski626b3db2016-04-07 13:24:59 -070023TEST(AnnotationProcessorTest, EmitsDeprecated) {
Adam Lesinskice5e56e22016-10-21 17:56:45 -070024 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 Lesinskib274e352015-11-06 15:14:35 -080028
Adam Lesinskice5e56e22016-10-21 17:56:45 -070029 AnnotationProcessor processor;
30 processor.AppendComment(comment);
Adam Lesinskib274e352015-11-06 15:14:35 -080031
Adam Lesinskice5e56e22016-10-21 17:56:45 -070032 std::stringstream result;
33 processor.WriteToStream(&result, "");
34 std::string annotations = result.str();
Adam Lesinskib274e352015-11-06 15:14:35 -080035
Adam Lesinskice5e56e22016-10-21 17:56:45 -070036 EXPECT_NE(std::string::npos, annotations.find("@Deprecated"));
Adam Lesinskib274e352015-11-06 15:14:35 -080037}
38
Adam Lesinski626b3db2016-04-07 13:24:59 -070039TEST(AnnotationProcessorTest, EmitsSystemApiAnnotationAndRemovesFromComment) {
Adam Lesinskice5e56e22016-10-21 17:56:45 -070040 AnnotationProcessor processor;
41 processor.AppendComment("@SystemApi This is a system API");
Adam Lesinski626b3db2016-04-07 13:24:59 -070042
Adam Lesinskice5e56e22016-10-21 17:56:45 -070043 std::stringstream result;
44 processor.WriteToStream(&result, "");
45 std::string annotations = result.str();
Adam Lesinski626b3db2016-04-07 13:24:59 -070046
Adam Lesinskice5e56e22016-10-21 17:56:45 -070047 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 Lesinski626b3db2016-04-07 13:24:59 -070051}
52
Adam Lesinskice5e56e22016-10-21 17:56:45 -070053} // namespace aapt