AAPT2: Rename to match new style
Use Google3 naming style to match new
projects' and open source google projects' style.
Preferred to do this in a massive CL so as to avoid
style inconsistencies that plague legacy code bases.
This is a relatively NEW code base, may as well keep
it up to date.
Test: name/style refactor - existing tests pass
Change-Id: Ie80ecb78d46ec53efdfca2336bb57d96cbb7fb87
diff --git a/tools/aapt2/split/TableSplitter.cpp b/tools/aapt2/split/TableSplitter.cpp
index 08b9ee9..7aad86f 100644
--- a/tools/aapt2/split/TableSplitter.cpp
+++ b/tools/aapt2/split/TableSplitter.cpp
@@ -14,251 +14,278 @@
* limitations under the License.
*/
-#include "ConfigDescription.h"
-#include "ResourceTable.h"
#include "split/TableSplitter.h"
-#include "util/Util.h"
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <vector>
+#include "android-base/logging.h"
+
+#include "ConfigDescription.h"
+#include "ResourceTable.h"
+#include "util/Util.h"
namespace aapt {
using ConfigClaimedMap = std::unordered_map<ResourceConfigValue*, bool>;
-using ConfigDensityGroups = std::map<ConfigDescription, std::vector<ResourceConfigValue*>>;
+using ConfigDensityGroups =
+ std::map<ConfigDescription, std::vector<ResourceConfigValue*>>;
-static ConfigDescription copyWithoutDensity(const ConfigDescription& config) {
- ConfigDescription withoutDensity = config;
- withoutDensity.density = 0;
- return withoutDensity;
+static ConfigDescription CopyWithoutDensity(const ConfigDescription& config) {
+ ConfigDescription without_density = config;
+ without_density.density = 0;
+ return without_density;
}
/**
* Selects values that match exactly the constraints given.
*/
class SplitValueSelector {
-public:
- explicit SplitValueSelector(const SplitConstraints& constraints) {
- for (const ConfigDescription& config : constraints.configs) {
- if (config.density == 0) {
- mDensityIndependentConfigs.insert(config);
- } else {
- mDensityDependentConfigToDensityMap[copyWithoutDensity(config)] = config.density;
- }
+ public:
+ explicit SplitValueSelector(const SplitConstraints& constraints) {
+ for (const ConfigDescription& config : constraints.configs) {
+ if (config.density == 0) {
+ density_independent_configs_.insert(config);
+ } else {
+ density_dependent_config_to_density_map_[CopyWithoutDensity(config)] =
+ config.density;
+ }
+ }
+ }
+
+ std::vector<ResourceConfigValue*> SelectValues(
+ const ConfigDensityGroups& density_groups,
+ ConfigClaimedMap* claimed_values) {
+ std::vector<ResourceConfigValue*> selected;
+
+ // Select the regular values.
+ for (auto& entry : *claimed_values) {
+ // Check if the entry has a density.
+ ResourceConfigValue* config_value = entry.first;
+ if (config_value->config.density == 0 && !entry.second) {
+ // This is still available.
+ if (density_independent_configs_.find(config_value->config) !=
+ density_independent_configs_.end()) {
+ selected.push_back(config_value);
+
+ // Mark the entry as taken.
+ entry.second = true;
}
+ }
}
- std::vector<ResourceConfigValue*> selectValues(const ConfigDensityGroups& densityGroups,
- ConfigClaimedMap* claimedValues) {
- std::vector<ResourceConfigValue*> selected;
+ // Now examine the densities
+ for (auto& entry : density_groups) {
+ // We do not care if the value is claimed, since density values can be
+ // in multiple splits.
+ const ConfigDescription& config = entry.first;
+ const std::vector<ResourceConfigValue*>& related_values = entry.second;
+ auto density_value_iter =
+ density_dependent_config_to_density_map_.find(config);
+ if (density_value_iter !=
+ density_dependent_config_to_density_map_.end()) {
+ // Select the best one!
+ ConfigDescription target_density = config;
+ target_density.density = density_value_iter->second;
- // Select the regular values.
- for (auto& entry : *claimedValues) {
- // Check if the entry has a density.
- ResourceConfigValue* configValue = entry.first;
- if (configValue->config.density == 0 && !entry.second) {
- // This is still available.
- if (mDensityIndependentConfigs.find(configValue->config) !=
- mDensityIndependentConfigs.end()) {
- selected.push_back(configValue);
-
- // Mark the entry as taken.
- entry.second = true;
- }
- }
+ ResourceConfigValue* best_value = nullptr;
+ for (ResourceConfigValue* this_value : related_values) {
+ if (!best_value ||
+ this_value->config.isBetterThan(best_value->config,
+ &target_density)) {
+ best_value = this_value;
+ }
}
+ CHECK(best_value != nullptr);
- // Now examine the densities
- for (auto& entry : densityGroups) {
- // We do not care if the value is claimed, since density values can be
- // in multiple splits.
- const ConfigDescription& config = entry.first;
- const std::vector<ResourceConfigValue*>& relatedValues = entry.second;
- auto densityValueIter = mDensityDependentConfigToDensityMap.find(config);
- if (densityValueIter != mDensityDependentConfigToDensityMap.end()) {
- // Select the best one!
- ConfigDescription targetDensity = config;
- targetDensity.density = densityValueIter->second;
-
- ResourceConfigValue* bestValue = nullptr;
- for (ResourceConfigValue* thisValue : relatedValues) {
- if (!bestValue ||
- thisValue->config.isBetterThan(bestValue->config, &targetDensity)) {
- bestValue = thisValue;
- }
- }
- assert(bestValue);
-
- // When we select one of these, they are all claimed such that the base
- // doesn't include any anymore.
- (*claimedValues)[bestValue] = true;
- selected.push_back(bestValue);
- }
- }
- return selected;
+ // When we select one of these, they are all claimed such that the base
+ // doesn't include any anymore.
+ (*claimed_values)[best_value] = true;
+ selected.push_back(best_value);
+ }
}
+ return selected;
+ }
-private:
- std::set<ConfigDescription> mDensityIndependentConfigs;
- std::map<ConfigDescription, uint16_t> mDensityDependentConfigToDensityMap;
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SplitValueSelector);
+
+ std::set<ConfigDescription> density_independent_configs_;
+ std::map<ConfigDescription, uint16_t>
+ density_dependent_config_to_density_map_;
};
/**
- * Marking non-preferred densities as claimed will make sure the base doesn't include them,
+ * Marking non-preferred densities as claimed will make sure the base doesn't
+ * include them,
* leaving only the preferred density behind.
*/
-static void markNonPreferredDensitiesAsClaimed(uint16_t preferredDensity,
- const ConfigDensityGroups& densityGroups,
- ConfigClaimedMap* configClaimedMap) {
- for (auto& entry : densityGroups) {
- const ConfigDescription& config = entry.first;
- const std::vector<ResourceConfigValue*>& relatedValues = entry.second;
+static void MarkNonPreferredDensitiesAsClaimed(
+ uint16_t preferred_density, const ConfigDensityGroups& density_groups,
+ ConfigClaimedMap* config_claimed_map) {
+ for (auto& entry : density_groups) {
+ const ConfigDescription& config = entry.first;
+ const std::vector<ResourceConfigValue*>& related_values = entry.second;
- ConfigDescription targetDensity = config;
- targetDensity.density = preferredDensity;
- ResourceConfigValue* bestValue = nullptr;
- for (ResourceConfigValue* thisValue : relatedValues) {
- if (!bestValue) {
- bestValue = thisValue;
- } else if (thisValue->config.isBetterThan(bestValue->config, &targetDensity)) {
- // Claim the previous value so that it is not included in the base.
- (*configClaimedMap)[bestValue] = true;
- bestValue = thisValue;
- } else {
- // Claim this value so that it is not included in the base.
- (*configClaimedMap)[thisValue] = true;
- }
- }
- assert(bestValue);
+ ConfigDescription target_density = config;
+ target_density.density = preferred_density;
+ ResourceConfigValue* best_value = nullptr;
+ for (ResourceConfigValue* this_value : related_values) {
+ if (!best_value) {
+ best_value = this_value;
+ } else if (this_value->config.isBetterThan(best_value->config,
+ &target_density)) {
+ // Claim the previous value so that it is not included in the base.
+ (*config_claimed_map)[best_value] = true;
+ best_value = this_value;
+ } else {
+ // Claim this value so that it is not included in the base.
+ (*config_claimed_map)[this_value] = true;
+ }
}
+ CHECK(best_value != nullptr);
+ }
}
-bool TableSplitter::verifySplitConstraints(IAaptContext* context) {
- bool error = false;
- for (size_t i = 0; i < mSplitConstraints.size(); i++) {
- for (size_t j = i + 1; j < mSplitConstraints.size(); j++) {
- for (const ConfigDescription& config : mSplitConstraints[i].configs) {
- if (mSplitConstraints[j].configs.find(config) !=
- mSplitConstraints[j].configs.end()) {
- context->getDiagnostics()->error(DiagMessage() << "config '" << config
- << "' appears in multiple splits, "
- << "target split ambiguous");
- error = true;
- }
- }
+bool TableSplitter::VerifySplitConstraints(IAaptContext* context) {
+ bool error = false;
+ for (size_t i = 0; i < split_constraints_.size(); i++) {
+ for (size_t j = i + 1; j < split_constraints_.size(); j++) {
+ for (const ConfigDescription& config : split_constraints_[i].configs) {
+ if (split_constraints_[j].configs.find(config) !=
+ split_constraints_[j].configs.end()) {
+ context->GetDiagnostics()->Error(DiagMessage()
+ << "config '" << config
+ << "' appears in multiple splits, "
+ << "target split ambiguous");
+ error = true;
}
+ }
}
- return !error;
+ }
+ return !error;
}
-void TableSplitter::splitTable(ResourceTable* originalTable) {
- const size_t splitCount = mSplitConstraints.size();
- for (auto& pkg : originalTable->packages) {
- // Initialize all packages for splits.
- for (size_t idx = 0; idx < splitCount; idx++) {
- ResourceTable* splitTable = mSplits[idx].get();
- splitTable->createPackage(pkg->name, pkg->id);
- }
-
- for (auto& type : pkg->types) {
- if (type->type == ResourceType::kMipmap) {
- // Always keep mipmaps.
- continue;
- }
-
- for (auto& entry : type->entries) {
- if (mConfigFilter) {
- // First eliminate any resource that we definitely don't want.
- for (std::unique_ptr<ResourceConfigValue>& configValue : entry->values) {
- if (!mConfigFilter->match(configValue->config)) {
- // null out the entry. We will clean up and remove nulls at the end
- // for performance reasons.
- configValue.reset();
- }
- }
- }
-
- // Organize the values into two separate buckets. Those that are density-dependent
- // and those that are density-independent.
- // One density technically matches all density, it's just that some densities
- // match better. So we need to be aware of the full set of densities to make this
- // decision.
- ConfigDensityGroups densityGroups;
- ConfigClaimedMap configClaimedMap;
- for (const std::unique_ptr<ResourceConfigValue>& configValue : entry->values) {
- if (configValue) {
- configClaimedMap[configValue.get()] = false;
-
- if (configValue->config.density != 0) {
- // Create a bucket for this density-dependent config.
- densityGroups[copyWithoutDensity(configValue->config)]
- .push_back(configValue.get());
- }
- }
- }
-
- // First we check all the splits. If it doesn't match one of the splits, we
- // leave it in the base.
- for (size_t idx = 0; idx < splitCount; idx++) {
- const SplitConstraints& splitConstraint = mSplitConstraints[idx];
- ResourceTable* splitTable = mSplits[idx].get();
-
- // Select the values we want from this entry for this split.
- SplitValueSelector selector(splitConstraint);
- std::vector<ResourceConfigValue*> selectedValues =
- selector.selectValues(densityGroups, &configClaimedMap);
-
- // No need to do any work if we selected nothing.
- if (!selectedValues.empty()) {
- // Create the same resource structure in the split. We do this lazily
- // because we might not have actual values for each type/entry.
- ResourceTablePackage* splitPkg = splitTable->findPackage(pkg->name);
- ResourceTableType* splitType = splitPkg->findOrCreateType(type->type);
- if (!splitType->id) {
- splitType->id = type->id;
- splitType->symbolStatus = type->symbolStatus;
- }
-
- ResourceEntry* splitEntry = splitType->findOrCreateEntry(entry->name);
- if (!splitEntry->id) {
- splitEntry->id = entry->id;
- splitEntry->symbolStatus = entry->symbolStatus;
- }
-
- // Copy the selected values into the new Split Entry.
- for (ResourceConfigValue* configValue : selectedValues) {
- ResourceConfigValue* newConfigValue = splitEntry->findOrCreateValue(
- configValue->config, configValue->product);
- newConfigValue->value = std::unique_ptr<Value>(
- configValue->value->clone(&splitTable->stringPool));
- }
- }
- }
-
- if (mPreferredDensity) {
- markNonPreferredDensitiesAsClaimed(mPreferredDensity.value(),
- densityGroups,
- &configClaimedMap);
- }
-
- // All splits are handled, now check to see what wasn't claimed and remove
- // whatever exists in other splits.
- for (std::unique_ptr<ResourceConfigValue>& configValue : entry->values) {
- if (configValue && configClaimedMap[configValue.get()]) {
- // Claimed, remove from base.
- configValue.reset();
- }
- }
-
- // Now erase all nullptrs.
- entry->values.erase(
- std::remove(entry->values.begin(), entry->values.end(), nullptr),
- entry->values.end());
- }
- }
+void TableSplitter::SplitTable(ResourceTable* original_table) {
+ const size_t split_count = split_constraints_.size();
+ for (auto& pkg : original_table->packages) {
+ // Initialize all packages for splits.
+ for (size_t idx = 0; idx < split_count; idx++) {
+ ResourceTable* split_table = splits_[idx].get();
+ split_table->CreatePackage(pkg->name, pkg->id);
}
+
+ for (auto& type : pkg->types) {
+ if (type->type == ResourceType::kMipmap) {
+ // Always keep mipmaps.
+ continue;
+ }
+
+ for (auto& entry : type->entries) {
+ if (options_.config_filter) {
+ // First eliminate any resource that we definitely don't want.
+ for (std::unique_ptr<ResourceConfigValue>& config_value :
+ entry->values) {
+ if (!options_.config_filter->Match(config_value->config)) {
+ // null out the entry. We will clean up and remove nulls at the
+ // end for performance reasons.
+ config_value.reset();
+ }
+ }
+ }
+
+ // Organize the values into two separate buckets. Those that are
+ // density-dependent
+ // and those that are density-independent.
+ // One density technically matches all density, it's just that some
+ // densities
+ // match better. So we need to be aware of the full set of densities to
+ // make this
+ // decision.
+ ConfigDensityGroups density_groups;
+ ConfigClaimedMap config_claimed_map;
+ for (const std::unique_ptr<ResourceConfigValue>& config_value :
+ entry->values) {
+ if (config_value) {
+ config_claimed_map[config_value.get()] = false;
+
+ if (config_value->config.density != 0) {
+ // Create a bucket for this density-dependent config.
+ density_groups[CopyWithoutDensity(config_value->config)]
+ .push_back(config_value.get());
+ }
+ }
+ }
+
+ // First we check all the splits. If it doesn't match one of the splits,
+ // we
+ // leave it in the base.
+ for (size_t idx = 0; idx < split_count; idx++) {
+ const SplitConstraints& split_constraint = split_constraints_[idx];
+ ResourceTable* split_table = splits_[idx].get();
+
+ // Select the values we want from this entry for this split.
+ SplitValueSelector selector(split_constraint);
+ std::vector<ResourceConfigValue*> selected_values =
+ selector.SelectValues(density_groups, &config_claimed_map);
+
+ // No need to do any work if we selected nothing.
+ if (!selected_values.empty()) {
+ // Create the same resource structure in the split. We do this
+ // lazily because we might not have actual values for each
+ // type/entry.
+ ResourceTablePackage* split_pkg =
+ split_table->FindPackage(pkg->name);
+ ResourceTableType* split_type =
+ split_pkg->FindOrCreateType(type->type);
+ if (!split_type->id) {
+ split_type->id = type->id;
+ split_type->symbol_status = type->symbol_status;
+ }
+
+ ResourceEntry* split_entry =
+ split_type->FindOrCreateEntry(entry->name);
+ if (!split_entry->id) {
+ split_entry->id = entry->id;
+ split_entry->symbol_status = entry->symbol_status;
+ }
+
+ // Copy the selected values into the new Split Entry.
+ for (ResourceConfigValue* config_value : selected_values) {
+ ResourceConfigValue* new_config_value =
+ split_entry->FindOrCreateValue(config_value->config,
+ config_value->product);
+ new_config_value->value = std::unique_ptr<Value>(
+ config_value->value->Clone(&split_table->string_pool));
+ }
+ }
+ }
+
+ if (options_.preferred_density) {
+ MarkNonPreferredDensitiesAsClaimed(options_.preferred_density.value(),
+ density_groups,
+ &config_claimed_map);
+ }
+
+ // All splits are handled, now check to see what wasn't claimed and
+ // remove
+ // whatever exists in other splits.
+ for (std::unique_ptr<ResourceConfigValue>& config_value :
+ entry->values) {
+ if (config_value && config_claimed_map[config_value.get()]) {
+ // Claimed, remove from base.
+ config_value.reset();
+ }
+ }
+
+ // Now erase all nullptrs.
+ entry->values.erase(
+ std::remove(entry->values.begin(), entry->values.end(), nullptr),
+ entry->values.end());
+ }
+ }
+ }
}
-} // namespace aapt
+} // namespace aapt
diff --git a/tools/aapt2/split/TableSplitter.h b/tools/aapt2/split/TableSplitter.h
index d7ecc82..1ae3271 100644
--- a/tools/aapt2/split/TableSplitter.h
+++ b/tools/aapt2/split/TableSplitter.h
@@ -17,15 +17,15 @@
#ifndef AAPT_SPLIT_TABLESPLITTER_H
#define AAPT_SPLIT_TABLESPLITTER_H
+#include <set>
+#include <vector>
+#include "android-base/macros.h"
+
#include "ConfigDescription.h"
#include "ResourceTable.h"
#include "filter/ConfigFilter.h"
#include "process/IResourceTableConsumer.h"
-#include <android-base/macros.h>
-#include <set>
-#include <vector>
-
namespace aapt {
struct SplitConstraints {
@@ -36,39 +36,36 @@
/**
* The preferred density to keep in the table, stripping out all others.
*/
- Maybe<uint16_t> preferredDensity;
+ Maybe<uint16_t> preferred_density;
/**
* Configuration filter that determines which resource configuration values
* end up in
* the final table.
*/
- IConfigFilter* configFilter = nullptr;
+ IConfigFilter* config_filter = nullptr;
};
class TableSplitter {
public:
TableSplitter(const std::vector<SplitConstraints>& splits,
const TableSplitterOptions& options)
- : mSplitConstraints(splits),
- mPreferredDensity(options.preferredDensity),
- mConfigFilter(options.configFilter) {
- for (size_t i = 0; i < mSplitConstraints.size(); i++) {
- mSplits.push_back(util::make_unique<ResourceTable>());
+ : split_constraints_(splits), options_(options) {
+ for (size_t i = 0; i < split_constraints_.size(); i++) {
+ splits_.push_back(util::make_unique<ResourceTable>());
}
}
- bool verifySplitConstraints(IAaptContext* context);
+ bool VerifySplitConstraints(IAaptContext* context);
- void splitTable(ResourceTable* originalTable);
+ void SplitTable(ResourceTable* original_table);
- std::vector<std::unique_ptr<ResourceTable>>& getSplits() { return mSplits; }
+ std::vector<std::unique_ptr<ResourceTable>>& splits() { return splits_; }
private:
- std::vector<SplitConstraints> mSplitConstraints;
- std::vector<std::unique_ptr<ResourceTable>> mSplits;
- Maybe<uint16_t> mPreferredDensity;
- IConfigFilter* mConfigFilter;
+ std::vector<SplitConstraints> split_constraints_;
+ std::vector<std::unique_ptr<ResourceTable>> splits_;
+ TableSplitterOptions options_;
DISALLOW_COPY_AND_ASSIGN(TableSplitter);
};
diff --git a/tools/aapt2/split/TableSplitter_test.cpp b/tools/aapt2/split/TableSplitter_test.cpp
index 5150e82..088dac3 100644
--- a/tools/aapt2/split/TableSplitter_test.cpp
+++ b/tools/aapt2/split/TableSplitter_test.cpp
@@ -15,155 +15,192 @@
*/
#include "split/TableSplitter.h"
+
#include "test/Test.h"
namespace aapt {
TEST(TableSplitterTest, NoSplitPreferredDensity) {
- std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
- .addFileReference("android:drawable/icon", "res/drawable-mdpi/icon.png",
- test::parseConfigOrDie("mdpi"))
- .addFileReference("android:drawable/icon", "res/drawable-hdpi/icon.png",
- test::parseConfigOrDie("hdpi"))
- .addFileReference("android:drawable/icon", "res/drawable-xhdpi/icon.png",
- test::parseConfigOrDie("xhdpi"))
- .addFileReference("android:drawable/icon", "res/drawable-xxhdpi/icon.png",
- test::parseConfigOrDie("xxhdpi"))
- .addSimple("android:string/one")
- .build();
+ std::unique_ptr<ResourceTable> table =
+ test::ResourceTableBuilder()
+ .AddFileReference("android:drawable/icon",
+ "res/drawable-mdpi/icon.png",
+ test::ParseConfigOrDie("mdpi"))
+ .AddFileReference("android:drawable/icon",
+ "res/drawable-hdpi/icon.png",
+ test::ParseConfigOrDie("hdpi"))
+ .AddFileReference("android:drawable/icon",
+ "res/drawable-xhdpi/icon.png",
+ test::ParseConfigOrDie("xhdpi"))
+ .AddFileReference("android:drawable/icon",
+ "res/drawable-xxhdpi/icon.png",
+ test::ParseConfigOrDie("xxhdpi"))
+ .AddSimple("android:string/one")
+ .Build();
- TableSplitterOptions options;
- options.preferredDensity = ConfigDescription::DENSITY_XHIGH;
- TableSplitter splitter({}, options);
- splitter.splitTable(table.get());
+ TableSplitterOptions options;
+ options.preferred_density = ConfigDescription::DENSITY_XHIGH;
+ TableSplitter splitter({}, options);
+ splitter.SplitTable(table.get());
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(),
- "android:drawable/icon",
- test::parseConfigOrDie("mdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(),
- "android:drawable/icon",
- test::parseConfigOrDie("hdpi")));
- EXPECT_NE(nullptr, test::getValueForConfig<FileReference>(table.get(),
- "android:drawable/icon",
- test::parseConfigOrDie("xhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(),
- "android:drawable/icon",
- test::parseConfigOrDie("xxhdpi")));
- EXPECT_NE(nullptr, test::getValue<Id>(table.get(), "android:string/one"));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ table.get(), "android:drawable/icon",
+ test::ParseConfigOrDie("mdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ table.get(), "android:drawable/icon",
+ test::ParseConfigOrDie("hdpi")));
+ EXPECT_NE(nullptr, test::GetValueForConfig<FileReference>(
+ table.get(), "android:drawable/icon",
+ test::ParseConfigOrDie("xhdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ table.get(), "android:drawable/icon",
+ test::ParseConfigOrDie("xxhdpi")));
+ EXPECT_NE(nullptr, test::GetValue<Id>(table.get(), "android:string/one"));
}
TEST(TableSplitterTest, SplitTableByDensity) {
- std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
- .addFileReference("android:drawable/foo", "res/drawable-mdpi/foo.png",
- test::parseConfigOrDie("mdpi"))
- .addFileReference("android:drawable/foo", "res/drawable-hdpi/foo.png",
- test::parseConfigOrDie("hdpi"))
- .addFileReference("android:drawable/foo", "res/drawable-xhdpi/foo.png",
- test::parseConfigOrDie("xhdpi"))
- .addFileReference("android:drawable/foo", "res/drawable-xxhdpi/foo.png",
- test::parseConfigOrDie("xxhdpi"))
- .build();
+ std::unique_ptr<ResourceTable> table =
+ test::ResourceTableBuilder()
+ .AddFileReference("android:drawable/foo", "res/drawable-mdpi/foo.png",
+ test::ParseConfigOrDie("mdpi"))
+ .AddFileReference("android:drawable/foo", "res/drawable-hdpi/foo.png",
+ test::ParseConfigOrDie("hdpi"))
+ .AddFileReference("android:drawable/foo",
+ "res/drawable-xhdpi/foo.png",
+ test::ParseConfigOrDie("xhdpi"))
+ .AddFileReference("android:drawable/foo",
+ "res/drawable-xxhdpi/foo.png",
+ test::ParseConfigOrDie("xxhdpi"))
+ .Build();
- std::vector<SplitConstraints> constraints;
- constraints.push_back(SplitConstraints{ { test::parseConfigOrDie("mdpi") } });
- constraints.push_back(SplitConstraints{ { test::parseConfigOrDie("hdpi") } });
- constraints.push_back(SplitConstraints{ { test::parseConfigOrDie("xhdpi") } });
+ std::vector<SplitConstraints> constraints;
+ constraints.push_back(SplitConstraints{{test::ParseConfigOrDie("mdpi")}});
+ constraints.push_back(SplitConstraints{{test::ParseConfigOrDie("hdpi")}});
+ constraints.push_back(SplitConstraints{{test::ParseConfigOrDie("xhdpi")}});
- TableSplitter splitter(constraints, TableSplitterOptions{});
- splitter.splitTable(table.get());
+ TableSplitter splitter(constraints, TableSplitterOptions{});
+ splitter.SplitTable(table.get());
- ASSERT_EQ(3u, splitter.getSplits().size());
+ ASSERT_EQ(3u, splitter.splits().size());
- ResourceTable* splitOne = splitter.getSplits()[0].get();
- ResourceTable* splitTwo = splitter.getSplits()[1].get();
- ResourceTable* splitThree = splitter.getSplits()[2].get();
+ ResourceTable* split_one = splitter.splits()[0].get();
+ ResourceTable* split_two = splitter.splits()[1].get();
+ ResourceTable* split_three = splitter.splits()[2].get();
- // Just xxhdpi should be in the base.
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(), "android:drawable/foo",
- test::parseConfigOrDie("mdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(), "android:drawable/foo",
- test::parseConfigOrDie("hdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(table.get(), "android:drawable/foo",
- test::parseConfigOrDie("xhdpi")));
- EXPECT_NE(nullptr, test::getValueForConfig<FileReference>(table.get(), "android:drawable/foo",
- test::parseConfigOrDie("xxhdpi")));
+ // Just xxhdpi should be in the base.
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ table.get(), "android:drawable/foo",
+ test::ParseConfigOrDie("mdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ table.get(), "android:drawable/foo",
+ test::ParseConfigOrDie("hdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ table.get(), "android:drawable/foo",
+ test::ParseConfigOrDie("xhdpi")));
+ EXPECT_NE(nullptr, test::GetValueForConfig<FileReference>(
+ table.get(), "android:drawable/foo",
+ test::ParseConfigOrDie("xxhdpi")));
- // Each split should have one and only one drawable.
- EXPECT_NE(nullptr, test::getValueForConfig<FileReference>(splitOne, "android:drawable/foo",
- test::parseConfigOrDie("mdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitOne, "android:drawable/foo",
- test::parseConfigOrDie("hdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitOne, "android:drawable/foo",
- test::parseConfigOrDie("xhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitOne, "android:drawable/foo",
- test::parseConfigOrDie("xxhdpi")));
+ // Each split should have one and only one drawable.
+ EXPECT_NE(nullptr, test::GetValueForConfig<FileReference>(
+ split_one, "android:drawable/foo",
+ test::ParseConfigOrDie("mdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ split_one, "android:drawable/foo",
+ test::ParseConfigOrDie("hdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ split_one, "android:drawable/foo",
+ test::ParseConfigOrDie("xhdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ split_one, "android:drawable/foo",
+ test::ParseConfigOrDie("xxhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitTwo, "android:drawable/foo",
- test::parseConfigOrDie("mdpi")));
- EXPECT_NE(nullptr, test::getValueForConfig<FileReference>(splitTwo, "android:drawable/foo",
- test::parseConfigOrDie("hdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitTwo, "android:drawable/foo",
- test::parseConfigOrDie("xhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitTwo, "android:drawable/foo",
- test::parseConfigOrDie("xxhdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ split_two, "android:drawable/foo",
+ test::ParseConfigOrDie("mdpi")));
+ EXPECT_NE(nullptr, test::GetValueForConfig<FileReference>(
+ split_two, "android:drawable/foo",
+ test::ParseConfigOrDie("hdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ split_two, "android:drawable/foo",
+ test::ParseConfigOrDie("xhdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ split_two, "android:drawable/foo",
+ test::ParseConfigOrDie("xxhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitThree, "android:drawable/foo",
- test::parseConfigOrDie("mdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitThree, "android:drawable/foo",
- test::parseConfigOrDie("hdpi")));
- EXPECT_NE(nullptr, test::getValueForConfig<FileReference>(splitThree, "android:drawable/foo",
- test::parseConfigOrDie("xhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<FileReference>(splitThree, "android:drawable/foo",
- test::parseConfigOrDie("xxhdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ split_three, "android:drawable/foo",
+ test::ParseConfigOrDie("mdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ split_three, "android:drawable/foo",
+ test::ParseConfigOrDie("hdpi")));
+ EXPECT_NE(nullptr, test::GetValueForConfig<FileReference>(
+ split_three, "android:drawable/foo",
+ test::ParseConfigOrDie("xhdpi")));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<FileReference>(
+ split_three, "android:drawable/foo",
+ test::ParseConfigOrDie("xxhdpi")));
}
TEST(TableSplitterTest, SplitTableByConfigAndDensity) {
- ResourceTable table;
+ ResourceTable table;
- const ResourceName foo = test::parseNameOrDie("android:string/foo");
- ASSERT_TRUE(table.addResource(foo, test::parseConfigOrDie("land-hdpi"), {},
- util::make_unique<Id>(),
- test::getDiagnostics()));
- ASSERT_TRUE(table.addResource(foo, test::parseConfigOrDie("land-xhdpi"), {},
- util::make_unique<Id>(),
- test::getDiagnostics()));
- ASSERT_TRUE(table.addResource(foo, test::parseConfigOrDie("land-xxhdpi"), {},
- util::make_unique<Id>(),
- test::getDiagnostics()));
+ const ResourceName foo = test::ParseNameOrDie("android:string/foo");
+ ASSERT_TRUE(table.AddResource(foo, test::ParseConfigOrDie("land-hdpi"), {},
+ util::make_unique<Id>(),
+ test::GetDiagnostics()));
+ ASSERT_TRUE(table.AddResource(foo, test::ParseConfigOrDie("land-xhdpi"), {},
+ util::make_unique<Id>(),
+ test::GetDiagnostics()));
+ ASSERT_TRUE(table.AddResource(foo, test::ParseConfigOrDie("land-xxhdpi"), {},
+ util::make_unique<Id>(),
+ test::GetDiagnostics()));
- std::vector<SplitConstraints> constraints;
- constraints.push_back(SplitConstraints{ { test::parseConfigOrDie("land-mdpi") } });
- constraints.push_back(SplitConstraints{ { test::parseConfigOrDie("land-xhdpi") } });
+ std::vector<SplitConstraints> constraints;
+ constraints.push_back(
+ SplitConstraints{{test::ParseConfigOrDie("land-mdpi")}});
+ constraints.push_back(
+ SplitConstraints{{test::ParseConfigOrDie("land-xhdpi")}});
- TableSplitter splitter(constraints, TableSplitterOptions{});
- splitter.splitTable(&table);
+ TableSplitter splitter(constraints, TableSplitterOptions{});
+ splitter.SplitTable(&table);
- ASSERT_EQ(2u, splitter.getSplits().size());
+ ASSERT_EQ(2u, splitter.splits().size());
- ResourceTable* splitOne = splitter.getSplits()[0].get();
- ResourceTable* splitTwo = splitter.getSplits()[1].get();
+ ResourceTable* split_one = splitter.splits()[0].get();
+ ResourceTable* split_two = splitter.splits()[1].get();
- // All but the xxhdpi resource should be gone, since there were closer matches in land-xhdpi.
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(&table, "android:string/foo",
- test::parseConfigOrDie("land-hdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(&table, "android:string/foo",
- test::parseConfigOrDie("land-xhdpi")));
- EXPECT_NE(nullptr, test::getValueForConfig<Id>(&table, "android:string/foo",
- test::parseConfigOrDie("land-xxhdpi")));
+ // All but the xxhdpi resource should be gone, since there were closer matches
+ // in land-xhdpi.
+ EXPECT_EQ(nullptr,
+ test::GetValueForConfig<Id>(&table, "android:string/foo",
+ test::ParseConfigOrDie("land-hdpi")));
+ EXPECT_EQ(nullptr,
+ test::GetValueForConfig<Id>(&table, "android:string/foo",
+ test::ParseConfigOrDie("land-xhdpi")));
+ EXPECT_NE(nullptr,
+ test::GetValueForConfig<Id>(&table, "android:string/foo",
+ test::ParseConfigOrDie("land-xxhdpi")));
- EXPECT_NE(nullptr, test::getValueForConfig<Id>(splitOne, "android:string/foo",
- test::parseConfigOrDie("land-hdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitOne, "android:string/foo",
- test::parseConfigOrDie("land-xhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitOne, "android:string/foo",
- test::parseConfigOrDie("land-xxhdpi")));
+ EXPECT_NE(nullptr,
+ test::GetValueForConfig<Id>(split_one, "android:string/foo",
+ test::ParseConfigOrDie("land-hdpi")));
+ EXPECT_EQ(nullptr,
+ test::GetValueForConfig<Id>(split_one, "android:string/foo",
+ test::ParseConfigOrDie("land-xhdpi")));
+ EXPECT_EQ(nullptr,
+ test::GetValueForConfig<Id>(split_one, "android:string/foo",
+ test::ParseConfigOrDie("land-xxhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitTwo, "android:string/foo",
- test::parseConfigOrDie("land-hdpi")));
- EXPECT_NE(nullptr, test::getValueForConfig<Id>(splitTwo, "android:string/foo",
- test::parseConfigOrDie("land-xhdpi")));
- EXPECT_EQ(nullptr, test::getValueForConfig<Id>(splitTwo, "android:string/foo",
- test::parseConfigOrDie("land-xxhdpi")));
+ EXPECT_EQ(nullptr,
+ test::GetValueForConfig<Id>(split_two, "android:string/foo",
+ test::ParseConfigOrDie("land-hdpi")));
+ EXPECT_NE(nullptr,
+ test::GetValueForConfig<Id>(split_two, "android:string/foo",
+ test::ParseConfigOrDie("land-xhdpi")));
+ EXPECT_EQ(nullptr,
+ test::GetValueForConfig<Id>(split_two, "android:string/foo",
+ test::ParseConfigOrDie("land-xxhdpi")));
}
-} // namespace aapt
+} // namespace aapt