diff options
author | Michael Schwartz | 2017-05-08 16:07:14 -0500 |
---|---|---|
committer | Yifan Hong | 2017-05-16 13:21:02 -0500 |
commit | 97dc0f94e3747da528bc2531a67c9c1ec193520c (patch) | |
tree | 574e38f12607804ac2780035cc337d6a8b0c3d1e /utils.h | |
parent | 4cec603d4baef149fbe02ce35190db01d0c757f5 (diff) | |
download | platform-system-libvintf-97dc0f94e3747da528bc2531a67c9c1ec193520c.tar.gz platform-system-libvintf-97dc0f94e3747da528bc2531a67c9c1ec193520c.tar.xz platform-system-libvintf-97dc0f94e3747da528bc2531a67c9c1ec193520c.zip |
VintfObject::verify() will fetch data from device
- If no info is provided then all data is fetched from device.
- Add hook to mock retrieving files from device.
- Add test.
- Print more detailed messages on AVB failures.
Test: Ran vintf_object_test and libvintf_test
Bug: 37863689
Bug: 36814984
Change-Id: Ia33f4e2e73c863bc0f8f68f5ed61c30df8eff53d
Merged-In: Ia33f4e2e73c863bc0f8f68f5ed61c30df8eff53d
Diffstat (limited to 'utils.h')
-rw-r--r-- | utils.h | 52 |
1 files changed, 41 insertions, 11 deletions
@@ -30,18 +30,48 @@ namespace android { | |||
30 | namespace vintf { | 30 | namespace vintf { |
31 | namespace details { | 31 | namespace details { |
32 | 32 | ||
33 | template<typename T> | 33 | // Return the file from the given location as a string. |
34 | status_t fetchAllInformation(const std::string &path, | 34 | // |
35 | const XmlConverter<T> &converter, T *outObject) { | 35 | // This class can be used to create a mock for overriding. |
36 | std::ifstream in; | 36 | class FileFetcher { |
37 | in.open(path); | 37 | public: |
38 | if (!in.is_open()) { | 38 | virtual ~FileFetcher() {} |
39 | LOG(WARNING) << "Cannot open " << path; | 39 | virtual status_t fetch(const std::string& path, std::string& fetched) { |
40 | return INVALID_OPERATION; | 40 | std::ifstream in; |
41 | |||
42 | in.open(path); | ||
43 | if (!in.is_open()) { | ||
44 | LOG(WARNING) << "Cannot open " << path; | ||
45 | return INVALID_OPERATION; | ||
46 | } | ||
47 | |||
48 | std::stringstream ss; | ||
49 | ss << in.rdbuf(); | ||
50 | fetched = ss.str(); | ||
51 | |||
52 | return OK; | ||
41 | } | 53 | } |
42 | std::stringstream ss; | 54 | }; |
43 | ss << in.rdbuf(); | 55 | |
44 | bool success = converter(outObject, ss.str()); | 56 | extern FileFetcher* gFetcher; |
57 | |||
58 | template <typename T> | ||
59 | status_t fetchAllInformation(const std::string& path, const XmlConverter<T>& converter, | ||
60 | T* outObject) { | ||
61 | std::string info; | ||
62 | |||
63 | if (gFetcher == nullptr) { | ||
64 | // Should never happen. | ||
65 | return NO_INIT; | ||
66 | } | ||
67 | |||
68 | status_t result = gFetcher->fetch(path, info); | ||
69 | |||
70 | if (result != OK) { | ||
71 | return result; | ||
72 | } | ||
73 | |||
74 | bool success = converter(outObject, info); | ||
45 | if (!success) { | 75 | if (!success) { |
46 | LOG(ERROR) << "Illformed file: " << path << ": " | 76 | LOG(ERROR) << "Illformed file: " << path << ": " |
47 | << converter.lastError(); | 77 | << converter.lastError(); |