blob: da96b84fd4ea28df57d4e69e1ef1e00139924bce [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) {
52 ASSERT_TRUE(parse(R"EOF(
53 <resources>
54 <declare-styleable name="foo">
55 <!-- 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>
61 </resources>)EOF"));
62
63 Attribute* attr = test::getValue<Attribute>(&mTable, u"@attr/autoText");
64 ASSERT_NE(nullptr, attr);
65
66 AnnotationProcessor processor;
67 processor.appendComment(attr->getComment());
68
69 std::stringstream result;
70 processor.writeToStream(&result, "");
71 std::string annotations = result.str();
72
73 EXPECT_NE(std::string::npos, annotations.find("@Deprecated"));
74}
75
76} // namespace aapt
77
78