text:
#pragma once

#include <type_traits>

#include <fc/reflect/reflect.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/cat.hpp>
#include <fc/optional.hpp>
#include <fc/variant.hpp>

#define DEFINE_API_ARGS(api_name, arg_type, return_type)  \
typedef arg_type api_name ## _args;                         \
typedef return_type api_name ## _return;

#define DECLARE_API_METHOD_HELPER(r, data, method) \
BOOST_PP_CAT( method, _return ) method( BOOST_PP_CAT( method, _args )& );

#define FOR_EACH_API_HELPER(r, callback, method) \
{ \
   typedef std::remove_pointer<decltype(this)>::type this_type; \
   \
   callback( \
      (*this), \
      BOOST_PP_STRINGIZE( method ), \
      &this_type::method, \
      static_cast< BOOST_PP_CAT( method, _args )* >(nullptr), \
      static_cast< BOOST_PP_CAT( method, _return )* >(nullptr) \
   ); \
}

#define DECLARE_API(METHODS) \
   BOOST_PP_SEQ_FOR_EACH( DECLARE_API_METHOD_HELPER, _, METHODS ) \
   \
   template< typename Lambda > \
   void for_each_api( Lambda&& callback ) \
   { \
      BOOST_PP_SEQ_FOR_EACH( FOR_EACH_API_HELPER, callback, METHODS ) \
   }

#define DEFINE_API(class, api_name)                                   \
api_name ## _return class :: api_name ( api_name ## _args& args )

namespace golos {
    namespace plugins {
        namespace json_rpc {
            class msg_pack final {
            public:
                fc::variant id;
                std::string plugin;
                std::string method;
                fc::optional<std::vector<fc::variant>> args;

                msg_pack();

                // Constructor with hidden handlers types
                template <typename Handler>
                msg_pack(Handler &&);

                // Move constructor/operator move handlers, so source msg_pack can't pass result/error to connection
                msg_pack(msg_pack &&);

                msg_pack & operator=(msg_pack &&);

                ~msg_pack();

                bool valid() const;

                // Initialize rpc request/response id
                void rpc_id(fc::variant);

                fc::optional<fc::variant> rpc_id() const;

                // Pass result to remote connection
                void result(fc::optional<fc::variant> result);

                void unsafe_result(fc::optional<fc::variant> result);

                fc::optional<fc::variant> result() const;

                // Pass error to remote connection
                void error(int32_t code, std::string message, fc::optional<fc::variant> data = fc::optional<fc::variant>());

                void error(std::string message, fc::optional<fc::variant> data = fc::optional<fc::variant>());

                void error(int32_t code, const fc::exception &);

                void error(const fc::exception &);

                fc::optional<std::string> error() const;

            private:
                struct impl;
                std::unique_ptr<impl> pimpl;
            };

            class msg_pack_transfer final {
            public:
                using ptr = std::shared_ptr<msg_pack>;

                msg_pack_transfer(msg_pack &msg):
                    orig_msg(msg),
                    msg_(std::make_shared<msg_pack>(std::move(msg)))
                { }

                ~msg_pack_transfer() {
                    if (nullptr != msg_.get()) {
                        orig_msg = std::move(*msg_.get());
                    }
                }

                ptr msg() {
                    return msg_;
                }

                operator ptr () {
                    return msg_;
                }

                void complete() {
                    msg_.reset();
                }

            private:
                msg_pack &orig_msg;
                ptr msg_;
            };

            struct void_type {
            };

        }
    }
} // golos::plugins::json_rpc

FC_REFLECT((golos::plugins::json_rpc::void_type),)

max_stars_repo_name: rusladder/LadderChain

max_issues_repo_name: rusladder/LadderChain

max_forks_repo_name: rusladder/LadderChain


text:
/**
 Boost Logging library

 Author: John Torjo, www.torjo.com

 Copyright (C) 2007 John Torjo (see www.torjo.com for email)

 Distributed under the Boost Software License, Version 1.0.
    (See accompanying file LICENSE_1_0.txt or copy at
          http://www.boost.org/LICENSE_1_0.txt)

 See http://www.boost.org for updates, documentation, and revision history.
 See http://www.torjo.com/log2/ for more details
*/

// my_app_log.cpp - DEFINE your loggers & filters here
#include "my_app_log.h"
#include <boost/logging/format/named_write.hpp>

BOOST_DEFINE_LOG_FILTER(g_log_filter, filter_type )
BOOST_DEFINE_LOG(g_l, logger_type)

void init_logs() {
    // formatting    : time [idx] message \n
    // destinations  : console, file "out.txt" and debug window
    g_l()->writer().write("%time%($hh:$mm.$ss.$mili) [%idx%] |\n", "cout file(out.txt) debug");
    g_l()->mark_as_initialized();
}

void use_logger() {
    int i = 1;
    L_ << "this is a simple message " << i;
    std::string hello = "hello";
    L_ << hello << " world";
}

ext: cpp

max_stars_repo_name: saga-project/saga-cpp

max_issues_repo_name: saga-project/saga-cpp

max_forks_repo_name: saga-project/saga-cpp


text:
// -----------------------------------------------------------------------
// RTToolbox - DKFZ radiotherapy quantitative evaluation library
//
// Copyright (c) German Cancer Research Center (DKFZ),
// Software development for Integrated Diagnostics and Therapy (SIDT).
// ALL RIGHTS RESERVED.
// See rttbCopyright.txt or
// http://www.dkfz.de/en/sidt/projects/rttb/copyright.html
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE.  See the above copyright notices for more information.
//
//------------------------------------------------------------------------

#include "rttbModelXMLWriter.h"

#include <cmath>

/*boost includes*/
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/make_shared.hpp>

#include "rttbInvalidParameterException.h"
#include "rttbDVHXMLFileWriter.h"
#include "rttbDoseStatisticsXMLWriter.h"

namespace rttb
{
	namespace io
	{
		namespace models
		{
			ModelXMLWriter::ModelXMLWriter(const std::string&  filename,
        rttb::models::BioModel::Pointer model, bool printDVH) : _filename(filename),
				_model(model), _printDVH(printDVH)
			{
			}

			void ModelXMLWriter::setFilename(FileNameString filename)
			{
				_filename = filename;
			}

			FileNameString ModelXMLWriter::getFilename() const
			{
				return _filename;
			}

			void ModelXMLWriter::setModel(rttb::models::BioModel::Pointer model)
			{
				_model = model;
			}

      rttb::models::BioModel::Pointer  ModelXMLWriter::getModel() const
			{
				return _model;
			}

			void ModelXMLWriter::setPrintDVH(bool printDVH)
			{
				_printDVH = printDVH;
			}
			bool ModelXMLWriter::getPrintDVH() const
			{
				return _printDVH;
			}

			void ModelXMLWriter::writeModel()
			{
				std::setprecision(2);
				boost::property_tree::ptree pt;

				std::string xmlattrNameTag = "<xmlattr>.name";
				std::string modelTag = "BioModel";
				std::string propertyTag = "property";
				std::string configTag = "config";
				std::string resultsTag = "results";
				std::string valueTag = "value";
				auto dvh = _model->getDVH();

				boost::property_tree::ptree propertynode;
				boost::property_tree::ptree confignode;
				confignode.put("BioModelType", _model->getModelType());
				confignode.put("StructureID", dvh->getStructureID());
				confignode.put("DoseID", dvh->getDoseID());

				if (_printDVH)
				{
					FileNameString filename = "dvhfor" + _model->getModelType() + ".xml";
					DVHType typeDiff = { DVHType::Differential };
					io::other::DVHXMLFileWriter dvhWriter(filename, typeDiff);
					dvhWriter.writeDVH(dvh);
					confignode.put("DVHReference", filename);
				}

				pt.add_child(modelTag + "." + configTag, confignode);

				propertynode.put("", _model->getValue());
				propertynode.put(xmlattrNameTag, valueTag);
				pt.add_child(modelTag + "." + resultsTag + "." + propertyTag, propertynode);

				std::map<std::string, double> parameterMap = _model->getParameterMap();

				for (std::map<std::string, double>::const_iterator it = parameterMap.begin();
				     it != parameterMap.end(); ++it)
				{
					double value = it->second;

					if (value - static_cast<double>(std::round(value)) < errorConstant)
					{
						propertynode.put("", static_cast<int>(value));
					}
					else
					{
						propertynode.put("", static_cast<float>(value));
					}

					propertynode.put(xmlattrNameTag, it->first);
					pt.add_child(modelTag + "." + resultsTag + "." + propertyTag, propertynode);
				}

				try
				{
					boost::property_tree::xml_parser::xml_writer_settings<std::string> settings =
					    boost::property_tree::xml_writer_make_settings<std::string>('\t', 1);

					boost::property_tree::xml_parser::write_xml(_filename, pt, std::locale(), settings);
				}
				catch (const boost::property_tree::xml_parser_error&  e)
				{
					std::cout << e.what();
					throw core::InvalidParameterException("Write xml failed: xml_parser_error!");
				}

			}

		}
	}
}

max_stars_repo_name: MIC-DKFZ/RTTB

max_issues_repo_name: MIC-DKFZ/RTTB

max_forks_repo_name: MIC-DKFZ/RTTB


text:
/**
 * @file metric_test.cpp
 *
 * Unit tests for the 'LMetric' class.
 *
 * mlpack is free software; you may redistribute it and/or modify it under the
 * terms of the 3-clause BSD license.  You should have received a copy of the
 * 3-clause BSD license along with mlpack.  If not, see
 * http://www.opensource.org/licenses/BSD-3-Clause for more information.
 */
#include <mlpack/core.hpp>
#include <mlpack/core/metrics/lmetric.hpp>
#include <boost/test/unit_test.hpp>
#include "test_tools.hpp"

using namespace std;
using namespace mlpack::metric;

BOOST_AUTO_TEST_SUITE(LMetricTest);

BOOST_AUTO_TEST_CASE(L1MetricTest)
{
  arma::vec a1(5);
  a1.randn();

  arma::vec b1(5);
  b1.randn();

  arma::Col<size_t> a2(5);
  a2 << 1 << 2 << 1 << 0 << 5;

  arma::Col<size_t> b2(5);
  b2 << 2 << 5 << 2 << 0 << 1;

  ManhattanDistance lMetric;

  BOOST_REQUIRE_CLOSE((double) arma::accu(arma::abs(a1 - b1)),
                      lMetric.Evaluate(a1, b1), 1e-5);

  BOOST_REQUIRE_CLOSE((double) arma::accu(arma::abs(a2 - b2)),
                      lMetric.Evaluate(a2, b2), 1e-5);
}

BOOST_AUTO_TEST_CASE(L2MetricTest)
{
  arma::vec a1(5);
  a1.randn();

  arma::vec b1(5);
  b1.randn();

  arma::vec a2(5);
  a2 << 1 << 2 << 1 << 0 << 5;

  arma::vec b2(5);
  b2 << 2 << 5 << 2 << 0 << 1;

  EuclideanDistance lMetric;

  BOOST_REQUIRE_CLOSE((double) sqrt(arma::accu(arma::square(a1 - b1))),
                      lMetric.Evaluate(a1, b1), 1e-5);

  BOOST_REQUIRE_CLOSE((double) sqrt(arma::accu(arma::square(a2 - b2))),
                      lMetric.Evaluate(a2, b2), 1e-5);
}

BOOST_AUTO_TEST_CASE(LINFMetricTest)
{
  arma::vec a1(5);
  a1.randn();

  arma::vec b1(5);
  b1.randn();

  arma::Col<size_t> a2(5);
  a2 << 1 << 2 << 1 << 0 << 5;

  arma::Col<size_t> b2(5);
  b2 << 2 << 5 << 2 << 0 << 1;

  ChebyshevDistance lMetric;

  BOOST_REQUIRE_CLOSE((double) arma::as_scalar(arma::max(arma::abs(a1 - b1))),
                      lMetric.Evaluate(a1, b1), 1e-5);

  BOOST_REQUIRE_CLOSE((double) arma::as_scalar(arma::max(arma::abs(a2 - b2))),
                      lMetric.Evaluate(a2, b2), 1e-5);
}

BOOST_AUTO_TEST_SUITE_END();

