Files
slsDetectorPackage/slsDetectorSoftware/tests/master_file/Checker.h
T
maliakal_d 8f3b9ce26b
Build on RHEL9 docker image / build (push) Successful in 3m43s
Build on RHEL8 docker image / build (push) Successful in 5m21s
Run Simulator Tests on local RHEL9 / build (push) Failing after 9m36s
Run Simulator Tests on local RHEL8 / build (push) Failing after 11m32s
extra tests
2026-06-11 14:26:30 +02:00

78 lines
1.9 KiB
C++

// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
#include "Readers.h"
#include "ReadersJson.h"
#ifdef HDF5C
#include "ReadersH5.h"
#endif
#include "catch.hpp"
namespace sls::test::master_file {
template <typename Context> class Checker;
/** JSON Specialization */
template <> class Checker<JsonContext> {
public:
explicit Checker(const std::string &path) : ctx_(path) {}
explicit Checker(JsonContext ctx) : ctx_(std::move(ctx)) {}
const JsonContext &context() const { return ctx_; }
template <typename T>
void check(const std::string &name, const T &expected,
AccessType = AccessType::Dataset) const {
CAPTURE(name);
REQUIRE(ctx_.doc.HasMember(name.c_str()));
auto retval = read<JsonContext, T>(ctx_, name);
REQUIRE(retval == expected);
}
private:
JsonContext ctx_;
};
/** HDF5 Specialization */
#ifdef HDF5C
template <> class Checker<H5Context> {
public:
explicit Checker(const std::string &path) : ctx_(path) {}
explicit Checker(H5Context ctx) : ctx_(std::move(ctx)) {}
const H5Context &context() const { return ctx_; }
template <typename T>
void check(const std::string &name, const T &expected,
AccessType access = AccessType::Dataset) const {
auto retval = read<H5Context, T>(ctx_, name, access);
REQUIRE(retval == expected);
}
private:
H5Context ctx_;
};
#endif
template <typename F>
void with_checker(const std::string &fname, defs::fileFormat format,
#ifdef HDF5C
F &&f)
#else
F &&f)
#endif
{
if (format == defs::HDF5) {
#ifdef HDF5C
Checker<H5Context> checker(fname);
f(checker);
#endif
} else {
Checker<JsonContext> checker(fname);
f(checker);
}
}
} // namespace sls::test::master_file