Adam Lesinski | 7a37b74 | 2016-10-12 14:05:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Adam Lesinski | ea78979 | 2016-11-10 14:33:11 -0800 | [diff] [blame] | 17 | #ifndef TEST_HELPERS_H_ |
| 18 | #define TEST_HELPERS_H_ |
Adam Lesinski | 7a37b74 | 2016-10-12 14:05:55 -0700 | [diff] [blame] | 19 | |
| 20 | #include <ostream> |
| 21 | #include <string> |
Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 22 | #include <vector> |
Adam Lesinski | 7a37b74 | 2016-10-12 14:05:55 -0700 | [diff] [blame] | 23 | |
Adam Lesinski | ea78979 | 2016-11-10 14:33:11 -0800 | [diff] [blame] | 24 | #include "androidfw/ResourceTypes.h" |
| 25 | #include "gtest/gtest.h" |
| 26 | #include "utils/String16.h" |
| 27 | #include "utils/String8.h" |
Adam Lesinski | f90f2f8d | 2014-06-06 14:27:00 -0700 | [diff] [blame] | 28 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame] | 29 | static inline ::std::ostream& operator<<(::std::ostream& out, const android::String8& str) { |
Adam Lesinski | 7a37b74 | 2016-10-12 14:05:55 -0700 | [diff] [blame] | 30 | return out << str.string(); |
Adam Lesinski | f90f2f8d | 2014-06-06 14:27:00 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame] | 33 | static inline ::std::ostream& operator<<(::std::ostream& out, const android::String16& str) { |
Adam Lesinski | 7a37b74 | 2016-10-12 14:05:55 -0700 | [diff] [blame] | 34 | return out << android::String8(str).string(); |
Adam Lesinski | f90f2f8d | 2014-06-06 14:27:00 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Adam Lesinski | 31245b4 | 2014-08-22 19:10:56 -0700 | [diff] [blame] | 37 | namespace android { |
| 38 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 39 | void InitializeTest(int* argc, char** argv); |
| 40 | |
Adam Lesinski | 6029319 | 2014-10-21 18:36:42 -0700 | [diff] [blame] | 41 | enum { MAY_NOT_BE_BAG = false }; |
| 42 | |
Adam Lesinski | ea78979 | 2016-11-10 14:33:11 -0800 | [diff] [blame] | 43 | void SetTestDataPath(const std::string& path); |
| 44 | |
| 45 | const std::string& GetTestDataPath(); |
| 46 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame] | 47 | ::testing::AssertionResult ReadFileFromZipToString(const std::string& zip_path, |
| 48 | const std::string& file, |
| 49 | std::string* out_contents); |
| 50 | |
| 51 | static inline bool operator==(const ResTable_config& a, const ResTable_config& b) { |
Adam Lesinski | 7a37b74 | 2016-10-12 14:05:55 -0700 | [diff] [blame] | 52 | return a.compare(b) == 0; |
Adam Lesinski | 31245b4 | 2014-08-22 19:10:56 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame] | 55 | static inline ::std::ostream& operator<<(::std::ostream& out, const ResTable_config& c) { |
Adam Lesinski | 7a37b74 | 2016-10-12 14:05:55 -0700 | [diff] [blame] | 56 | return out << c.toString().string(); |
Adam Lesinski | 31245b4 | 2014-08-22 19:10:56 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Adam Lesinski | 4c67a47 | 2016-11-10 16:43:59 -0800 | [diff] [blame] | 59 | ::testing::AssertionResult IsStringEqual(const ResTable& table, uint32_t resource_id, |
Adam Lesinski | 7a37b74 | 2016-10-12 14:05:55 -0700 | [diff] [blame] | 60 | const char* expected_str); |
Adam Lesinski | 6029319 | 2014-10-21 18:36:42 -0700 | [diff] [blame] | 61 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 62 | std::string GetStringFromPool(const ResStringPool* pool, uint32_t idx); |
| 63 | |
Adam Lesinski | 7a37b74 | 2016-10-12 14:05:55 -0700 | [diff] [blame] | 64 | } // namespace android |
Adam Lesinski | 31245b4 | 2014-08-22 19:10:56 -0700 | [diff] [blame] | 65 | |
Adam Lesinski | ea78979 | 2016-11-10 14:33:11 -0800 | [diff] [blame] | 66 | #endif // TEST_HELPERS_H_ |