max_stars_repo_name: RMaron/mlpack

max_issues_repo_name: RMaron/mlpack

max_forks_repo_name: RMaron/mlpack


text:
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
// (C) Copyright 2004-2007 Jonathan Turkanis
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)

// See http://www.boost.org/libs/iostreams for documentation.

#include <boost/iostreams/detail/config/wide_streams.hpp>
#ifdef BOOST_IOSTREAMS_NO_WIDE_STREAMS
# error wide streams not supported on this platform
#endif

#include <algorithm>         // equal.
#include <locale>
#include <string>
#include <boost/config.hpp>  // BOOST_DEDUCED_TYPENAME.
#include <boost/iostreams/code_converter.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/detail/add_facet.hpp>
#include <boost/iostreams/device/back_inserter.hpp>
#include <boost/iostreams/detail/config/windows_posix.hpp>
#include <boost/iostreams/device/file.hpp>
#if !defined(__COMO__) || !defined(BOOST_COMO_STRICT)
# if defined(BOOST_IOSTREAMS_NO_LIB) || defined(BOOST_ALL_NO_LIB)
#  include "../src/file_descriptor.cpp"
# else
#  include <boost/iostreams/device/file_descriptor.hpp>
# endif
#endif
#include <boost/iostreams/stream.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include "detail/closable.hpp"
#include "detail/operation_sequence.hpp"
#include "detail/temp_file.hpp"

    // Include codevct facets

#include "detail/null_padded_codecvt.hpp"
#include "detail/utf8_codecvt_facet.hpp"
#ifdef BOOST_IOSTREAMS_USE_DINKUM_COREX
# include <codecvt/8859_1>
# include <codecvt/8859_10>
# include <codecvt/8859_13>
# include <codecvt/8859_14>
# include <codecvt/8859_15>
# include <codecvt/8859_16>
# include <codecvt/8859_2>
# include <codecvt/8859_3>
# include <codecvt/8859_4>
# include <codecvt/8859_5>
# include <codecvt/8859_6>
# include <codecvt/8859_7>
# include <codecvt/8859_8>
# include <codecvt/8859_9>
# include <codecvt/baltic>
# include <codecvt/big5>
# include <codecvt/cp037>
# include <codecvt/cp1006>
# include <codecvt/cp1026>
# include <codecvt/cp1250>
# include <codecvt/cp1251>
# include <codecvt/cp1252>
# include <codecvt/cp1253>
# include <codecvt/cp1254>
# include <codecvt/cp1255>
# include <codecvt/cp1256>
# include <codecvt/cp1257>
# include <codecvt/cp1258>
# include <codecvt/cp424>
# include <codecvt/cp437>
# include <codecvt/cp500>
# include <codecvt/cp737>
# include <codecvt/cp775>
# include <codecvt/cp850>
# include <codecvt/cp852>
# include <codecvt/cp855>
# include <codecvt/cp856>
# include <codecvt/cp857>
# include <codecvt/cp860>
# include <codecvt/cp861>
# include <codecvt/cp862>
# include <codecvt/cp863>
# include <codecvt/cp864>
# include <codecvt/cp865>
# include <codecvt/cp866>
# include <codecvt/cp869>
# include <codecvt/cp874>
# include <codecvt/cp875>
# include <codecvt/cp932>
# include <codecvt/cp936>
# include <codecvt/cp949>
# include <codecvt/cp950>
# include <codecvt/cyrillic>
# include <codecvt/ebcdic>
# include <codecvt/euc>
# include <codecvt/euc_0208>
# include <codecvt/gb12345>
# include <codecvt/gb2312>
# include <codecvt/greek>
# include <codecvt/iceland>
# include <codecvt/jis>
# include <codecvt/jis_0208>
# include <codecvt/jis0201>
# include <codecvt/ksc5601>
# include <codecvt/latin2>
# include <codecvt/one_one>
# include <codecvt/roman>
# include <codecvt/sjis>
# include <codecvt/sjis_0208>
# include <codecvt/turkish>
# include <codecvt/utf16>
# include <codecvt/utf8>
# include <codecvt/utf8_utf16>
# include <codecvt/xjis>
#endif // #ifdef BOOST_IOSTREAMS_USE_DINKUM_COREX]

#include <iostream>

using namespace std;
using namespace boost::iostreams;
using namespace boost::iostreams::detail;
using namespace boost::iostreams::test;
using boost::unit_test::test_suite;
namespace io = boost::iostreams;

const int max_length = 30;
const unsigned int pattern_length = 100;
const unsigned int pattern_reps = 100;

template<typename Codecvt>
bool valid_char(typename codecvt_intern<Codecvt>::type c)
{
    typedef typename codecvt_state<Codecvt>::type   state_type;
    typedef typename codecvt_intern<Codecvt>::type  intern_type;
    Codecvt             cvt;
    state_type          state = state_type();
    const intern_type*  nint;
    char*               next;
    char                buf[max_length];

    return cvt.out( state, &c, &c + 1, nint,
                    buf, buf + max_length, next )
           ==
           codecvt_base::ok;
}

template<typename Codecvt>
basic_string<
    BOOST_DEDUCED_TYPENAME
    codecvt_intern<Codecvt>::type
>
test_string()
{
    typedef typename codecvt_intern<Codecvt>::type intern_type;
    std::basic_string<intern_type> pattern, result;
    for (intern_type c = 255; pattern.size() < pattern_length; --c)
        if (valid_char<Codecvt>(c))
            pattern += c;
    result.reserve(pattern.size() * pattern_reps);
    for (unsigned int w = 0; w < pattern_reps; ++w)
        result += pattern;
    return result;
}

// Como can't compile file_descriptor.cpp in strict mode; this failure
// is detected by file_descriptor_test.cpp.
#if !defined(__COMO__) || !defined(BOOST_COMO_STRICT)
    typedef io::file_descriptor_source  classic_file_source;
    typedef io::file_descriptor_sink    classic_file_sink;
#else
    struct classic_file_source : io::source {
        classic_file_source(const std::string& path)
            : file_(new filebuf)
        {
            file_->pubimbue(locale::classic());
            file_->open(path.c_str(), BOOST_IOS::in | BOOST_IOS::binary);
        }
        streamsize read(char* s, streamsize n) { return file_->sgetn(s, n); }
        boost::shared_ptr<filebuf> file_;
    };

    struct classic_file_sink : io::sink  {
        classic_file_sink(const std::string& path)
            : file_(new filebuf)
        {
            file_->pubimbue(locale::classic());
            file_->open(path.c_str(), BOOST_IOS::out | BOOST_IOS::binary);
        }
        streamsize write(const char* s, streamsize n) { return file_->sputn(s, n); }
        boost::shared_ptr<filebuf> file_;
    };
#endif

template<typename Codecvt>
bool codecvt_test1()
{
    typedef basic_string<
                BOOST_DEDUCED_TYPENAME
                codecvt_intern<Codecvt>::type
            >                                             string_type;
    typedef code_converter<classic_file_source, Codecvt>  wide_file_source;
    typedef code_converter<classic_file_sink, Codecvt>    wide_file_sink;

    BOOST_CHECK(Codecvt().max_length() <= max_length);
    temp_file                 temp;
    string_type               test = test_string<Codecvt>();
    stream<wide_file_sink>    out(temp.name());
    out.write(test.data(), static_cast<streamsize>(test.size()));
    out.close();

    stream<wide_file_source>  in(temp.name());
    string_type               test2;
    io::copy(in, io::back_inserter(test2));

    return test == test2;
}

template<typename Codecvt>
bool codecvt_test2()
{
    typedef basic_string<
                BOOST_DEDUCED_TYPENAME
                codecvt_intern<Codecvt>::type
            >                                    string_type;
    typedef code_converter<classic_file_source>  wide_file_source;
    typedef code_converter<classic_file_sink>    wide_file_sink;

    // Set global locale.
    locale loc = add_facet(locale(), new Codecvt);
    locale::global(loc);

    temp_file                 temp;
    string_type               test = test_string<Codecvt>();
    stream<wide_file_sink>    out(temp.name());
    out.write(test.data(), static_cast<streamsize>(test.size()));
    out.close();

    stream<wide_file_source>  in(temp.name());
    string_type               test2;
    io::copy(in, io::back_inserter(test2));

    return test == test2;
}

template<typename Codecvt>
bool codecvt_test()
{
    return codecvt_test1<Codecvt>() && codecvt_test2<Codecvt>();
}

void code_converter_test()
{
    BOOST_CHECK((codecvt_test<utf8_codecvt_facet<wchar_t, char> >()));
    BOOST_CHECK(codecvt_test<null_padded_codecvt>());
    BOOST_CHECK(codecvt_test<stateless_null_padded_codecvt>());
#ifdef BOOST_IOSTREAMS_USE_DINKUM_COREX
    using namespace Dinkum::conversions;
    BOOST_CHECK(codecvt_test< codecvt_8859_1<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_10<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_13<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_14<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_15<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_16<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_2<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_3<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_4<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_5<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_6<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_7<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_8<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_8859_9<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_baltic<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_big5<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp037<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp1006<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp1026<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp1250<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp1251<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp1252<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp1253<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp1254<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp1255<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp1256<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp1257<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp1258<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp424<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp437<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp500<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp737<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp775<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp850<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp852<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp855<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp856<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp857<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp860<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp861<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp862<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp863<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp864<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp865<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp866<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp869<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp874<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp875<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp932<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp936<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp949<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cp950<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_cyrillic<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_ebcdic<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_euc<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_euc_0208<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_gb12345<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_gb2312<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_greek<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_iceland<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_jis<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_jis_0208<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_jis0201<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_ksc5601<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_latin2<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_one_one<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_roman<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_sjis<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_sjis_0208<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_turkish<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_utf16<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_utf8<wchar_t> >());
    BOOST_CHECK(codecvt_test< codecvt_utf8_utf16<wchar_t> >());
#endif
}

/* Defer pending further testing
void close_test()
{
    typedef utf8_codecvt_facet<wchar_t, char> codecvt_type;

    // Test code converter based on a source
    {
        operation_sequence  seq;
        io::wchain<input>   ch;
        ch.push(
            code_converter<closable_device<input>, codecvt_type>(
                seq.new_operation(1)
            )
        );
        BOOST_CHECK_NO_THROW(ch.reset());
        BOOST_CHECK_OPERATION_SEQUENCE(seq);
    }

    // Test code converter based on a sink
    {
        operation_sequence   seq;
        io::wchain<output>    ch;
        ch.push(
            code_converter<closable_device<output>, codecvt_type>(
                seq.new_operation(1)
            )
        );
        BOOST_CHECK_NO_THROW(ch.reset());
        BOOST_CHECK_OPERATION_SEQUENCE(seq);
    }

    // Test code converter based on a bidirectional device
    {
        operation_sequence         seq;
        io::wchain<bidirectional>  ch;
        ch.push(
            code_converter<closable_device<bidirectional>, codecvt_type>(
                seq.new_operation(1),
                seq.new_operation(2)
            )
        );
        BOOST_CHECK_NO_THROW(ch.reset());
        BOOST_CHECK_OPERATION_SEQUENCE(seq);
    }
}*/

test_suite* init_unit_test_suite(int, char* [])
{
    test_suite* test = BOOST_TEST_SUITE("code_converter test");
    test->add(BOOST_TEST_CASE(&code_converter_test));
    //test->add(BOOST_TEST_CASE(&close_test));
    return test;
}


