AAPT2: Allow merging of Style attributes from overlays
Previously style overlays would completely override an existing style.
To be compatible with AAPT, styles now merge with the overlay, allowing
the overlay's attributes and parent to take precedence.
Bug: 38355988
Test: make aapt2_tests
Change-Id: Id25c7240050a43e6a4a177c6e3d51e048d0cceb5
diff --git a/tools/aapt2/test/Common.h b/tools/aapt2/test/Common.h
index 248921f..a937de8 100644
--- a/tools/aapt2/test/Common.h
+++ b/tools/aapt2/test/Common.h
@@ -22,12 +22,14 @@
#include "android-base/logging.h"
#include "android-base/macros.h"
#include "androidfw/StringPiece.h"
+#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ConfigDescription.h"
#include "Debug.h"
#include "ResourceTable.h"
#include "ResourceUtils.h"
+#include "ResourceValues.h"
#include "ValueVisitor.h"
#include "io/File.h"
#include "process/IResourceTableConsumer.h"
@@ -51,13 +53,11 @@
return;
case Level::Warn:
- std::cerr << actual_msg.source << ": warn: " << actual_msg.message
- << "." << std::endl;
+ std::cerr << actual_msg.source << ": warn: " << actual_msg.message << "." << std::endl;
break;
case Level::Error:
- std::cerr << actual_msg.source << ": error: " << actual_msg.message
- << "." << std::endl;
+ std::cerr << actual_msg.source << ": error: " << actual_msg.message << "." << std::endl;
break;
}
}
@@ -84,11 +84,9 @@
T* GetValueForConfigAndProduct(ResourceTable* table, const android::StringPiece& res_name,
const ConfigDescription& config,
const android::StringPiece& product) {
- Maybe<ResourceTable::SearchResult> result =
- table->FindResource(ParseNameOrDie(res_name));
+ Maybe<ResourceTable::SearchResult> result = table->FindResource(ParseNameOrDie(res_name));
if (result) {
- ResourceConfigValue* config_value =
- result.value().entry->FindValue(config, product);
+ ResourceConfigValue* config_value = result.value().entry->FindValue(config, product);
if (config_value) {
return ValueCast<T>(config_value->value.get());
}
@@ -111,9 +109,13 @@
public:
explicit TestFile(const android::StringPiece& path) : source_(path) {}
- std::unique_ptr<io::IData> OpenAsData() override { return {}; }
+ std::unique_ptr<io::IData> OpenAsData() override {
+ return {};
+ }
- const Source& GetSource() const override { return source_; }
+ const Source& GetSource() const override {
+ return source_;
+ }
private:
DISALLOW_COPY_AND_ASSIGN(TestFile);
@@ -122,6 +124,47 @@
};
} // namespace test
+
+// Workaround gtest bug (https://github.com/google/googletest/issues/443)
+// that does not select base class operator<< for derived class T.
+template <typename T>
+typename std::enable_if<std::is_base_of<Value, T>::value, std::ostream&>::type operator<<(
+ std::ostream& out, const T& value) {
+ value.Print(&out);
+ return out;
+}
+
+template std::ostream& operator<<<Item>(std::ostream&, const Item&);
+template std::ostream& operator<<<Reference>(std::ostream&, const Reference&);
+template std::ostream& operator<<<Id>(std::ostream&, const Id&);
+template std::ostream& operator<<<RawString>(std::ostream&, const RawString&);
+template std::ostream& operator<<<String>(std::ostream&, const String&);
+template std::ostream& operator<<<StyledString>(std::ostream&, const StyledString&);
+template std::ostream& operator<<<FileReference>(std::ostream&, const FileReference&);
+template std::ostream& operator<<<BinaryPrimitive>(std::ostream&, const BinaryPrimitive&);
+template std::ostream& operator<<<Attribute>(std::ostream&, const Attribute&);
+template std::ostream& operator<<<Style>(std::ostream&, const Style&);
+template std::ostream& operator<<<Array>(std::ostream&, const Array&);
+template std::ostream& operator<<<Plural>(std::ostream&, const Plural&);
+
+// Add a print method to Maybe.
+template <typename T>
+void PrintTo(const Maybe<T>& value, std::ostream* out) {
+ if (value) {
+ *out << ::testing::PrintToString(value.value());
+ } else {
+ *out << "Nothing";
+ }
+}
+
+namespace test {
+
+MATCHER_P(ValueEq, a,
+ std::string(negation ? "isn't" : "is") + " equal to " + ::testing::PrintToString(a)) {
+ return arg.Equals(&a);
+}
+
+} // namespace test
} // namespace aapt
#endif /* AAPT_TEST_COMMON_H */
diff --git a/tools/aapt2/test/Test.h b/tools/aapt2/test/Test.h
index ec07432..a24c01c 100644
--- a/tools/aapt2/test/Test.h
+++ b/tools/aapt2/test/Test.h
@@ -17,6 +17,7 @@
#ifndef AAPT_TEST_TEST_H
#define AAPT_TEST_TEST_H
+#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "test/Builders.h"