/* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ManifestMerger.h" #include "SourceXmlPullParser.h" #include #include #include namespace aapt { constexpr const char* kAppManifest = R"EOF( )EOF"; constexpr const char* kLibManifest = R"EOF( )EOF"; constexpr const char* kBadLibManifest = R"EOF( )EOF"; TEST(ManifestMergerTest, MergeManifestsSuccess) { std::stringstream inA(kAppManifest); std::stringstream inB(kLibManifest); const Source sourceA = { "AndroidManifest.xml" }; const Source sourceB = { "lib.apk/AndroidManifest.xml" }; SourceLogger loggerA(sourceA); SourceLogger loggerB(sourceB); ManifestMerger merger({}); EXPECT_TRUE(merger.setAppManifest(sourceA, u"com.android.example", xml::inflate(&inA, &loggerA))); EXPECT_TRUE(merger.mergeLibraryManifest(sourceB, u"com.android.library", xml::inflate(&inB, &loggerB))); } TEST(ManifestMergerTest, MergeManifestFail) { std::stringstream inA(kAppManifest); std::stringstream inB(kBadLibManifest); const Source sourceA = { "AndroidManifest.xml" }; const Source sourceB = { "lib.apk/AndroidManifest.xml" }; SourceLogger loggerA(sourceA); SourceLogger loggerB(sourceB); ManifestMerger merger({}); EXPECT_TRUE(merger.setAppManifest(sourceA, u"com.android.example", xml::inflate(&inA, &loggerA))); EXPECT_FALSE(merger.mergeLibraryManifest(sourceB, u"com.android.library", xml::inflate(&inB, &loggerB))); } } // namespace aapt