text:
/*
 * Copyright 2014 Open Connectome Project (http://openconnecto.me)
 * Written by Da Zheng (zhengda1936@gmail.com)
 *
 * This file is part of FlashGraph.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <boost/assert.hpp>

#include "thread.h"

#include "vertex_program.h"
#include "messaging.h"
#include "worker_thread.h"
#include "message_processor.h"

namespace fg
{

vertex_program::~vertex_program()
{
	for (unsigned i = 0; i < msg_senders.size(); i++)
		simple_msg_sender::destroy(msg_senders[i]);
	for (unsigned i = 0; i < flush_msg_senders.size(); i++)
		simple_msg_sender::destroy(flush_msg_senders[i]);
	for (unsigned i = 0; i < multicast_senders.size(); i++)
		multicast_msg_sender::destroy(multicast_senders[i]);
	for (unsigned i = 0; i < activate_senders.size(); i++)
		multicast_msg_sender::destroy(activate_senders[i]);
}

void vertex_program::init(graph_engine *graph, worker_thread *t)
{
	this->t = t;
	this->graph = graph;
	part_id = t->get_worker_id();
}

void vertex_program::init_messaging(const std::vector<worker_thread *> &threads,
		std::shared_ptr<slab_allocator> msg_alloc,
		std::shared_ptr<slab_allocator> flush_msg_alloc)
{
	vid_bufs = std::unique_ptr<std::vector<local_vid_t>[]>(
			new std::vector<local_vid_t>[graph->get_num_threads()]);
	vloc_size = graph->get_num_threads() * 2;
	vertex_locs = std::unique_ptr<vertex_loc_t[]>(new vertex_loc_t[vloc_size]);

	for (unsigned i = 0; i < threads.size(); i++) {
		msg_senders.push_back(simple_msg_sender::create(t->get_node_id(),
					msg_alloc, &threads[i]->get_msg_processor().get_msg_queue()));
		flush_msg_senders.push_back(simple_msg_sender::create(t->get_node_id(),
					flush_msg_alloc, &threads[i]->get_msg_processor().get_msg_queue()));
		multicast_senders.push_back(multicast_msg_sender::create(msg_alloc,
					&threads[i]->get_msg_processor().get_msg_queue()));
		multicast_msg_sender *activate_sender = multicast_msg_sender::create(
				msg_alloc, &threads[i]->get_msg_processor().get_msg_queue());
		// All activation messages are the same. We can initialize the sender
		// here.
		activation_message msg;
		activate_sender->init(msg);
		activate_senders.push_back(activate_sender);
	}
}

void vertex_program::multicast_msg(vertex_id_t ids[], int num,
		vertex_message &msg)
{
	assert(!msg.is_flush());
	BOOST_VERIFY(t == (worker_thread *) thread::get_curr_thread());

	if (num == 0)
		return;

	if (num < graph->get_num_threads() * 2) {
		for (int i = 0; i < num; i++)
			this->send_msg(ids[i], msg);
		return;
	}

	graph->get_partitioner()->map2loc(ids, num, vid_bufs.get(),
			graph->get_num_threads());
	for (int i = 0; i < graph->get_num_threads(); i++) {
		if (vid_bufs[i].empty())
			continue;

		multicast_msg_sender &sender = get_multicast_sender(i);
		sender.init(msg);
		BOOST_VERIFY((size_t) sender.add_dests(vid_bufs[i].data(),
					vid_bufs[i].size()) == vid_bufs[i].size());
		vid_bufs[i].clear();
		sender.end_multicast();
	}
}

void vertex_program::multicast_msg(edge_seq_iterator &it, vertex_message &msg)
{
	assert(!msg.is_flush());
	BOOST_VERIFY((worker_thread *) thread::get_curr_thread() == t);

	int num_dests = it.get_num_tot_entries();
	if (num_dests == 0)
		return;

	if (num_dests < graph->get_num_threads() * 2) {
		PAGE_FOREACH(vertex_id_t, id, it) {
			this->send_msg(id, msg);
		} PAGE_FOREACH_END
		return;
	}

	graph->get_partitioner()->map2loc(it, vid_bufs.get(),
			graph->get_num_threads());
	for (int i = 0; i < graph->get_num_threads(); i++) {
		if (vid_bufs[i].empty())
			continue;

		multicast_msg_sender &sender = get_multicast_sender(i);
		sender.init(msg);
		BOOST_VERIFY((size_t) sender.add_dests(vid_bufs[i].data(),
					vid_bufs[i].size()) == vid_bufs[i].size());
		vid_bufs[i].clear();
		sender.end_multicast();
	}
}

void vertex_program::send_msg(vertex_id_t dest, vertex_message &msg)
{
	BOOST_VERIFY(t == (worker_thread *) thread::get_curr_thread());

	int part_id;
	// We are going to use the offset of a vertex in a partition as
	// the ID of the vertex.
	off_t local_id;
	graph->get_partitioner()->map2loc(dest, part_id, local_id);
	msg.set_dest(local_vid_t(local_id));
	if (msg.is_flush()) {
		// Let's flush all messages sent by the thread before sending
		// the flush message.
		get_activate_sender(part_id).flush();
		get_multicast_sender(part_id).flush();
		get_msg_sender(part_id).flush();

		simple_msg_sender &sender = get_flush_msg_sender(part_id);
		sender.send_cached(msg);
		sender.flush();
	}
	else {
		simple_msg_sender &sender = get_msg_sender(part_id);
		sender.send_cached(msg);
	}
}

void vertex_program::activate_vertices(vertex_id_t ids[], int num)
{
	worker_thread *curr = (worker_thread *) thread::get_curr_thread();
	BOOST_VERIFY(curr == t);

	if (num == 0)
		return;

	// When there are very few destinations, this way is cheaper.
	if ((size_t) num <= vloc_size) {
		for (int i = 0; i < num; i++) {
			int part_id;
			// We are going to use the offset of a vertex in a partition as
			// the ID of the vertex.
			off_t local_id;
			graph->get_partitioner()->map2loc(ids[i], part_id, local_id);
			multicast_msg_sender &sender = get_activate_sender(part_id);
			BOOST_VERIFY(sender.add_dest((local_vid_t) local_id));
		}
		return;
	}

	graph->get_partitioner()->map2loc(ids, num, vid_bufs.get(),
			graph->get_num_threads());
	for (int i = 0; i < graph->get_num_threads(); i++) {
		multicast_msg_sender &sender = get_activate_sender(i);
		if (vid_bufs[i].empty())
			continue;
		int ret = sender.add_dests(vid_bufs[i].data(), vid_bufs[i].size());
		BOOST_VERIFY((size_t) ret == vid_bufs[i].size());
		vid_bufs[i].clear();
	}
}

void vertex_program::activate_vertices(edge_seq_iterator &it)
{
	worker_thread *curr = (worker_thread *) thread::get_curr_thread();
	assert(curr == t);

	size_t num_dests = it.get_num_tot_entries();
	if (num_dests == 0)
		return;

	// When there are very few destinations, this way is cheaper.
	if (num_dests <= vloc_size) {
		size_t ret = graph->get_partitioner()->map2loc(it, vertex_locs.get(),
				vloc_size);
		assert(ret == num_dests);
		for (size_t i = 0; i < ret; i++) {
			int part_id = vertex_locs[i].first;
			if (t->get_worker_id() == part_id)
				t->activate_vertex(vertex_locs[i].second);
			else {
				// We are going to use the offset of a vertex in a partition as
				// the ID of the vertex.
				local_vid_t local_id = vertex_locs[i].second;
				multicast_msg_sender &sender = get_activate_sender(part_id);
				BOOST_VERIFY(sender.add_dest(local_id));
			}
		}
		return;
	}

	graph->get_partitioner()->map2loc(it, vid_bufs.get(),
			graph->get_num_threads());
	for (int i = 0; i < graph->get_num_threads(); i++) {
		multicast_msg_sender &sender = get_activate_sender(i);
		if (vid_bufs[i].empty())
			continue;
		if (i == t->get_worker_id()) {
			curr->activate_vertices(vid_bufs[i].data(), vid_bufs[i].size());
			vid_bufs[i].clear();
		}
		else {
			int ret = sender.add_dests(vid_bufs[i].data(), vid_bufs[i].size());
			BOOST_VERIFY((size_t) ret == vid_bufs[i].size());
			vid_bufs[i].clear();
		}
	}
}

void vertex_program::flush_msgs()
{
	for (size_t i = 0; i < msg_senders.size(); i++)
		msg_senders[i]->flush();
	for (size_t i = 0; i < multicast_senders.size(); i++)
		multicast_senders[i]->flush();
	for (size_t i = 0; i < activate_senders.size(); i++) {
		activate_senders[i]->flush();
		activation_message msg;
		activate_senders[i]->init(msg);
	}
}

void vertex_program::request_notify_iter_end(const compute_vertex &v)
{
	local_vid_t local_id = graph->get_graph_index().get_local_id(
			t->get_worker_id(), v);
	// TODO this shouldn't be right. We should allow a vertex to request
	// the notification of iteration end at any thread.
	assert(local_id.id != INVALID_VERTEX_ID);
	t->request_notify_iter_end(local_id);
}

vertex_id_t vertex_program::get_vertex_id(const compute_vertex &v) const
{
	// The current thread is usually the owner thread of the compute vertex.
	// It is possible that the current thread is the execution thread but
	// not the owner thread. It happens when the vertex is moved to another
	// thread due to load balancing.
	vertex_id_t id = graph->get_graph_index().get_vertex_id(t->get_worker_id(), v);
	if (id == INVALID_VERTEX_ID) {
		int part_id = t->get_stolen_vertex_part(v);
		assert(part_id >= 0);
		id = graph->get_graph_index().get_vertex_id(part_id, v);
		assert(id != INVALID_VERTEX_ID);
	}
	return id;
}

vertex_id_t vertex_program::get_vertex_id(compute_vertex_pointer v) const
{
	// The current thread is usually the owner thread of the compute vertex.
	// It is possible that the current thread is the execution thread but
	// not the owner thread. It happens when the vertex is moved to another
	// thread due to load balancing.
	vertex_id_t id = graph->get_graph_index().get_vertex_id(t->get_worker_id(), v);
	if (id == INVALID_VERTEX_ID) {
		int part_id = t->get_stolen_vertex_part(*v);
		assert(part_id >= 0);
		id = graph->get_graph_index().get_vertex_id(part_id, v);
		assert(id != INVALID_VERTEX_ID);
	}
	return id;
}

vsize_t vertex_program::get_num_edges(vertex_id_t id) const
{
	return graph->get_num_edges(id);
}

}


text:
#include <stdexcept>

#include <boost/uuid/random_generator.hpp>

#include "ResolveOperation.h"
#include "LifetimeScope.h"

namespace Hypodermic
{
	const boost::uuids::uuid LifetimeScope::selfRegistrationId = boost::uuids::random_generator()();
	std::function< void(ContainerBuilder*) > LifetimeScope::noConfiguration_ = [](ContainerBuilder*) -> void {};

    LifetimeScope::LifetimeScope(std::shared_ptr< IComponentRegistry > componentRegistry)
        : componentRegistry_(componentRegistry)
    {
        if (componentRegistry == nullptr)
            throw std::invalid_argument("componentRegistry");
    }

    LifetimeScope::LifetimeScope(std::shared_ptr< IComponentRegistry > componentRegistry, std::shared_ptr< LifetimeScope > parent)
        : componentRegistry_(componentRegistry)
        , parent_(parent)
    {
        if (componentRegistry == nullptr)
            throw std::invalid_argument("componentRegistry");
        if (parent == nullptr)
            throw std::invalid_argument("parent");
    }

    std::shared_ptr< ISharingLifetimeScope > LifetimeScope::parentLifetimeScope()
    {
        return parent_;
    }

    std::shared_ptr< ISharingLifetimeScope > LifetimeScope::rootLifetimeScope()
    {
        return root_.lock();
    }

    std::shared_ptr< IComponentRegistry > LifetimeScope::componentRegistry()
    {
        return componentRegistry_;
    }

    std::shared_ptr< void > LifetimeScope::resolveComponent(std::shared_ptr< IComponentRegistration > registration)
    {
        if (registration == nullptr)
            throw std::invalid_argument("registration");

        {
            boost::lock_guard< decltype(mutex_) > lock(mutex_);

            auto operation = std::make_shared< ResolveOperation >(shared_from_this());
            return operation->execute(registration);
        }
    }

    std::shared_ptr< void > LifetimeScope::getOrCreateAndShare(const boost::uuids::uuid& id,
                                                               std::function< std::shared_ptr< void >() > creator)
    {
        boost::lock_guard< decltype(mutex_) > lock(mutex_);

        std::shared_ptr< void > result;
        if (sharedInstances_.count(id) == 0)
        {
            result = creator();
            sharedInstances_[id] = result;
        }
        else
            result = sharedInstances_[id];

        return result;
    }

    void LifetimeScope::initialize()
    {
        auto sharedSelf = shared_from_this();
        root_ = parent_ != nullptr ? parent_ : std::static_pointer_cast< ISharingLifetimeScope >(sharedSelf);
    }

} // namespace Hypodermic

max_stars_repo_name: DeltaEngine/DeltaEngineCpp

max_issues_repo_name: DeltaEngine/DeltaEngineCpp

max_forks_repo_name: DeltaEngine/DeltaEngineCpp


text:
/***************************************************************************
 * Copyright 1998-2017 by authors (see AUTHORS.txt)                        *
 *                                                                         *
 *   This file is part of LuxRender.                                       *
 *                                                                         *
 * Licensed under the Apache License, Version 2.0 (the "License");         *
 * you may not use this file except in compliance with the License.        *
 * You may obtain a copy of the License at                                 *
 *                                                                         *
 *     http://www.apache.org/licenses/LICENSE-2.0                          *
 *                                                                         *
 * Unless required by applicable law or agreed to in writing, software     *
 * distributed under the License is distributed on an "AS IS" BASIS,       *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.*
 * See the License for the specific language governing permissions and     *
 * limitations under the License.                                          *
 ***************************************************************************/

