blob: 7110c90fa3a947ca8ce56b32f8d4b67f60bbf5e8 [file] [log] [blame]
Adam Lesinskicc5609d2016-04-05 12:41:07 -07001/*
2 * Copyright (C) 2016 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 Lesinskicc5609d2016-04-05 12:41:07 -070017#include "xml/XmlActionExecutor.h"
18
Adam Lesinskice5e56e2016-10-21 17:56:45 -070019#include "test/Test.h"
20
Adam Lesinskicc5609d2016-04-05 12:41:07 -070021namespace aapt {
22namespace xml {
23
24TEST(XmlActionExecutorTest, BuildsAccessibleNestedPattern) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070025 XmlActionExecutor executor;
26 XmlNodeAction& manifest_action = executor["manifest"];
27 XmlNodeAction& application_action = manifest_action["application"];
Adam Lesinskicc5609d2016-04-05 12:41:07 -070028
Adam Lesinskice5e56e2016-10-21 17:56:45 -070029 Element* manifest_el = nullptr;
30 manifest_action.Action([&](Element* manifest) -> bool {
31 manifest_el = manifest;
32 return true;
33 });
Adam Lesinskicc5609d2016-04-05 12:41:07 -070034
Adam Lesinskice5e56e2016-10-21 17:56:45 -070035 Element* application_el = nullptr;
36 application_action.Action([&](Element* application) -> bool {
37 application_el = application;
38 return true;
39 });
Adam Lesinskicc5609d2016-04-05 12:41:07 -070040
Adam Lesinskice5e56e2016-10-21 17:56:45 -070041 std::unique_ptr<XmlResource> doc =
42 test::BuildXmlDom("<manifest><application /></manifest>");
Adam Lesinskicc5609d2016-04-05 12:41:07 -070043
Adam Lesinskice5e56e2016-10-21 17:56:45 -070044 StdErrDiagnostics diag;
45 ASSERT_TRUE(
46 executor.Execute(XmlActionExecutorPolicy::kNone, &diag, doc.get()));
47 ASSERT_NE(nullptr, manifest_el);
48 EXPECT_EQ(std::string("manifest"), manifest_el->name);
Adam Lesinskicc5609d2016-04-05 12:41:07 -070049
Adam Lesinskice5e56e2016-10-21 17:56:45 -070050 ASSERT_NE(nullptr, application_el);
51 EXPECT_EQ(std::string("application"), application_el->name);
Adam Lesinskicc5609d2016-04-05 12:41:07 -070052}
53
54TEST(XmlActionExecutorTest, FailsWhenUndefinedHierarchyExists) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070055 XmlActionExecutor executor;
56 executor["manifest"]["application"];
Adam Lesinskicc5609d2016-04-05 12:41:07 -070057
Adam Lesinskice5e56e2016-10-21 17:56:45 -070058 std::unique_ptr<XmlResource> doc =
59 test::BuildXmlDom("<manifest><application /><activity /></manifest>");
60 StdErrDiagnostics diag;
61 ASSERT_FALSE(
62 executor.Execute(XmlActionExecutorPolicy::kWhitelist, &diag, doc.get()));
Adam Lesinskicc5609d2016-04-05 12:41:07 -070063}
64
Adam Lesinskice5e56e2016-10-21 17:56:45 -070065} // namespace xml
66} // namespace aapt