• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 #include "xml/XmlActionExecutor.h"
18 
19 #include "test/Test.h"
20 
21 namespace aapt {
22 namespace xml {
23 
TEST(XmlActionExecutorTest,BuildsAccessibleNestedPattern)24 TEST(XmlActionExecutorTest, BuildsAccessibleNestedPattern) {
25   XmlActionExecutor executor;
26   XmlNodeAction& manifest_action = executor["manifest"];
27   XmlNodeAction& application_action = manifest_action["application"];
28 
29   Element* manifest_el = nullptr;
30   manifest_action.Action([&](Element* manifest) -> bool {
31     manifest_el = manifest;
32     return true;
33   });
34 
35   Element* application_el = nullptr;
36   application_action.Action([&](Element* application) -> bool {
37     application_el = application;
38     return true;
39   });
40 
41   std::unique_ptr<XmlResource> doc =
42       test::BuildXmlDom("<manifest><application /></manifest>");
43 
44   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);
49 
50   ASSERT_NE(nullptr, application_el);
51   EXPECT_EQ(std::string("application"), application_el->name);
52 }
53 
TEST(XmlActionExecutorTest,FailsWhenUndefinedHierarchyExists)54 TEST(XmlActionExecutorTest, FailsWhenUndefinedHierarchyExists) {
55   XmlActionExecutor executor;
56   executor["manifest"]["application"];
57 
58   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()));
63 }
64 
65 }  // namespace xml
66 }  // namespace aapt
67