#include <iostream>
#include <boost/format.hpp>

#include "luxcoreapp.h"

using namespace std;
using namespace luxrays;
using namespace luxcore;

//------------------------------------------------------------------------------
// EpsilonWindow
//------------------------------------------------------------------------------

EpsilonWindow::EpsilonWindow(LuxCoreApp *a) : ObjectEditorWindow(a, "Epsilon") {
}

Properties EpsilonWindow::GetEpsilonProperties(const Properties &cfgProps) const {
	return cfgProps.GetAllProperties("scene.epsilon");
}

void EpsilonWindow::RefreshObjectProperties(Properties &props) {
	RenderConfig *config = app->config;
	try {
		props = GetEpsilonProperties(config->ToProperties());
	} catch(exception &ex) {
		LA_LOG("Epsilon parsing error: " << endl << ex.what());

		// Just revert to the initialized properties (note: they will include the error)
		props = GetEpsilonProperties(config->GetProperties());
	}
}

void EpsilonWindow::ParseObjectProperties(const Properties &props) {
	app->RenderConfigParse(GetEpsilonProperties(props));
}

bool EpsilonWindow::DrawObjectGUI(Properties &props, bool &modifiedProps) {
	float fval;

	fval = props.Get("scene.epsilon.min").Get<float>();
	if (ImGui::InputFloat("Min. epsilon value", &fval, 0.f, 0.f, 15)) {
		props.Set(Property("scene.epsilon.min")(fval));
		modifiedProps = true;
	}
	LuxCoreApp::HelpMarker("scene.epsilon.min");

	fval = props.Get("scene.epsilon.max").Get<float>();
	if (ImGui::InputFloat("Max. epsilon value", &fval, 0.f, 0.f, 15)) {
		props.Set(Property("scene.epsilon.max")(fval));
		modifiedProps = true;
	}
	LuxCoreApp::HelpMarker("scene.epsilon.max");

	return false;
}

max_stars_repo_name: LuxRender/LuxRays

max_issues_repo_name: LuxRender/LuxRays

max_forks_repo_name: LuxRender/LuxRays


text:
#ifndef BART_SOLVER_LINEAR_I_H_
#define BART_SOLVER_LINEAR_I_H_

#include <deal.II/lac/petsc_precondition.h>
#include <deal.II/lac/petsc_matrix_base.h>
#include <deal.II/lac/petsc_vector_base.h>

namespace bart::solver::linear {
/*! \brief Linear solver class.
 *
 * This class is all solvers that solve an equation in the form \f$Ax = b\f$.
 *
 */
class LinearI {
 public:
  virtual ~LinearI() = default;
  virtual void Solve(
      dealii::PETScWrappers::MatrixBase *A,
      dealii::PETScWrappers::VectorBase *x,
      dealii::PETScWrappers::VectorBase *b,
      dealii::PETScWrappers::PreconditionerBase *preconditioner) = 0;
};

} // namespace bart::solver::linear

#endif // BART_SOLVER_LINEAR_I_H_

ext: hpp

max_stars_repo_name: SlaybaughLab/Transport

max_issues_repo_name: jsrehak/BART

max_forks_repo_name: jsrehak/BART


text:
#include "common/config/proxy.h"

#include <boost/algorithm/string.hpp>

#include <ssf/log/log.h>
#include <ssf/utils/enum.h>

namespace ssf {
namespace config {

HttpProxy::HttpProxy()
    : host_(""),
      port_(""),
      username_(""),
      domain_(""),
      password_(""),
      reuse_ntlm_(true),
      reuse_kerb_(true) {}

void HttpProxy::Update(const Json& proxy_prop) {
  if (proxy_prop.count("host") == 1) {
    host_ = proxy_prop.at("host").get<std::string>();
    boost::trim(host_);
  }

  if (proxy_prop.count("port") == 1) {
    port_ = proxy_prop.at("port").get<std::string>();
    boost::trim(port_);
  }

  if (proxy_prop.count("user_agent") == 1) {
    user_agent_ = proxy_prop.at("user_agent").get<std::string>();
    boost::trim(user_agent_);
  }

  if (proxy_prop.count("credentials") == 1) {
    auto credentials = proxy_prop.at("credentials");

    if (credentials.count("username") == 1) {
      username_ = credentials.at("username").get<std::string>();
      boost::trim(username_);
    }

    if (credentials.count("domain") == 1) {
      domain_ = credentials.at("domain").get<std::string>();
      boost::trim(domain_);
    }

    if (credentials.count("password") == 1) {
      password_ = credentials.at("password").get<std::string>();
      boost::trim(password_);
    }

    if (credentials.count("reuse_ntlm") == 1) {
      reuse_ntlm_ = credentials.at("reuse_ntlm").get<bool>();
    }

    if (credentials.count("reuse_kerb") == 1) {
      reuse_kerb_ = credentials.at("reuse_kerb").get<bool>();
    }
  }
}

void HttpProxy::Log() const {
  if (IsSet()) {
    SSF_LOG("config", info, "[http proxy] <{}:{}>", host_, port_);
    if (!username_.empty()) {
      SSF_LOG("config", info, "[http proxy] username: <{}>", username_);
    }
    SSF_LOG("config", info, "[http proxy] reuse NTLM credentials <{}>",
            (reuse_ntlm_ ? "true" : "false"));
    SSF_LOG("config", info, "[http proxy] reuse Kerberos credentials <{}>",
            (reuse_kerb_ ? "true" : "false"));
  } else {
    SSF_LOG("config", info, "[http proxy] <None>");
  }
}

SocksProxy::SocksProxy()
    : version_(Socks::Version::kVUnknown), host_(""), port_("") {}

void SocksProxy::Update(const Json& proxy_prop) {
  if (proxy_prop.count("version") == 1) {
    int version = proxy_prop.at("version").get<int>();
    if (version == 4) {
      version_ = Socks::Version::kV4;
    }
    if (version == 5) {
      version_ = Socks::Version::kV5;
    }
  }

  if (proxy_prop.count("host") == 1) {
    host_ = proxy_prop.at("host").get<std::string>();
    boost::trim(host_);
  }

  if (proxy_prop.count("port") == 1) {
    port_ = proxy_prop.at("port").get<std::string>();
    boost::trim(port_);
  }
}

void SocksProxy::Log() const {
  if (IsSet()) {
    SSF_LOG("config", info, "[socks proxy] <V{} {}:{}>",
            std::to_string(ToIntegral(version_)), host_, port_);
  } else {
    SSF_LOG("config", info, "[socks proxy] <None>");
  }
}

}  // config
}  // ssf

max_stars_repo_name: ZhiQiAnSecFork/ssf

max_issues_repo_name: ZhiQiAnSecFork/ssf

max_forks_repo_name: ZhiQiAnSecFork/ssf


text:
//
// Copyright (c) 2017-2020 Project PAI Foundation
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
//

#include "wallet/test/wallet_stake_test_fixture.h"

#include <boost/test/unit_test.hpp>

#include "validation.h"
#include "wallet/coincontrol.h"
#include "rpc/server.h"

BOOST_FIXTURE_TEST_SUITE(vote_tests, WalletStakeTestingSetup)

// test the stakebase content verifier
BOOST_FIXTURE_TEST_CASE(stakebase_detection, WalletStakeTestingSetup)
{
    const uint256& dummyOutputHash = GetRandHash();
    const uint256& prevOutputHash = emptyData.hash;
    const uint32_t& prevOutputIndex = static_cast<uint32_t>(-1);
    const CScript& stakeBaseSigScript = consensus.stakeBaseSigScript;

    // prevout.n
    BOOST_CHECK_EQUAL(HasStakebaseContents(CTxIn(prevOutputHash, 0, stakeBaseSigScript)), false);
    BOOST_CHECK_EQUAL(HasStakebaseContents(CTxIn(prevOutputHash, 1, stakeBaseSigScript)), false);
    BOOST_CHECK_EQUAL(HasStakebaseContents(CTxIn(prevOutputHash, 2, stakeBaseSigScript)), false);

    // sigScript
    BOOST_CHECK_EQUAL(HasStakebaseContents(CTxIn(prevOutputHash, prevOutputIndex, CScript())), false);
    BOOST_CHECK_EQUAL(HasStakebaseContents(CTxIn(prevOutputHash, prevOutputIndex, CScript() << 0x01)), false);
    BOOST_CHECK_EQUAL(HasStakebaseContents(CTxIn(prevOutputHash, prevOutputIndex, CScript() << 0x01 << 0x02)), false);
    BOOST_CHECK_EQUAL(HasStakebaseContents(CTxIn(prevOutputHash, prevOutputIndex, CScript() << 0x01)), false);

    // prevout.hash
    BOOST_CHECK_EQUAL(HasStakebaseContents(CTxIn(dummyOutputHash, prevOutputIndex, stakeBaseSigScript)), false);

    // correct
    BOOST_CHECK(HasStakebaseContents(CTxIn(prevOutputHash, prevOutputIndex, stakeBaseSigScript)));
}

