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
diff --git a/utils.h b/utils.h
index 3c06817..2c5f813 100644
--- a/utils.h
+++ b/utils.h
@@ -30,18 +30,48 @@
 namespace vintf {
 namespace details {
 
-template<typename T>
-status_t fetchAllInformation(const std::string &path,
-        const XmlConverter<T> &converter, T *outObject) {
-    std::ifstream in;
-    in.open(path);
-    if (!in.is_open()) {
-        LOG(WARNING) << "Cannot open " << path;
-        return INVALID_OPERATION;
+// Return the file from the given location as a string.
+//
+// This class can be used to create a mock for overriding.
+class FileFetcher {
+   public:
+    virtual ~FileFetcher() {}
+    virtual status_t fetch(const std::string& path, std::string& fetched) {
+        std::ifstream in;
+
+        in.open(path);
+        if (!in.is_open()) {
+            LOG(WARNING) << "Cannot open " << path;
+            return INVALID_OPERATION;
+        }
+
+        std::stringstream ss;
+        ss << in.rdbuf();
+        fetched = ss.str();
+
+        return OK;
     }
-    std::stringstream ss;
-    ss << in.rdbuf();
-    bool success = converter(outObject, ss.str());
+};
+
+extern FileFetcher* gFetcher;
+
+template <typename T>
+status_t fetchAllInformation(const std::string& path, const XmlConverter<T>& converter,
+                             T* outObject) {
+    std::string info;
+
+    if (gFetcher == nullptr) {
+        // Should never happen.
+        return NO_INIT;
+    }
+
+    status_t result = gFetcher->fetch(path, info);
+
+    if (result != OK) {
+        return result;
+    }
+
+    bool success = converter(outObject, info);
     if (!success) {
         LOG(ERROR) << "Illformed file: " << path << ": "
                    << converter.lastError();