Skip to content
Snippets Groups Projects
TestFacility.h 10.99 KiB
// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
// SPDX-License-Identifier: LGPL-3.0-or-later
#pragma once

#include "Application.h"

#include <ChimeraTK/ControlSystemAdapter/ControlSystemPVManager.h>
#include <ChimeraTK/OneDRegisterAccessor.h>
#include <ChimeraTK/ScalarRegisterAccessor.h>
#include <ChimeraTK/VoidRegisterAccessor.h>

#include <boost/fusion/include/at_key.hpp>

namespace ChimeraTK {

  /********************************************************************************************************************/

  namespace detail {

    template<typename T>
    struct BoolTypeHelper {
      using type = T;
    };

    template<>
    struct BoolTypeHelper<bool> {
      using type = ChimeraTK::Boolean;
    };

  } // namespace detail

  /********************************************************************************************************************/

  /** Helper class to facilitate tests of applications based on ApplicationCore */
  class TestFacility {
   public:
    /** The constructor will internally obtain the instance of the application, so
     * the instance of the TestFacility must not be created before the application
     * (i.e. usually not before the main() routine). The application will
     *  automatically be put into the testable mode and initialised. */
    [[deprecated("Use TestFacility(Application&, bool) instead")]] explicit TestFacility(
        bool enableTestableMode = true);

    /** The passed application will
     *  automatically be put into the testable mode and initialised. */
    explicit TestFacility(Application& app, bool enableTestableMode = true);

    /** Start the application in testable mode. */
    void runApplication() const;

    /**
     * Check whether data has been sent to the application so stepApplication() can be called.
     */
    bool canStepApplication() const;

    /** Perform a "step" of the application. This runs the application until all
     * input provided to it has been processed and all application modules wait
     * for new data in blocking read calls. This function returns only after the
     * application has reached that stated and was paused again. After returning
     * from this function, the result can be checked and new data can be provided
     * to the application. The new data will not be
     *  processed until the next call to step(). */
    void stepApplication(bool waitForDeviceInitialisation = true) const;

    /** Obtain a void process variable from the application, which is published
     * to the control system. */
    ChimeraTK::VoidRegisterAccessor getVoid(const ChimeraTK::RegisterPath& name) const;

    /** Obtain a scalar process variable from the application, which is published
     * to the control system. */