// test the vote bits
BOOST_FIXTURE_TEST_CASE(vote_bits, WalletStakeTestingSetup)
{
    // default values

    BOOST_CHECK(VoteBits::allRejected.getBits() == 0x0000);
    BOOST_CHECK(VoteBits::rttAccepted.getBits() == 0x0001);

    // default construction

    BOOST_CHECK(VoteBits().getBits() == 0x0000);

    // construction from uint16_t

    BOOST_CHECK(VoteBits(0x0000).getBits() == 0x0000);
    BOOST_CHECK(VoteBits(0x0001).getBits() == 0x0001);
    BOOST_CHECK(VoteBits(0x1234).getBits() == 0x1234);
    BOOST_CHECK(VoteBits(0xFFFF).getBits() == 0xFFFF);

    // construction with signaled bit

    BOOST_CHECK(VoteBits(VoteBits::Rtt, true).getBits() == 0x0001);
    BOOST_CHECK(VoteBits(VoteBits::Rtt, false).getBits() == 0x0000);
    BOOST_CHECK(VoteBits(1, true).getBits() == 0x0002);
    BOOST_CHECK(VoteBits(1, false).getBits() == 0x0000);
    BOOST_CHECK(VoteBits(7, true).getBits() == 0x0080);
    BOOST_CHECK(VoteBits(7, false).getBits() == 0x0000);
    BOOST_CHECK(VoteBits(15, true).getBits() == 0x8000);
    BOOST_CHECK(VoteBits(15, false).getBits() == 0x0000);

    // copy constructor (also testing getting all the bits)

    VoteBits vb1;
    BOOST_CHECK(VoteBits(vb1).getBits() == 0x0000);

    vb1 = VoteBits(0x0001);
    BOOST_CHECK(VoteBits(vb1).getBits() == 0x0001);

    vb1 = VoteBits(0x1234);
    BOOST_CHECK(VoteBits(vb1).getBits() == 0x1234);

    vb1 = VoteBits(0xFFFF);
    BOOST_CHECK(VoteBits(vb1).getBits() == 0xFFFF);

    // move constructor

    vb1 = VoteBits(0x0000);
    BOOST_CHECK(VoteBits(std::move(vb1)).getBits() == 0x0000);

    vb1 = VoteBits(0x0001);
    BOOST_CHECK(VoteBits(std::move(vb1)).getBits() == 0x0001);

    vb1 = VoteBits(0x1234);
    BOOST_CHECK(VoteBits(std::move(vb1)).getBits() == 0x1234);

    vb1 = VoteBits(0xFFFF);
    BOOST_CHECK(VoteBits(std::move(vb1)).getBits() == 0xFFFF);

    // copy assignment

    vb1 = VoteBits(0x0000);
    VoteBits vb2 = vb1;
    BOOST_CHECK(vb2.getBits() == 0x0000);

    vb1 = VoteBits(0x0001);
    vb2 = vb1;
    BOOST_CHECK(vb2.getBits() == 0x0001);

    vb1 = VoteBits(0x1234);
    vb2 = vb1;
    BOOST_CHECK(vb2.getBits() == 0x1234);

    vb1 = VoteBits(0xFFFF);
    vb2 = vb1;
    BOOST_CHECK(vb2.getBits() == 0xFFFF);

    // move assignment

    vb1 = VoteBits(0x0000);
    vb2 = std::move(vb1);
    BOOST_CHECK(vb2.getBits() == 0x0000);

    vb1 = VoteBits(0x0001);
    vb2 = std::move(vb1);
    BOOST_CHECK(vb2.getBits() == 0x0001);

    vb1 = VoteBits(0x1234);
    vb2 = std::move(vb1);
    BOOST_CHECK(vb2.getBits() == 0x1234);

    vb1 = VoteBits(0xFFFF);
    vb2 = std::move(vb1);
    BOOST_CHECK(vb2.getBits() == 0xFFFF);

    // equality

    vb1 = VoteBits(0x0000);
    BOOST_CHECK(vb1 == VoteBits(0x0000));

    vb1 = VoteBits(0x0001);
    BOOST_CHECK(vb1 == VoteBits(0x0001));

    vb1 = VoteBits(0x1234);
    BOOST_CHECK(vb1 == VoteBits(0x1234));

    vb1 = VoteBits(0xFFFF);
    BOOST_CHECK(vb1 == VoteBits(0xFFFF));

    // inequality

    vb1 = VoteBits(0x0000);
    BOOST_CHECK(vb1 != VoteBits(0x0001));
    BOOST_CHECK(vb1 != VoteBits(0x1234));
    BOOST_CHECK(vb1 != VoteBits(0xFFFF));

    vb1 = VoteBits(0x0001);
    BOOST_CHECK(vb1 != VoteBits(0x0000));
    BOOST_CHECK(vb1 != VoteBits(0x1234));
    BOOST_CHECK(vb1 != VoteBits(0xFFFF));

    vb1 = VoteBits(0x1234);
    BOOST_CHECK(vb1 != VoteBits(0x0000));
    BOOST_CHECK(vb1 != VoteBits(0x0001));
    BOOST_CHECK(vb1 != VoteBits(0xFFFF));

    vb1 = VoteBits(0xFFFF);
    BOOST_CHECK(vb1 != VoteBits(0x0000));
    BOOST_CHECK(vb1 != VoteBits(0x0001));
    BOOST_CHECK(vb1 != VoteBits(0x1234));

    // set bit

    vb1 = VoteBits(0x0000);

    vb1.setBit(VoteBits::Rtt, true);
    BOOST_CHECK(vb1.getBits() == 0x0001);
    vb1.setBit(VoteBits::Rtt, false);
    BOOST_CHECK(vb1.getBits() == 0x0000);

    vb1.setBit(1, true);
    BOOST_CHECK(vb1.getBits() == 0x0002);
    vb1.setBit(1, false);
    BOOST_CHECK(vb1.getBits() == 0x0000);

    vb1.setBit(7, true);
    BOOST_CHECK(vb1.getBits() == 0x0080);
    vb1.setBit(7, false);
    BOOST_CHECK(vb1.getBits() == 0x0000);

    vb1.setBit(15, true);
    BOOST_CHECK(vb1.getBits() == 0x8000);
    vb1.setBit(15, false);
    BOOST_CHECK(vb1.getBits() == 0x0000);

    // get bit

    vb1 = VoteBits(0x0001);
    BOOST_CHECK(vb1.getBit(VoteBits::Rtt));
    vb1 = VoteBits(0x0000);
    BOOST_CHECK(!vb1.getBit(VoteBits::Rtt));

    vb1 = VoteBits(0x0002);
    BOOST_CHECK(vb1.getBit(1));
    vb1 = VoteBits(0x0000);
    BOOST_CHECK(!vb1.getBit(1));

    vb1 = VoteBits(0x0080);
    BOOST_CHECK(vb1.getBit(7));
    vb1 = VoteBits(0x0000);
    BOOST_CHECK(!vb1.getBit(7));

    vb1 = VoteBits(0x8000);
    BOOST_CHECK(vb1.getBit(15));
    vb1 = VoteBits(0x0000);
    BOOST_CHECK(!vb1.getBit(15));

    vb1 = VoteBits(0x0003);
    BOOST_CHECK(vb1.getBit(0));
    BOOST_CHECK(vb1.getBit(1));
    BOOST_CHECK(!vb1.getBit(2));

    vb1 = VoteBits(0xFFFE);
    BOOST_CHECK(!vb1.getBit(0));
    BOOST_CHECK(vb1.getBit(1));
    BOOST_CHECK(vb1.getBit(2));
    BOOST_CHECK(vb1.getBit(7));
    BOOST_CHECK(vb1.getBit(15));

    // RTT acceptance verification

    vb1 = VoteBits(0x0001);
    BOOST_CHECK(vb1.isRttAccepted());
    vb1 = VoteBits(0x4321);
    BOOST_CHECK(vb1.isRttAccepted());
    vb1 = VoteBits(0xCDEF);
    BOOST_CHECK(vb1.isRttAccepted());

    vb1 = VoteBits(0x0000);
    BOOST_CHECK(!vb1.isRttAccepted());
    vb1 = VoteBits(0x1234);
    BOOST_CHECK(!vb1.isRttAccepted());
    vb1 = VoteBits(0xFFFE);
    BOOST_CHECK(!vb1.isRttAccepted());

    // RTT acceptance control

    vb1 = VoteBits(0x0000);
    vb1.setRttAccepted(true);
    BOOST_CHECK(vb1.getBits() == 0x0001);
    vb1.setRttAccepted(false);
    BOOST_CHECK(vb1.getBits() == 0x0000);

    vb1 = VoteBits(0x1234);
    vb1.setRttAccepted(true);
    BOOST_CHECK(vb1.getBits() == 0x1235);
    vb1.setRttAccepted(false);
    BOOST_CHECK(vb1.getBits() == 0x1234);

    vb1 = VoteBits(0xFFFE);
    vb1.setRttAccepted(true);
    BOOST_CHECK(vb1.getBits() == 0xFFFF);
    vb1.setRttAccepted(false);
    BOOST_CHECK(vb1.getBits() == 0xFFFE);

    vb1 = VoteBits(0xFFFF);
    vb1.setRttAccepted(true);
    BOOST_CHECK(vb1.getBits() == 0xFFFF);
    vb1.setRttAccepted(false);
    BOOST_CHECK(vb1.getBits() == 0xFFFE);
}

