<commit_before>// -*- mode:C++ { } tab-width:4 { } c-basic-offset:4 { } indent-tabs-mode:nil -*-

/*
 * Copyright (C) 2015 iCub Facility
 * Authors: <NAME>
 * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
 *
 */

#include <rtf/dll/Plugin.h>
#include <yarp/manager/utility.h>
#include <yarp/os/Network.h>
#include <yarp/os/Property.h>
#include <yarp/os/ResourceFinder.h>

#include "YarpFixManager.h"

using namespace RTF;
using namespace yarp::os;
using namespace yarp::manager;

PREPARE_FIXTURE_PLUGIN(YarpFixManager)

YarpFixManager::YarpFixManager()
    : initialized(false) { }

YarpFixManager::~YarpFixManager() {
        tearDown();
}


bool YarpFixManager::setup(int argc, char** argv) {
    RTF_FIXTURE_REPORT("yarpmanager is setuping the fixture...");
    bool ret;
    const char* szerror;
    if(!initialized) {
        // check yarp network
        yarp.setVerbosity(-1);
        RTF_ASSERT_ERROR_IF(yarp.checkNetwork(),
                            "YARP network does not seem to be available, is the yarp server accessible?");

        // load the config file and update the environment if available
        // E.g., "--application myapp.xml"
        yarp::os::ResourceFinder rf;
        rf.setVerbose(false);
        rf.setDefaultContext("RobotTesting");
        rf.configure("", argc, argv, false);

        RTF_ASSERT_ERROR_IF(rf.check("fixture"),
                            "No application xml file is set (add --fixture yourfixture.xml)");

        fixtureName = rf.find("fixture").asString();
        std::string appfile = rf.findFileByName(std::string("fixtures/"+fixtureName).c_str());
        RTF_ASSERT_ERROR_IF(appfile.size(),
                            RTF::Asserter::format("yarpmanager cannot find apllication file %s. Is it in the 'fixtures' folder?",
                                                  fixtureName.c_str()));

        // enable restricted mode to ensure all the modules
        // is running and enable watchdog to monitor the modules.
        enableWatchDog();
        enableAutoConnect();
        enableRestrictedMode();

        // load the fixture (application xml)
        char szAppName[] = "fixture";
        ret = addApplication(appfile.c_str(), szAppName);
        szerror = getLogger()->getLastError();
        RTF_ASSERT_ERROR_IF(ret,
                            "yarpmanager cannot setup the fixture because " +
                            std::string((szerror) ? szerror : ""));
        ret = loadApplication(szAppName);
        szerror = getLogger()->getLastError();
        RTF_ASSERT_ERROR_IF(ret,
                            "yarpmanager cannot setup the fixture because " +
                            std::string((szerror) ? szerror : ""));
        initialized = true;
    }

    //run the modules and connect
    ret = run();
    szerror = getLogger()->getLastError();
    RTF_ASSERT_ERROR_IF(ret,
                        "yarpmanager cannot setup the fixture because " +
                        std::string(getLogger()->getFormatedErrorString()));
    return true;
}

void YarpFixManager::tearDown() {
    RTF_FIXTURE_REPORT("yarpmanager is tearing down the fixture...");
    bool ret = stop();
    if(!ret)<commit_msg>YarpFixManager: printing all error messages on failure<commit_after>// -*- mode:C++ { } tab-width:4 { } c-basic-offset:4 { } indent-tabs-mode:nil -*-

/*
 * Copyright (C) 2015 iCub Facility
 * Authors: <NAME>
 * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
 *
 */

#include <rtf/dll/Plugin.h>
#include <yarp/manager/utility.h>
#include <yarp/os/Network.h>
#include <yarp/os/Property.h>
#include <yarp/os/ResourceFinder.h>

#include "YarpFixManager.h"

using namespace RTF;
using namespace yarp::os;
using namespace yarp::manager;

PREPARE_FIXTURE_PLUGIN(YarpFixManager)

YarpFixManager::YarpFixManager()
    : initialized(false) { }

YarpFixManager::~YarpFixManager() {
        tearDown();
}


bool YarpFixManager::setup(int argc, char** argv) {
    RTF_FIXTURE_REPORT("yarpmanager is setuping the fixture...");
    bool ret;
    const char* szerror;
    if(!initialized) {
        // check yarp network
        yarp.setVerbosity(-1);
        RTF_ASSERT_ERROR_IF(yarp.checkNetwork(),
                            "YARP network does not seem to be available, is the yarp server accessible?");

        // load the config file and update the environment if available
        // E.g., "--application myapp.xml"
        yarp::os::ResourceFinder rf;
        rf.setVerbose(false);
        rf.setDefaultContext("RobotTesting");
        rf.configure("", argc, argv, false);

        RTF_ASSERT_ERROR_IF(rf.check("fixture"),
                            "No application xml file is set (add --fixture yourfixture.xml)");

        fixtureName = rf.find("fixture").asString();
        std::string appfile = rf.findFileByName(std::string("fixtures/"+fixtureName).c_str());
        RTF_ASSERT_ERROR_IF(appfile.size(),
                            RTF::Asserter::format("yarpmanager cannot find apllication file %s. Is it in the 'fixtures' folder?",
                                                  fixtureName.c_str()));

        // enable restricted mode to ensure all the modules
        // is running and enable watchdog to monitor the modules.
        enableWatchDog();
        enableAutoConnect();
        enableRestrictedMode();

        // load the fixture (application xml)
        char szAppName[] = "fixture";
        ret = addApplication(appfile.c_str(), szAppName);
        RTF_ASSERT_ERROR_IF(ret,
                            "yarpmanager (addApplication) cannot setup the fixture because " +
                            std::string(getLogger()->getFormatedErrorString()));
        ret = loadApplication(szAppName);
        RTF_ASSERT_ERROR_IF(ret,
                            "yarpmanager (loadApplication) cannot setup the fixture because " +
                            std::string(getLogger()->getFormatedErrorString()));
        initialized = true;
    }

    //run the modules and connect
    ret = run();
    RTF_ASSERT_ERROR_IF(ret,
                        "yarpmanager (run) cannot setup the fixture because " +
                        std::string(getLogger()->getFormatedErrorString()));
    return true;
}

void YarpFixManager::tearDown() {
    RTF_FIXTURE_REPORT("yarpmanager is tearing down the fixture...");
    bool ret = stop();
    if(!ret)
{'fraction_non_alphanumeric': 0.12044992969848461, 'fraction_numerical': 0.0028120606155288236, 'mean_word_length': 2.4235294117647057, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '823943', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1858, 'n_words': 452}