blob: d9cee22a15935ef68d497f2b9ea2ae651e815067 [file] [log] [blame]
Adam Lesinski7a37b742016-10-12 14:05:55 -07001/*
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 Lesinskiea789792016-11-10 14:33:11 -080017#ifndef TEST_HELPERS_H_
18#define TEST_HELPERS_H_
Adam Lesinski7a37b742016-10-12 14:05:55 -070019
20#include <ostream>
21#include <string>
22
Adam Lesinskiea789792016-11-10 14:33:11 -080023#include "androidfw/ResourceTypes.h"
24#include "gtest/gtest.h"
25#include "utils/String16.h"
26#include "utils/String8.h"
Adam Lesinskif90f2f8d2014-06-06 14:27:00 -070027
Adam Lesinski4c67a472016-11-10 16:43:59 -080028static inline ::std::ostream& operator<<(::std::ostream& out, const android::String8& str) {
Adam Lesinski7a37b742016-10-12 14:05:55 -070029 return out << str.string();
Adam Lesinskif90f2f8d2014-06-06 14:27:00 -070030}
31
Adam Lesinski4c67a472016-11-10 16:43:59 -080032static inline ::std::ostream& operator<<(::std::ostream& out, const android::String16& str) {
Adam Lesinski7a37b742016-10-12 14:05:55 -070033 return out << android::String8(str).string();
Adam Lesinskif90f2f8d2014-06-06 14:27:00 -070034}
35
Adam Lesinski31245b42014-08-22 19:10:56 -070036namespace android {
37
Adam Lesinski60293192014-10-21 18:36:42 -070038enum { MAY_NOT_BE_BAG = false };
39
Adam Lesinskiea789792016-11-10 14:33:11 -080040void SetTestDataPath(const std::string& path);
41
42const std::string& GetTestDataPath();
43
Adam Lesinski4c67a472016-11-10 16:43:59 -080044::testing::AssertionResult ReadFileFromZipToString(const std::string& zip_path,
45 const std::string& file,
46 std::string* out_contents);
47
48static inline bool operator==(const ResTable_config& a, const ResTable_config& b) {
Adam Lesinski7a37b742016-10-12 14:05:55 -070049 return a.compare(b) == 0;
Adam Lesinski31245b42014-08-22 19:10:56 -070050}
51
Adam Lesinski4c67a472016-11-10 16:43:59 -080052static inline ::std::ostream& operator<<(::std::ostream& out, const ResTable_config& c) {
Adam Lesinski7a37b742016-10-12 14:05:55 -070053 return out << c.toString().string();
Adam Lesinski31245b42014-08-22 19:10:56 -070054}
55
Adam Lesinski4c67a472016-11-10 16:43:59 -080056::testing::AssertionResult IsStringEqual(const ResTable& table, uint32_t resource_id,
Adam Lesinski7a37b742016-10-12 14:05:55 -070057 const char* expected_str);
Adam Lesinski60293192014-10-21 18:36:42 -070058
Adam Lesinski7a37b742016-10-12 14:05:55 -070059} // namespace android
Adam Lesinski31245b42014-08-22 19:10:56 -070060
Adam Lesinskiea789792016-11-10 14:33:11 -080061#endif // TEST_HELPERS_H_