// test the extended vote bits functions
BOOST_FIXTURE_TEST_CASE(extended_vote_bits, WalletStakeTestingSetup)
{
    // string validation

    BOOST_CHECK(ExtendedVoteBits::containsValidExtendedVoteBits("00"));
    BOOST_CHECK(ExtendedVoteBits::containsValidExtendedVoteBits("01"));
    BOOST_CHECK(ExtendedVoteBits::containsValidExtendedVoteBits("0123"));
    BOOST_CHECK(ExtendedVoteBits::containsValidExtendedVoteBits("1234567890abcdef"));
    BOOST_CHECK(ExtendedVoteBits::containsValidExtendedVoteBits("1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"));
    BOOST_CHECK(ExtendedVoteBits::containsValidExtendedVoteBits(extendedVoteBitsData.validLargeString));

    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits("0"));
    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits("1"));
    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits("012"));
    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits("12345"));
    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits("abc"));
    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits("lala"));
    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits("a!"));
    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits(" "));
    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits("a "));
    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits(emptyData.string));
    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits(extendedVoteBitsData.invalidLargeString));

    // vector validation

    std::vector<unsigned char> vect = {0x00};
    BOOST_CHECK(ExtendedVoteBits::containsValidExtendedVoteBits(vect));
    vect = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
    BOOST_CHECK(ExtendedVoteBits::containsValidExtendedVoteBits(vect));
    BOOST_CHECK(ExtendedVoteBits::containsValidExtendedVoteBits(extendedVoteBitsData.validLargeVector));

    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits(emptyData.vector));
    BOOST_CHECK(!ExtendedVoteBits::containsValidExtendedVoteBits(extendedVoteBitsData.invalidLargeVector));

    // vote data size

    VoteData voteData;
    BOOST_CHECK_EQUAL(ExtendedVoteBits::minSize(), 1U);
    BOOST_CHECK_EQUAL(ExtendedVoteBits::maxSize(), nMaxStructDatacarrierBytes - GetVoteDataSizeWithEmptyExtendedVoteBits() - 1);
    BOOST_CHECK_EQUAL(GetVoteDataSizeWithEmptyExtendedVoteBits(), GetSerializeSize(GetScriptForVoteDecl(voteData), SER_NETWORK, PROTOCOL_VERSION));

    // default construction

    BOOST_CHECK(ExtendedVoteBits().getVector() == extendedVoteBitsData.empty.getVector());

    // construction from string

    vect = {0x00};
    BOOST_CHECK(ExtendedVoteBits("00").getVector() == vect);

    vect = {0x01};
    BOOST_CHECK(ExtendedVoteBits("01").getVector() == vect);

    vect = {0x01, 0x23};
    BOOST_CHECK(ExtendedVoteBits("0123").getVector() == vect);

    vect = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
    BOOST_CHECK(ExtendedVoteBits("0123456789abcdef").getVector() == vect);

    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.validLargeString).getVector() == extendedVoteBitsData.validLargeVector);

    BOOST_CHECK(ExtendedVoteBits(emptyData.string).getVector() == extendedVoteBitsData.empty.getVector());
    BOOST_CHECK(ExtendedVoteBits("").getVector() == extendedVoteBitsData.empty.getVector());
    BOOST_CHECK(ExtendedVoteBits("0").getVector() == extendedVoteBitsData.empty.getVector());
    BOOST_CHECK(ExtendedVoteBits("1").getVector() == extendedVoteBitsData.empty.getVector());
    BOOST_CHECK(ExtendedVoteBits("123").getVector() == extendedVoteBitsData.empty.getVector());
    BOOST_CHECK(ExtendedVoteBits("12345").getVector() == extendedVoteBitsData.empty.getVector());
    BOOST_CHECK(ExtendedVoteBits("abc").getVector() == extendedVoteBitsData.empty.getVector());
    BOOST_CHECK(ExtendedVoteBits("lala").getVector() == extendedVoteBitsData.empty.getVector());
    BOOST_CHECK(ExtendedVoteBits("a!").getVector() == extendedVoteBitsData.empty.getVector());
    BOOST_CHECK(ExtendedVoteBits(" ").getVector() == extendedVoteBitsData.empty.getVector());
    BOOST_CHECK(ExtendedVoteBits("a ").getVector() == extendedVoteBitsData.empty.getVector());
    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.invalidLargeString).getVector() == extendedVoteBitsData.empty.getVector());

    // construction from vector (also testing vector access)

    vect = {0x00};
    BOOST_CHECK(ExtendedVoteBits(vect).getVector() == vect);

    vect = {0x01};
    BOOST_CHECK(ExtendedVoteBits(vect).getVector() == vect);

    vect = {0x01, 0x23};
    BOOST_CHECK(ExtendedVoteBits(vect).getVector() == vect);

    vect = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
    BOOST_CHECK(ExtendedVoteBits(vect).getVector() == vect);

    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.validLargeVector).getVector() == extendedVoteBitsData.validLargeVector);

    vect.clear();
    BOOST_CHECK(ExtendedVoteBits(vect).getVector() == extendedVoteBitsData.empty.getVector());

    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.invalidLargeVector).getVector() == extendedVoteBitsData.empty.getVector());

    // copy constructor

    vect = {0x00};
    BOOST_CHECK(ExtendedVoteBits(ExtendedVoteBits(vect)).getVector() == vect);

    vect = {0x01, 0x23};
    BOOST_CHECK(ExtendedVoteBits(ExtendedVoteBits(vect)).getVector() == vect);

    vect = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
    BOOST_CHECK(ExtendedVoteBits(ExtendedVoteBits(vect)).getVector() == vect);

    BOOST_CHECK(ExtendedVoteBits(ExtendedVoteBits(extendedVoteBitsData.validLargeVector)).getVector() == extendedVoteBitsData.validLargeVector);

    BOOST_CHECK(ExtendedVoteBits(ExtendedVoteBits()).getVector() == extendedVoteBitsData.empty.getVector());
    BOOST_CHECK(ExtendedVoteBits(ExtendedVoteBits(extendedVoteBitsData.invalidLargeVector)).getVector() == extendedVoteBitsData.empty.getVector());

    // move constructor

    vect = {0x00};
    ExtendedVoteBits evb1 = ExtendedVoteBits(vect);
    BOOST_CHECK(ExtendedVoteBits(std::move(evb1)).getVector() == vect);

    vect = {0x01, 0x23};
    evb1 = ExtendedVoteBits(vect);
    BOOST_CHECK(ExtendedVoteBits(std::move(evb1)).getVector() == vect);

    vect = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
    evb1 = ExtendedVoteBits(vect);
    BOOST_CHECK(ExtendedVoteBits(std::move(evb1)).getVector() == vect);

    evb1 = ExtendedVoteBits(extendedVoteBitsData.validLargeVector);
    BOOST_CHECK(ExtendedVoteBits(std::move(evb1)).getVector() == extendedVoteBitsData.validLargeVector);

    evb1 = ExtendedVoteBits();
    BOOST_CHECK(ExtendedVoteBits(std::move(evb1)).getVector() == extendedVoteBitsData.empty.getVector());

    evb1 = ExtendedVoteBits(extendedVoteBitsData.invalidLargeVector);
    BOOST_CHECK(ExtendedVoteBits(std::move(evb1)).getVector() == extendedVoteBitsData.empty.getVector());

    // copy assignment

    vect = {0x00};
    evb1 = ExtendedVoteBits(vect);
    ExtendedVoteBits evb2 = evb1;
    BOOST_CHECK(evb2.getVector() == vect);

    vect = {0x01, 0x23};
    evb1 = ExtendedVoteBits(vect);
    evb2 = evb1;
    BOOST_CHECK(evb2.getVector() == vect);

    vect = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
    evb1 = ExtendedVoteBits(vect);
    evb2 = evb1;
    BOOST_CHECK(evb2.getVector() == vect);

    evb1 = ExtendedVoteBits(extendedVoteBitsData.validLargeVector);
    evb2 = evb1;
    BOOST_CHECK(evb2.getVector() == extendedVoteBitsData.validLargeVector);

    evb1 = ExtendedVoteBits();
    evb2 = evb1;
    BOOST_CHECK(evb2.getVector() == extendedVoteBitsData.empty.getVector());

    evb1 = ExtendedVoteBits(extendedVoteBitsData.invalidLargeVector);
    evb2 = evb1;
    BOOST_CHECK(evb2.getVector() == extendedVoteBitsData.empty.getVector());

    // move assignment

    vect = {0x00};
    evb1 = ExtendedVoteBits(vect);
    evb2 = std::move(evb1);
    BOOST_CHECK(evb2.getVector() == vect);

    vect = {0x01, 0x23};
    evb1 = ExtendedVoteBits(vect);
    evb2 = std::move(evb1);
    BOOST_CHECK(evb2.getVector() == vect);

    vect = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
    evb1 = ExtendedVoteBits(vect);
    evb2 = std::move(evb1);
    BOOST_CHECK(evb2.getVector() == vect);

    evb1 = ExtendedVoteBits(extendedVoteBitsData.validLargeVector);
    evb2 = std::move(evb1);
    BOOST_CHECK(evb2.getVector() == extendedVoteBitsData.validLargeVector);

    evb1 = ExtendedVoteBits();
    evb2 = std::move(evb1);
    BOOST_CHECK(evb2.getVector() == extendedVoteBitsData.empty.getVector());

    evb1 = ExtendedVoteBits(extendedVoteBitsData.invalidLargeVector);
    evb2 = std::move(evb1);
    BOOST_CHECK(evb2.getVector() == extendedVoteBitsData.empty.getVector());

    // equality

    vect = {0x00};
    BOOST_CHECK(ExtendedVoteBits(vect) == ExtendedVoteBits("00"));

    vect = {0x01, 0x23};
    BOOST_CHECK(ExtendedVoteBits(vect) == ExtendedVoteBits("0123"));

    vect = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
    BOOST_CHECK(ExtendedVoteBits(vect) == ExtendedVoteBits("0123456789abcdef"));

    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.validLargeVector) == ExtendedVoteBits(extendedVoteBitsData.validLargeString));
    BOOST_CHECK(ExtendedVoteBits() == extendedVoteBitsData.empty);
    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.invalidLargeVector) == ExtendedVoteBits());

    // inequality

    vect = {0x00};
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits("01"));
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits("0123"));
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits("0123456789abcdef"));
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits(extendedVoteBitsData.validLargeString));

    vect = {0x01};
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits("00"));
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits("0123"));
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits("0123456789abcdef"));
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits(extendedVoteBitsData.validLargeString));

    vect = {0x01, 0x23};
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits("00"));
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits("01"));
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits("0123456789abcdef"));
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits(extendedVoteBitsData.validLargeString));

    vect = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits("00"));
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits("01"));
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits("0123"));
    BOOST_CHECK(ExtendedVoteBits(vect) != ExtendedVoteBits(extendedVoteBitsData.validLargeString));

    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.validLargeString) != ExtendedVoteBits("00"));
    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.validLargeString) != ExtendedVoteBits("01"));
    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.validLargeString) != ExtendedVoteBits("0123"));
    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.validLargeString) != ExtendedVoteBits("0123456789abcdef"));

    // validity (also see vector access below)

    BOOST_CHECK(ExtendedVoteBits().isValid());
    BOOST_CHECK(ExtendedVoteBits("00").isValid());
    BOOST_CHECK(ExtendedVoteBits("01").isValid());
    BOOST_CHECK(ExtendedVoteBits("0123").isValid());
    BOOST_CHECK(ExtendedVoteBits("0123456789abcdef").isValid());
    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.validLargeString).isValid());
    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.invalidLargeString).isValid());

    // vector access (mostly already tested in the constructor area above)
    // const_cast like this is highly discouraged

    evb1 = ExtendedVoteBits();
    const_cast<std::vector<unsigned char>&>(evb1.getVector()).clear();
    BOOST_CHECK(!evb1.isValid());

    evb1 = ExtendedVoteBits();
    const_cast<std::vector<unsigned char>&>(evb1.getVector()) = extendedVoteBitsData.validLargeVector;
    BOOST_CHECK(evb1.getVector() == extendedVoteBitsData.validLargeVector);

    evb1 = ExtendedVoteBits();
    const_cast<std::vector<unsigned char>&>(evb1.getVector()) = extendedVoteBitsData.invalidLargeVector;
    BOOST_CHECK(!evb1.isValid());

    // hexadecimal string

    BOOST_CHECK(ExtendedVoteBits().getHex() == "00");

    vect = {0x00};
    BOOST_CHECK(ExtendedVoteBits(vect).getHex() == "00");

    vect = {0x01, 0x23};
    BOOST_CHECK(ExtendedVoteBits(vect).getHex() == "0123");

    vect = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
    BOOST_CHECK(ExtendedVoteBits(vect).getHex() == "0123456789abcdef");

    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.validLargeVector).getHex() == extendedVoteBitsData.validLargeString);

    BOOST_CHECK(ExtendedVoteBits(extendedVoteBitsData.invalidLargeVector).getHex() == "00");
}

// test the transaction for votes
BOOST_FIXTURE_TEST_CASE(vote_transaction, WalletStakeTestingSetup)
{
    std::string voteHashStr;
    CWalletError we;

    LOCK2(cs_main, wallet->cs_wallet);

    // Premature votes and preconditions

    {
        // ticket hash
        std::tie(voteHashStr, we) = wallet->Vote(emptyData.hash, chainActive.Tip()->GetBlockHash(), chainActive.Tip()->nHeight, VoteBits::allRejected, extendedVoteBitsData.empty);
        BOOST_CHECK_EQUAL(we.code, CWalletError::INVALID_PARAMETER);

        // stake validation height not reached yet
        std::tie(voteHashStr, we) = wallet->Vote(chainActive.Tip()->GetBlockHash(), chainActive.Tip()->GetBlockHash(), chainActive.Tip()->nHeight, VoteBits::allRejected, extendedVoteBitsData.empty);
        BOOST_CHECK_EQUAL(we.code, CWalletError::INVALID_PARAMETER);

        ExtendChain(consensus.nStakeValidationHeight - chainActive.Height());

        // block hash
        std::tie(voteHashStr, we) = wallet->Vote(chainActive.Tip()->GetBlockHash(), emptyData.hash, chainActive.Tip()->nHeight, VoteBits::allRejected, extendedVoteBitsData.empty);
        BOOST_CHECK_EQUAL(we.code, CWalletError::INVALID_PARAMETER);
        std::tie(voteHashStr, we) = wallet->Vote(chainActive.Tip()->GetBlockHash(), chainActive.Tip()->pprev->GetBlockHash(), chainActive.Tip()->nHeight, VoteBits::allRejected, extendedVoteBitsData.empty);
        BOOST_CHECK_EQUAL(we.code, CWalletError::INVALID_PARAMETER);

        // block height
        std::tie(voteHashStr, we) = wallet->Vote(chainActive.Tip()->GetBlockHash(), chainActive.Tip()->GetBlockHash(), chainActive.Tip()->nHeight - 1, VoteBits::allRejected, extendedVoteBitsData.empty);
        BOOST_CHECK_EQUAL(we.code, CWalletError::INVALID_PARAMETER);
        std::tie(voteHashStr, we) = wallet->Vote(chainActive.Tip()->GetBlockHash(), chainActive.Tip()->GetBlockHash(), chainActive.Tip()->nHeight + 1, VoteBits::allRejected, extendedVoteBitsData.empty);
        BOOST_CHECK_EQUAL(we.code, CWalletError::INVALID_PARAMETER);

        // ticket
        std::tie(voteHashStr, we) = wallet->Vote(chainActive.Tip()->GetBlockHash(), chainActive.Tip()->GetBlockHash(), chainActive.Tip()->nHeight, VoteBits::allRejected, extendedVoteBitsData.empty);
        BOOST_CHECK_EQUAL(we.code, CWalletError::INVALID_ADDRESS_OR_KEY);
    }

    // Single vote

    {
        BOOST_CHECK(chainActive.Tip()->pstakeNode->Winners().size() > 0);

        const uint256 ticketHash = chainActive.Tip()->pstakeNode->Winners()[0];
        BOOST_CHECK(ticketHash != emptyData.hash);

        std::tie(voteHashStr, we) = wallet->Vote(ticketHash, chainActive.Tip()->GetBlockHash(), chainActive.Tip()->nHeight, VoteBits::rttAccepted, extendedVoteBitsData.empty);
        BOOST_CHECK_EQUAL(we.code, CWalletError::SUCCESSFUL);
        BOOST_CHECK(voteHashStr.length() > 0);

        const uint256& voteHash = uint256S(voteHashStr);

        BOOST_CHECK(MempoolHasVoteForTicket(ticketHash));

        const CWalletTx* ticket = wallet->GetWalletTx(ticketHash);
        BOOST_CHECK(ticket != nullptr);
        BOOST_CHECK(ticket->tx != nullptr);

        const CWalletTx* vote = wallet->GetWalletTx(voteHash);
        BOOST_CHECK(vote != nullptr);
        BOOST_CHECK(vote->tx != nullptr);

        CheckVote(*vote->tx, *ticket->tx);

        ExtendChain(1);

        BOOST_CHECK(std::find_if(votesInLastBlock.begin(), votesInLastBlock.end(), [&voteHash](const CTransactionRef tx) { return tx->GetHash() == voteHash; }) != votesInLastBlock.end());
    }

    // Multiple votes

    {
        BOOST_CHECK(chainActive.Tip()->pstakeNode->Winners().size() > 0);

        std::vector<uint256> voteHashes;

        for (const uint256& ticketHash : chainActive.Tip()->pstakeNode->Winners()) {
            BOOST_CHECK(ticketHash != emptyData.hash);

            std::tie(voteHashStr, we) = wallet->Vote(ticketHash, chainActive.Tip()->GetBlockHash(), chainActive.Tip()->nHeight, VoteBits::rttAccepted, extendedVoteBitsData.empty);
            BOOST_CHECK_EQUAL(we.code, CWalletError::SUCCESSFUL);
            BOOST_CHECK(voteHashStr.length() > 0);

            const uint256 voteHash = uint256S(voteHashStr);

            BOOST_CHECK(MempoolHasVoteForTicket(ticketHash));

            const CWalletTx* ticket = wallet->GetWalletTx(ticketHash);
            BOOST_CHECK(ticket != nullptr);
            BOOST_CHECK(ticket->tx != nullptr);

            const CWalletTx* vote = wallet->GetWalletTx(voteHash);
            BOOST_CHECK(vote != nullptr);
            BOOST_CHECK(vote->tx != nullptr);

            CheckVote(*vote->tx, *ticket->tx);

            voteHashes.push_back(voteHash);
        }

        ExtendChain(1);

        for (const uint256& voteHash : voteHashes)
            BOOST_CHECK(std::find_if(votesInLastBlock.begin(), votesInLastBlock.end(), [&voteHash](const CTransactionRef tx) { return tx->GetHash() == voteHash; }) != votesInLastBlock.end());
    }

    // Encrypted wallet

    {
        wallet->EncryptWallet(passphrase);
        BOOST_CHECK(wallet->IsLocked());

        const uint256 ticketHash = chainActive.Tip()->pstakeNode->Winners()[0];
        BOOST_CHECK(ticketHash != emptyData.hash);

        std::tie(voteHashStr, we) = wallet->Vote(ticketHash, chainActive.Tip()->GetBlockHash(), chainActive.Tip()->nHeight, VoteBits::rttAccepted, extendedVoteBitsData.empty);
        BOOST_CHECK_EQUAL(we.code, CWalletError::WALLET_UNLOCK_NEEDED);
    }
}

