1 /*
2 * Copyright (C) 2014 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 "TestHelpers.h"
18
19 #include <androidfw/ResourceTypes.h>
20 #include <utils/String8.h>
21 #include <gtest/gtest.h>
22
23 namespace android {
24
IsStringEqual(const ResTable & table,uint32_t resourceId,const char * expectedStr)25 ::testing::AssertionResult IsStringEqual(const ResTable& table, uint32_t resourceId, const char* expectedStr) {
26 Res_value val;
27 ssize_t block = table.getResource(resourceId, &val, MAY_NOT_BE_BAG);
28 if (block < 0) {
29 return ::testing::AssertionFailure() << "could not find resource";
30 }
31
32 if (val.dataType != Res_value::TYPE_STRING) {
33 return ::testing::AssertionFailure() << "resource is not a string";
34 }
35
36 const ResStringPool* pool = table.getTableStringBlock(block);
37 if (pool == NULL) {
38 return ::testing::AssertionFailure() << "table has no string pool for block " << block;
39 }
40
41 const String8 actual = pool->string8ObjectAt(val.data);
42 if (String8(expectedStr) != actual) {
43 return ::testing::AssertionFailure() << actual.string();
44 }
45 return ::testing::AssertionSuccess() << actual.string();
46 }
47
48 } // namespace android
49