blob: d3860a5825b2f6b559584a599c9bb562d227d290 [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
17#include "ResourceParser.h"
18#include "ResourceTable.h"
19#include "ResourceValues.h"
Adam Lesinskib274e352015-11-06 15:14:35 -080020#include "java/AnnotationProcessor.h"
Adam Lesinskib274e352015-11-06 15:14:35 -080021#include "test/Builders.h"
22#include "test/Context.h"
Adam Lesinski467f1712015-11-16 17:35:44 -080023#include "xml/XmlPullParser.h"
Adam Lesinskib274e352015-11-06 15:14:35 -080024
25#include <gtest/gtest.h>
26
27namespace aapt {
28
29struct AnnotationProcessorTest : public ::testing::Test {
30 std::unique_ptr<IAaptContext> mContext;
31 ResourceTable mTable;
32
33 void SetUp() override {
34 mContext = test::ContextBuilder().build();
35 }
36
37 ::testing::AssertionResult parse(const StringPiece& str) {
38 ResourceParserOptions options;
39 ResourceParser parser(mContext->getDiagnostics(), &mTable, Source{}, ConfigDescription{},
40 options);
41 std::stringstream in;
42 in << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" << str;
Adam Lesinski467f1712015-11-16 17:35:44 -080043 xml::XmlPullParser xmlParser(in);
Adam Lesinskib274e352015-11-06 15:14:35 -080044 if (parser.parse(&xmlParser)) {
45 return ::testing::AssertionSuccess();
46 }
47 return ::testing::AssertionFailure();
48 }
49};
50
51TEST_F(AnnotationProcessorTest, EmitsDeprecated) {
Adam Lesinski803c7c82016-04-06 16:09:43 -070052 const char* xmlInput = R"EOF(
Adam Lesinskib274e352015-11-06 15:14:35 -080053 <resources>
Adam Lesinski803c7c82016-04-06 16:09:43 -070054 <declare-styleable name="foo">
Adam Lesinskib274e352015-11-06 15:14:35 -080055 <!-- Some comment, and it should contain
56 a marker word, something that marks
57 this resource as nor needed.
58 {@deprecated That's the marker! } -->
59 <attr name="autoText" format="boolean" />
60 </declare-styleable>
Adam Lesinski803c7c82016-04-06 16:09:43 -070061 </resources>)EOF";
62
63 ASSERT_TRUE(parse(xmlInput));
Adam Lesinskib274e352015-11-06 15:14:35 -080064
65 Attribute* attr = test::getValue<Attribute>(&mTable, u"@attr/autoText");
66 ASSERT_NE(nullptr, attr);
67
68 AnnotationProcessor processor;
69 processor.appendComment(attr->getComment());
70
71 std::stringstream result;
72 processor.writeToStream(&result, "");
73 std::string annotations = result.str();
74
75 EXPECT_NE(std::string::npos, annotations.find("@Deprecated"));
76}
77
78} // namespace aapt
79
80