summaryrefslogtreecommitdiff
path: root/test/yaml-parser.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-05-24 18:29:32 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-06-16 02:43:47 +0300
commitd6d0a675bfe27420d14394ef6b0da5247ea63d87 (patch)
treeff4e62ad8017165de3bb76925cc7baa0cf97b9c1 /test/yaml-parser.cpp
parent27fb47f70b55000fbd793c40377c20d915216f70 (diff)
libcamera: yaml_parser: Switch from FILE to File
THe FILE object isn't very user-friendly as it requires manual close. Replace it with File to provide RAII-style resource management in the YamlParser API. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Diffstat (limited to 'test/yaml-parser.cpp')
-rw-r--r--test/yaml-parser.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp
index c5b4ddbb..e75f8fe8 100644
--- a/test/yaml-parser.cpp
+++ b/test/yaml-parser.cpp
@@ -9,6 +9,8 @@
#include <string>
#include <unistd.h>
+#include <libcamera/base/file.h>
+
#include "libcamera/internal/yaml_parser.h"
#include "test.h"
@@ -69,29 +71,27 @@ protected:
int run()
{
/* Test invalid YAML file */
- FILE *fh = fopen(invalidYamlFile_.c_str(), "r");
- if (!fh) {
+ File file{ invalidYamlFile_ };
+ if (!file.open(File::OpenModeFlag::ReadOnly)) {
cerr << "Fail to open invalid YAML file" << std::endl;
return TestFail;
}
- std::unique_ptr<YamlObject> root = YamlParser::parse(fh);
- fclose(fh);
-
+ std::unique_ptr<YamlObject> root = YamlParser::parse(file);
if (root) {
cerr << "Invalid YAML file parse successfully" << std::endl;
return TestFail;
}
/* Test YAML file */
- fh = fopen(testYamlFile_.c_str(), "r");
- if (!fh) {
+ file.close();
+ file.setFileName(testYamlFile_);
+ if (!file.open(File::OpenModeFlag::ReadOnly)) {
cerr << "Fail to open test YAML file" << std::endl;
return TestFail;
}
- root = YamlParser::parse(fh);
- fclose(fh);
+ root = YamlParser::parse(file);
if (!root) {
cerr << "Fail to parse test YAML file: " << std::endl;