<commit_before>#pragma once

#include <zmqpp/zmqpp.hpp>
#include "FakeGPIO.hpp"
#include <boost/property_tree/ptree.hpp>
#include "gtest/gtest.h"
#include "core/MessageBus.hpp"

namespace Leosac
{
    namespace Test
    {
        namespace Helper
        {
            /**
            * Helper function that create an object of type ModuleType (using conventional parameter) and run it.
            * This runs in "module"'s thread.
            */
            template<typename ModuleType>
            bool test_run_module(zmqpp::context *ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg)
            {
                {
                    ModuleType module(*ctx, pipe, cfg);

                    pipe->send(zmqpp::signal::ok);
                    module.run();
                }
                return true;
            }

            /**
            * Part of the `bus_read()` stuff.
            */
            bool bus_read_extract(zmqpp::message *)
            {
                return true;
            }

            /**
            * Default frame extraction function.
            */
            template<typename T, typename ...Content>
            bool bus_read_extract(zmqpp::message *m,
                    T first_arg,
                    Content... content)
            {
                if (std::is_same<const char *, T>::value)
                {
                    std::string value;
                    *m >> value;
                    if (strcmp(value.c_str(), reinterpret_cast<const char *>(first_arg)) != 0)
                        return false;
                     return bus_read_extract(m, content...);
                }

                T value;
                *m >> value;
                if (value != first_arg)
                    return false;

                return bus_read_extract(m, content...);
            }

            /**
            * Frame extraction method specialized (thanks to overloading) for `const char *`
            */
/*            template<typename ...Content>
            bool bus_read_extract(zmqpp::message *m, const char *first_arg, Content... content)
            {
                std::string value;
                *m >> value;

                std::cerr << "I AM HERE" << std::endl;
                if (strcmp(value.c_str(), first_arg) != 0)
                    return false;
                return bus_read_extract(m, content...);
            }*/

            /**<commit_msg>fix template magic in TestHelper<commit_after>#pragma once

#include <zmqpp/zmqpp.hpp>
#include "FakeGPIO.hpp"
#include <boost/property_tree/ptree.hpp>
#include "gtest/gtest.h"
#include "core/MessageBus.hpp"

namespace Leosac
{
    namespace Test
    {
        namespace Helper
        {
            /**
            * Helper function that create an object of type ModuleType (using conventional parameter) and run it.
            * This runs in "module"'s thread.
            */
            template<typename ModuleType>
            bool test_run_module(zmqpp::context *ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg)
            {
                {
                    ModuleType module(*ctx, pipe, cfg);

                    pipe->send(zmqpp::signal::ok);
                    module.run();
                }
                return true;
            }

            /**
            * Part of the `bus_read()` stuff.
            */
            bool bus_read_extract(zmqpp::message *)
            {
                return true;
            }

            template<typename ...Content>
            bool bus_read_extract(zmqpp::message *m, const char *first_arg, Content... content);

            /**
            * Default frame extraction function.
            *
            * Disabled for `const char *`.
            */
            template<typename T, typename ...Content>
            typename std::enable_if<!std::is_same<const char *, T>::value, bool>::type bus_read_extract(zmqpp::message *m,
                    T first_arg,
                    Content... content)
            {
                T value;
                *m >> value;
                if (value != first_arg)
                    return false;

                return bus_read_extract(m, content...);
            }

            /**
            * Frame extraction method specialized (thanks to overloading) for `const char *`
            */
            template<typename ...Content>
            bool bus_read_extract(zmqpp::message *m, const char *first_arg, Content... content)
            {
                std::string value;
                *m >> value;

                if (strcmp(value.c_str(), first_arg) != 0)
                    return false;
                return bus_read_extract(m, content...);
            }

            /**
{'fraction_non_alphanumeric': 0.10599078341013825, 'fraction_numerical': 0.0006284038542103058, 'mean_word_length': 1.2544853635505193, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7629399', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1183, 'n_words': 296}