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>
This commit is contained in:
Laurent Pinchart 2022-05-24 18:29:32 +03:00
parent 27fb47f70b
commit d6d0a675bf
4 changed files with 47 additions and 30 deletions

View file

@ -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;