// test the transaction for votes with VSP support
BOOST_FIXTURE_TEST_CASE(vote_transaction_vsp, WalletStakeTestingSetup)
{
    std::string voteHashStr;
    CWalletError we;

    LOCK2(cs_main, wallet->cs_wallet);

    ExtendChain(consensus.nStakeValidationHeight - chainActive.Height(), true, true);

    BOOST_CHECK(chainActive.Tip()->pstakeNode->Winners().size() > 0);

    std::vector<uint256> voteHashes;

    for (const uint256& ticketHash : chainActive.Tip()->pstakeNode->Winners()) {
        BOOST_CHECK(ticketHash != emptyData.hash);

        std::tie(voteHashStr, we) = wallet->Vote(ticketHash, chainActive.Tip()->GetBlockHash(), chainActive.Tip()->nHeight, VoteBits::rttAccepted, extendedVoteBitsData.empty);
        BOOST_CHECK_EQUAL(we.code, CWalletError::SUCCESSFUL);
        BOOST_CHECK(voteHashStr.length() > 0);

        const uint256 voteHash = uint256S(voteHashStr);

        BOOST_CHECK(MempoolHasVoteForTicket(ticketHash));

        const CWalletTx* ticket = wallet->GetWalletTx(ticketHash);
        BOOST_CHECK(ticket != nullptr);
        BOOST_CHECK(ticket->tx != nullptr);

        const CWalletTx* vote = wallet->GetWalletTx(voteHash);
        BOOST_CHECK(vote != nullptr);
        BOOST_CHECK(vote->tx != nullptr);

        CheckVote(*vote->tx, *ticket->tx);

        voteHashes.push_back(voteHash);
    }

    ExtendChain(1);

    for (const uint256& voteHash : voteHashes)
        BOOST_CHECK(std::find_if(votesInLastBlock.begin(), votesInLastBlock.end(), [&voteHash](const CTransactionRef tx) { return tx->GetHash() == voteHash; }) != votesInLastBlock.end());
}

// test the failing transaction for votes that spend ticket not belonging to the wallet
BOOST_FIXTURE_TEST_CASE(foreign_ticket_vote_transaction, WalletStakeTestingSetup)
{
    std::string txHash;
    CWalletError we;

    LOCK2(cs_main, wallet->cs_wallet);

    ExtendChain(consensus.nStakeValidationHeight - 1 - chainActive.Tip()->nHeight, true, false, true);

    BOOST_CHECK_GT(chainActive.Tip()->pstakeNode->Winners().size(), 0U);

    for (auto& hash : chainActive.Tip()->pstakeNode->Winners()) {
        std::tie(txHash, we) = wallet->Vote(hash, chainActive.Tip()->GetBlockHash(), chainActive.Tip()->nHeight, VoteBits::allRejected, extendedVoteBitsData.empty);
        BOOST_CHECK_EQUAL(we.code, CWalletError::INVALID_ADDRESS_OR_KEY);
    }
}

// test the failing transaction for votes that spend ticket not belonging to the wallet and using VSP
BOOST_FIXTURE_TEST_CASE(foreign_vsp_ticket_vote_transaction, WalletStakeTestingSetup)
{
    std::string txHash;
    CWalletError we;

    LOCK2(cs_main, wallet->cs_wallet);

    ExtendChain(consensus.nStakeValidationHeight - 1 - chainActive.Tip()->nHeight, true, true, true);

    BOOST_CHECK_GT(chainActive.Tip()->pstakeNode->Winners().size(), 0U);

    for (auto& hash : chainActive.Tip()->pstakeNode->Winners()) {
        std::tie(txHash, we) = wallet->Vote(hash, chainActive.Tip()->GetBlockHash(), chainActive.Tip()->nHeight, VoteBits::allRejected, extendedVoteBitsData.empty);
        BOOST_CHECK_EQUAL(we.code, CWalletError::INVALID_ADDRESS_OR_KEY);
    }
}

// test the automatic voter
BOOST_FIXTURE_TEST_CASE(auto_voter, WalletStakeTestingSetup)
{
    LOCK2(cs_main, wallet->cs_wallet);

    CAutoVoter* av = wallet->GetAutoVoter();
    BOOST_CHECK(av != nullptr);

    BOOST_CHECK(!av->isStarted());

    CAutoVoterConfig& cfg = av->GetConfig();

    // Premature votes and preconditions

    av->start();
    ExtendChain(1);
    BOOST_CHECK(votesInLastBlock.size() == 0U);
    ExtendChain(1);
    BOOST_CHECK(votesInLastBlock.size() == 0U);
    av->stop();

    ExtendChain(consensus.nStakeValidationHeight - chainActive.Height());

    av->start();

    // All tickets (in mempool)

    ExtendChain(1);
    CheckLatestVotes(true);

    // All tickets (in blockchain) (from previous extension)

    ExtendChain(1, false);
    CheckLatestVotes();

    // Encrypted wallet (no passphrase)

    wallet->EncryptWallet(passphrase);
    BOOST_CHECK(wallet->IsLocked());

    ExtendChain(1, false); // (from previous extension)
    BOOST_CHECK(ExtendChain(1, false) == false);
    BOOST_CHECK(votesInLastBlock.size() == 0U);

    // Encrypted wallet (wrong passphrase)

    cfg.passphrase = "aWr0ngP4$$word";

    BOOST_CHECK(ExtendChain(1, false) == false);
    BOOST_CHECK(votesInLastBlock.size() == 0U);

    // Encrypted wallet (good passphrase)

    cfg.passphrase = passphrase;

    ExtendChain(1);
    BOOST_CHECK(votesInLastBlock.size() > 0U);
    CheckLatestVotes(true);

    BOOST_CHECK(ExtendChain(1, false));
    BOOST_CHECK(votesInLastBlock.size() > 0U);
    CheckLatestVotes();

    av->stop();
}

// test the automatic voter with VSP support
BOOST_FIXTURE_TEST_CASE(auto_voter_vsp, WalletStakeTestingSetup)
{
    LOCK2(cs_main, wallet->cs_wallet);

    CAutoVoter* av = wallet->GetAutoVoter();
    BOOST_CHECK(av != nullptr);

    BOOST_CHECK(!av->isStarted());

    CAutoVoterConfig& cfg = av->GetConfig();

    // Premature votes and preconditions

    ExtendChain(consensus.nStakeValidationHeight - chainActive.Height(), true, true);

    av->start();

    // All tickets (in mempool)

    ExtendChain(1, true, true);
    CheckLatestVotes(true);

    // All tickets (in blockchain) (from previous extension)

    ExtendChain(1, false, true);
    CheckLatestVotes();

    // Encrypted wallet (no passphrase)

    wallet->EncryptWallet(passphrase);
    BOOST_CHECK(wallet->IsLocked());

    ExtendChain(1, false); // (from previous extension)
    BOOST_CHECK(ExtendChain(1, false, true) == false);
    BOOST_CHECK(votesInLastBlock.size() == 0U);

    // Encrypted wallet (wrong passphrase)

    cfg.passphrase = "aWr0ngP4$$word";

    BOOST_CHECK(ExtendChain(1, false, true) == false);
    BOOST_CHECK(votesInLastBlock.size() == 0U);

    // Encrypted wallet (good passphrase)

    cfg.passphrase = passphrase;

    ExtendChain(1, true, true);
    BOOST_CHECK(votesInLastBlock.size() > 0U);
    CheckLatestVotes(true);

    BOOST_CHECK(ExtendChain(1, false, true));
    BOOST_CHECK(votesInLastBlock.size() > 0U);
    CheckLatestVotes();

    av->stop();
}

