blob: cdf24534184451572cd91be7b7fd6cf678442260 [file] [log] [blame]
Adam Lesinskibab4ef52017-06-01 15:22:57 -07001/*
2 * Copyright (C) 2017 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 "test/Common.h"
18
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +020019using android::ConfigDescription;
20
Adam Lesinskibab4ef52017-06-01 15:22:57 -070021namespace aapt {
22namespace test {
23
Jeremy Meyer56f36e82022-05-20 20:35:42 +000024struct TestDiagnosticsImpl : public android::IDiagnostics {
25 void Log(Level level, android::DiagMessageActual& actual_msg) override {
Adam Lesinskibab4ef52017-06-01 15:22:57 -070026 switch (level) {
27 case Level::Note:
28 return;
29
30 case Level::Warn:
31 std::cerr << actual_msg.source << ": warn: " << actual_msg.message << "." << std::endl;
32 break;
33
34 case Level::Error:
35 std::cerr << actual_msg.source << ": error: " << actual_msg.message << "." << std::endl;
36 break;
37 }
38 }
39};
40
Jeremy Meyer56f36e82022-05-20 20:35:42 +000041android::IDiagnostics* GetDiagnostics() {
Ryan Mitchell4ea90752020-07-31 08:21:43 -070042 static TestDiagnosticsImpl diag;
Adam Lesinskibab4ef52017-06-01 15:22:57 -070043 return &diag;
44}
45
46template <>
Yurii Zubrytskyia5775142022-11-02 17:49:49 -070047Value* GetValueForConfigAndProduct<Value>(ResourceTable* table, android::StringPiece res_name,
Adam Lesinskibab4ef52017-06-01 15:22:57 -070048 const ConfigDescription& config,
Yurii Zubrytskyia5775142022-11-02 17:49:49 -070049 android::StringPiece product) {
Ryan Mitchell4382e442021-07-14 12:53:01 -070050 std::optional<ResourceTable::SearchResult> result = table->FindResource(ParseNameOrDie(res_name));
Adam Lesinskibab4ef52017-06-01 15:22:57 -070051 if (result) {
52 ResourceConfigValue* config_value = result.value().entry->FindValue(config, product);
53 if (config_value) {
54 return config_value->value.get();
55 }
56 }
57 return nullptr;
58}
59
60} // namespace test
61} // namespace aapt