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 
17 #ifndef TEST_HELPERS_H_
18 #define TEST_HELPERS_H_
19 
20 #include <ostream>
21 #include <string>
22 #include <vector>
23 
24 #include "androidfw/ResourceTypes.h"
25 #include "gtest/gtest.h"
26 #include "utils/String16.h"
27 #include "utils/String8.h"
28 
29 static inline ::std::ostream& operator<<(::std::ostream& out, const android::String8& str) {
30   return out << str.string();
31 }
32 
33 static inline ::std::ostream& operator<<(::std::ostream& out, const android::String16& str) {
34   return out << android::String8(str).string();
35 }
36 
37 namespace android {
38 
39 void InitializeTest(int* argc, char** argv);
40 
41 enum { MAY_NOT_BE_BAG = false };
42 
43 void SetTestDataPath(const std::string& path);
44 
45 const std::string& GetTestDataPath();
46 
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) {
52   return a.compare(b) == 0;
53 }
54 
55 static inline ::std::ostream& operator<<(::std::ostream& out, const ResTable_config& c) {
56   return out << c.toString().string();
57 }
58 
59 ::testing::AssertionResult IsStringEqual(const ResTable& table, uint32_t resource_id,
60                                          const char* expected_str);
61 
62 std::string GetStringFromPool(const ResStringPool* pool, uint32_t idx);
63 
64 }  // namespace android
65 
66 #endif  // TEST_HELPERS_H_
67