Files
slsDetectorPackage/slsDetectorSoftware/tests/master_file/Context.h
T
2e4cd258a8
Build on RHEL9 docker image / build (push) Successful in 4m1s
Build on RHEL8 docker image / build (push) Successful in 5m1s
Build and Deploy on local RHEL9 / build (push) Successful in 2m1s
Build and Deploy on local RHEL8 / build (push) Successful in 5m7s
Run Simulator Tests on local RHEL9 / build (push) Successful in 18m37s
Run Simulator Tests on local RHEL8 / build (push) Successful in 22m10s
Dev/refactor caller tests master attributes (#1462)
* refactoring

* wip

* refactored, yet to take out checkers

* checker added

* wip acquire ctb state

* wip acquire ctb state

* wip, acq test

* acquire moved out

* fix

* wip, To fix masterattribtues

* wip, masterfilecheks

* wip, at ctbexpectedstate

* wip, fixing acquire

* wip, acquire done

* wip

* compiles

* refactoring

* minor

* minor

* reduced unnecessary includes

* fix in tests

* removed ctb state check

* ctb fix with ctb state

* fixed ctb guard tests

* minor debug

* work for xilinx ctb

---------

Co-authored-by: Erik Fröjdh <erik.frojdh@gmail.com>
2026-06-10 17:30:30 +02:00

64 lines
1.6 KiB
C++

// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
#include "catch.hpp"
#include <filesystem>
#include <fstream>
#include <optional>
#include <rapidjson/document.h>
#include <rapidjson/error/en.h>
#include <sstream>
#include <string>
#ifdef HDF5C
#include "H5Cpp.h"
#endif
namespace sls::test::master_file {
struct JsonContext {
rapidjson::Document doc;
explicit JsonContext(const std::string &path) {
parse_binary_master_attributes(path);
}
private:
void parse_binary_master_attributes(const std::string &file_path) {
REQUIRE(std::filesystem::exists(file_path));
std::ifstream file(file_path);
REQUIRE(file.is_open());
std::stringstream buffer;
buffer << file.rdbuf();
std::string json_str = buffer.str();
rapidjson::ParseResult result = doc.Parse(json_str.c_str());
if (!result) {
std::cout << "JSON parse error: " << GetParseError_En(result.Code())
<< " (at offset " << result.Offset() << ")" << std::endl;
size_t offset = result.Offset();
std::string context =
json_str.substr(std::max(0, (int)offset - 20), 40);
std::cout << "Context around error: \"" << context << "\""
<< std::endl;
}
REQUIRE(result);
}
};
#ifdef HDF5C
struct H5Context {
H5::H5File file;
explicit H5Context(const std::string &path) : file(path, H5F_ACC_RDONLY) {}
};
#endif
} // namespace sls::test::master_file