// test the vote generating RPC
BOOST_FIXTURE_TEST_CASE(generate_vote_rpc, WalletStakeTestingSetup)
{
    vpwallets.insert(vpwallets.begin(), wallet.get());

    RegisterWalletRPCCommands(tableRPC);

    ExtendChain(consensus.nStakeValidationHeight - 1 - chainActive.Tip()->nHeight);

    uint256 blockHash = chainActive.Tip()->GetBlockHash();
    std::string blockHashStr = blockHash.GetHex();
    int blockHeight = chainActive.Tip()->nHeight;
    std::string blockHeightStr = std::to_string(blockHeight);
    BOOST_CHECK_EQUAL(chainActive.Tip()->pstakeNode->Winners().size(), consensus.nTicketsPerBlock);
    uint256 ticketHash = chainActive.Tip()->pstakeNode->Winners()[0];
    std::string ticketHashStr = ticketHash.GetHex();

    // missing required parameters

    BOOST_CHECK_THROW(CallRpc(std::string("generatevote")), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr), std::runtime_error);

    // block hash

    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + "0" + " " + blockHeightStr + " " + ticketHashStr + " " + "1"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + "test" + " " + blockHeightStr + " " + ticketHashStr + " " + "1"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + "abc!" + " " + blockHeightStr + " " + ticketHashStr + " " + "1"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + "123" + " " + blockHeightStr + " " + ticketHashStr + " " + "1"), std::runtime_error);

    // block height

    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + "0" + " " + ticketHashStr + " " + "1"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + "test" + " " + ticketHashStr + " " + "1"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + "abc!" + " " + ticketHashStr + " " + "1"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + "123" + " " + ticketHashStr + " " + "1"), std::runtime_error);

    // ticket hash

    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + "0" + " " + "1"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + "test" + " " + "1"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + "abc!" + " " + "1"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + "123" + " " + "1"), std::runtime_error);

    // vote bits

    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "-1"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "65536"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "test"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "abc!"), std::runtime_error);

    // vote yes

    UniValue r;

    BOOST_CHECK_NO_THROW(r = CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "1"));
    BOOST_CHECK(find_value(r.get_obj(), "hex").isStr());

    uint256 voteHash = uint256S(find_value(r.get_obj(), "hex").get_str());
    CheckVote(voteHash, ticketHash, VoteData{1, blockHash, static_cast<uint32_t>(blockHeight), VoteBits::rttAccepted, 0, extendedVoteBitsData.empty});

    // vote no

    ticketHash = chainActive.Tip()->pstakeNode->Winners()[1];
    ticketHashStr = ticketHash.GetHex();

    BOOST_CHECK_NO_THROW(r = CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "0"));

    voteHash = uint256S(find_value(r.get_obj(), "hex").get_str());
    CheckVote(voteHash, ticketHash, VoteData{1, blockHash, static_cast<uint32_t>(blockHeight), VoteBits::allRejected, 0, extendedVoteBitsData.empty});

    // vote exhaustive

    ticketHash = chainActive.Tip()->pstakeNode->Winners()[2];
    ticketHashStr = ticketHash.GetHex();

    BOOST_CHECK_NO_THROW(r = CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "65535"));

    voteHash = uint256S(find_value(r.get_obj(), "hex").get_str());
    CheckVote(voteHash, ticketHash, VoteData{1, blockHash, static_cast<uint32_t>(blockHeight), VoteBits(65535U), 0, extendedVoteBitsData.empty});

    // extended vote bits

    ticketHash = chainActive.Tip()->pstakeNode->Winners()[3];
    ticketHashStr = ticketHash.GetHex();

    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "1" + " " + "0"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "1" + " " + "1"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "1" + " " + "123"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "1" + " " + "abcde"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "1" + " " + "test"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "1" + " " + "abc!"), std::runtime_error);

    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "1" + " " + extendedVoteBitsData.invalidLargeString), std::runtime_error);

    BOOST_CHECK_NO_THROW(r = CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "1" + " " + "1234567890abcdef"));

    voteHash = uint256S(find_value(r.get_obj(), "hex").get_str());
    CheckVote(voteHash, ticketHash, VoteData{1, blockHash, static_cast<uint32_t>(blockHeight), VoteBits::rttAccepted, 0, ExtendedVoteBits("1234567890abcdef")});

    ticketHash = chainActive.Tip()->pstakeNode->Winners()[4];
    ticketHashStr = ticketHash.GetHex();

    BOOST_CHECK_NO_THROW(r = CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "1" + " " + extendedVoteBitsData.validLargeString));

    voteHash = uint256S(find_value(r.get_obj(), "hex").get_str());
    CheckVote(voteHash, ticketHash, VoteData{1, blockHash, static_cast<uint32_t>(blockHeight), VoteBits::rttAccepted, 0, ExtendedVoteBits(extendedVoteBitsData.validLargeString)});

    // encrypted wallet

    wallet->EncryptWallet(passphrase);
    BOOST_CHECK(wallet->IsLocked());

    ExtendChain(1);

    blockHash = chainActive.Tip()->GetBlockHash();
    blockHashStr = blockHash.GetHex();
    blockHeight = chainActive.Tip()->nHeight;
    blockHeightStr = std::to_string(blockHeight);
    BOOST_CHECK_EQUAL(chainActive.Tip()->pstakeNode->Winners().size(), consensus.nTicketsPerBlock);
    ticketHash = chainActive.Tip()->pstakeNode->Winners()[0];
    ticketHashStr = ticketHash.GetHex();

    BOOST_CHECK_THROW(CallRpc(std::string("generatevote ") + blockHashStr + " " + blockHeightStr + " " + ticketHashStr + " " + "1" + " " + extendedVoteBitsData.empty.getHex()), std::runtime_error);

    vpwallets.erase(std::remove(vpwallets.begin(), vpwallets.end(), wallet.get()), vpwallets.end());
}

// test the automatic voter RPCs
BOOST_FIXTURE_TEST_CASE(auto_voter_rpc, WalletStakeTestingSetup)
{
    vpwallets.insert(vpwallets.begin(), wallet.get());

    RegisterWalletRPCCommands(tableRPC);

    CPubKey ticketPubKey;
    BOOST_CHECK(wallet->GetKeyFromPool(ticketPubKey));
    CTxDestination ticketKeyId = ticketPubKey.GetID();
    std::string ticketAddress{EncodeDestination(ticketKeyId)};

    CPubKey vspPubKey;
    BOOST_CHECK(wallet->GetKeyFromPool(vspPubKey));
    CTxDestination vspKeyId = vspPubKey.GetID();
    std::string vspAddress{EncodeDestination(vspKeyId)};

    CAutoVoter* av = wallet->GetAutoVoter();
    BOOST_CHECK(av != nullptr);

    BOOST_CHECK(!av->isStarted());

    CAutoVoterConfig& cfg = av->GetConfig();

    // Settings (write)

    BOOST_CHECK_THROW(CallRpc("setautovotervotebits"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc("setautovotervotebits abc"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc("setautovotervotebits -1"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc("setautovotervotebits 65536"), std::runtime_error);

    BOOST_CHECK_NO_THROW(CallRpc("setautovotervotebits 0"));
    BOOST_CHECK(cfg.voteBits == VoteBits(0U));
    BOOST_CHECK_NO_THROW(CallRpc("setautovotervotebits 1234"));
    BOOST_CHECK(cfg.voteBits == VoteBits(1234U));
    BOOST_CHECK_NO_THROW(CallRpc("setautovotervotebits 65535"));
    BOOST_CHECK(cfg.voteBits == VoteBits(65535U));
    BOOST_CHECK_NO_THROW(CallRpc("setautovotervotebits 1"));
    BOOST_CHECK(cfg.voteBits == VoteBits(1U));

    BOOST_CHECK_THROW(CallRpc("setautovotervotebitsext"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc("setautovotervotebitsext "), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc("setautovotervotebitsext  "), std::runtime_error);

    std::string largeExtendedVoteBits;
    for (unsigned i = 0; i <= ExtendedVoteBits::maxSize(); ++i)
        largeExtendedVoteBits += "00";
    BOOST_CHECK_THROW(CallRpc("setautovotervotebitsext " + largeExtendedVoteBits), std::runtime_error);

    BOOST_CHECK(cfg.extendedVoteBits == extendedVoteBitsData.empty);

    BOOST_CHECK_NO_THROW(CallRpc("setautovotervotebitsext 00"));
    BOOST_CHECK(cfg.extendedVoteBits == ExtendedVoteBits("00"));
    BOOST_CHECK_NO_THROW(CallRpc("setautovotervotebitsext 1234"));
    BOOST_CHECK(cfg.extendedVoteBits == ExtendedVoteBits("1234"));
    BOOST_CHECK_NO_THROW(CallRpc("setautovotervotebitsext 12345678900abcdef0"));
    BOOST_CHECK(cfg.extendedVoteBits == ExtendedVoteBits("12345678900abcdef0"));

    BOOST_CHECK(cfg.voteBits == VoteBits(1U));
    BOOST_CHECK(cfg.extendedVoteBits == ExtendedVoteBits("12345678900abcdef0"));
    BOOST_CHECK_EQUAL(cfg.passphrase, "");

    // Settings (read)

    UniValue r;
    BOOST_CHECK_NO_THROW(r = CallRpc("autovoterconfig"));
    BOOST_CHECK_EQUAL(find_value(r.get_obj(), "autovote").get_bool(), false);
    BOOST_CHECK_EQUAL(find_value(r.get_obj(), "votebits").get_int(), 1);
    BOOST_CHECK_EQUAL(find_value(r.get_obj(), "votebitsext").get_str(), "12345678900abcdef0");

    // Start (with minimal settings)

    BOOST_CHECK_THROW(CallRpc("startautovoter"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc("startautovoter \"\""), std::runtime_error);
    BOOST_CHECK_NO_THROW(CallRpc("startautovoter 65535"));

    BOOST_CHECK_EQUAL(cfg.autoVote, true);
    BOOST_CHECK(cfg.voteBits == VoteBits(65535U));
    BOOST_CHECK(cfg.extendedVoteBits == extendedVoteBitsData.empty);
    BOOST_CHECK_EQUAL(cfg.passphrase, "");

    // Start (with full settings)

    av->stop();

    BOOST_CHECK_EQUAL(cfg.autoVote, false);

    BOOST_CHECK_NO_THROW(CallRpc("startautovoter 1234 123456789abcdef0"));

    BOOST_CHECK_EQUAL(cfg.autoVote, true);
    BOOST_CHECK(cfg.voteBits == VoteBits(1234U));
    BOOST_CHECK(cfg.extendedVoteBits == ExtendedVoteBits("123456789abcdef0"));
    BOOST_CHECK_EQUAL(cfg.passphrase, "");

    // Stop

    BOOST_CHECK_NO_THROW(CallRpc("stopautovoter"));

    BOOST_CHECK_EQUAL(cfg.autoVote, false);

    // Start with passphrase

    wallet->EncryptWallet(passphrase);
    BOOST_CHECK(wallet->IsLocked());

    BOOST_CHECK_THROW(CallRpc("startautovoter 1234 123456789abcdef0"), std::runtime_error);
    BOOST_CHECK_THROW(CallRpc("startautovoter 1234 123456789abcdef0 wrongP4ssword!"), std::runtime_error);

    BOOST_CHECK_NO_THROW(CallRpc(std::string("startautovoter 1 123456789abcdef0 ") + std::string(passphrase.c_str())));

    BOOST_CHECK_EQUAL(cfg.autoVote, true);
    BOOST_CHECK(cfg.voteBits == VoteBits(1U));
    BOOST_CHECK(cfg.extendedVoteBits == ExtendedVoteBits("123456789abcdef0"));
    BOOST_CHECK_EQUAL(cfg.passphrase, passphrase);

    av->stop();

    BOOST_CHECK_EQUAL(cfg.autoVote, false);

    BOOST_CHECK_NO_THROW(CallRpc(std::string("startautovoter 1  ") + std::string(passphrase.c_str())));

    BOOST_CHECK_EQUAL(cfg.autoVote, true);
    BOOST_CHECK(cfg.voteBits == VoteBits(1U));
    BOOST_CHECK(cfg.extendedVoteBits == extendedVoteBitsData.empty);
    BOOST_CHECK_EQUAL(cfg.passphrase, passphrase);

    av->stop();

    vpwallets.erase(std::remove(vpwallets.begin(), vpwallets.end(), wallet.get()), vpwallets.end());
}

BOOST_AUTO_TEST_SUITE_END()

max_stars_repo_name: paicoin/paicoin

max_issues_repo_name: paicoin/paicoin

max_forks_repo_name: paicoin/paicoin


text:
/*
 * GUI container gadget header
 *
 * This file is part of the "SoftPixel Engine" (Copyright (c) 2008 by Lukas Hermanns)
 * See "SoftPixelEngine.hpp" for license information.
 */

#ifndef __SP_GUI_CONTAINERGADGET_H__
#define __SP_GUI_CONTAINERGADGET_H__

#include "Base/spStandard.hpp"

#ifdef SP_COMPILE_WITH_GUI

#include "GUI/spGUIGadget.hpp"

#include <boost/function.hpp>

namespace sp
{
namespace gui
{

typedef boost::function<void (GUIController* Controller)> GUIOwnerDrawCallback;

/**
Container controller gadget.
\ingroup group_gui
*/
class SP_EXPORT GUIContainerGadget : public GUIGadget
{

    public:

        GUIContainerGadget();
        ~GUIContainerGadget();

        bool update();
        void draw();

        /* Inline functions */

        inline void setOwnerDrawCallback(const GUIOwnerDrawCallback &Callback)
        {
            OwnerDrawProc_ = Callback;
        }

    private:

        /* Members */

        GUIOwnerDrawCallback OwnerDrawProc_;

};

} // /namespace gui

} // /namespace sp

#endif

#endif

// ================================================================================

max_stars_repo_name: rontrek/softpixel

max_issues_repo_name: rontrek/softpixel

max_forks_repo_name: rontrek/softpixel


text: #include <boost/spirit/include/classic_optional.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino