text:
#include "Tests_pcp.h"

#include <Eigen/Dense>

#include "Model_T3D_ME_s.h"
#include "QtApp_Prep_T3D_ME_s.h"

#include "test_model_view.h"

void test_RigidTetrahedronMesh_display(int argc, char** argv)
{
	Model_T3D_ME_s model;

	// load mesh
	model.load_mesh_from_hdf5("../../Asset/brick_mesh_1.00_1x1x1.h5");
	model.init_search_grid(0.05, 0.05, 0.05);

	// init rigid tetrahedron mesh
	model.init_rb(1.0, "../../Asset/brick_mesh_1.00_1x1x1.h5", 0.0, 0.0, 1.0, 0.7854);
	model.set_contact_params(100.0, 0.0, 0.0);

	RigidTetrahedronMesh& rb = model.get_rb();

	Point3D cen = rb.get_centre();
	std::cout << "centre: " << cen.x << ", " << cen.y << ", " << cen.z << "\n";

	RigidTetrahedronMesh::Face* bfaces = rb.get_bfaces();
	size_t bface_num = rb.get_bface_num();
	std::cout << "faces: " << bface_num << "\n";
	for (size_t f_id = 0; f_id < bface_num; ++f_id)
	{
		RigidTetrahedronMesh::Face& f = bfaces[f_id];
		std::cout << f.n1 << ", " << f.n2 << ", " << f.n3 << "\n";
	}

	rb.init_bg_grids(0.5, 0.3);

	Cube rb_bbox;
	rb.get_cur_bbox(rb_bbox);
	std::cout << "bbox: " << rb_bbox.xl << ", " << rb_bbox.xu
				  << ", " << rb_bbox.yl << ", " << rb_bbox.yu
				  << ", " << rb_bbox.zl << ", " << rb_bbox.zu << "\n";

	// generate particles
	ParticleGenerator3D<Model_T3D_ME_s> pcl_gen;
	pcl_gen.generate_pcls_second_order_gauss(model);
	model.init_pcls(pcl_gen, 10.0);

	QtApp_Prep_T3D_ME_s view_app(argc, argv);
	view_app.set_win_size(950, 950);
	view_app.set_view_dir(0.0, 0.0);
	view_app.set_view_dist_scale(2.0f);
	view_app.set_light_dir(20.0, 20.0);
	view_app.set_rb_display_mode(QtRigidTetrahedronMeshGLObject::DisplayMode::LineFrame);
	view_app.set_model(model);
	view_app.start();
}

void test_RigidTetrahedronMesh_moi(int argc, char** argv)
{
	double rb_m;
	typedef Eigen::Matrix<double, 3, 3> Matrix3x3;

	//RigidTetrahedronMesh rb1;
	//rb1.init_mesh("../../Asset/teh_mesh.h5", 0.0, 0.0, 0.0, 0.0, 0.0 ,0.0);
	//rb_m = rb1.get_m();
	//const Matrix3x3& rb_mat1 = rb1.get_moi();
	//std::cout << "m: " << rb_m << "\nmoi:\n" << rb_mat1 << "\n\n";

	//RigidTetrahedronMesh rb2;
	//rb2.init_mesh("../../Asset/brick_mesh_1.00_1x1x1.h5", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
	//rb_m = rb2.get_m();
	//const Matrix3x3& rb_mat2 = rb2.get_moi();
	//std::cout << "m: " << rb_m << "\nmoi:\n" << rb_mat2 << "\n\n";

	RigidTetrahedronMesh rb3;
	rb3.init_mesh("../../Asset/brick_mesh_1.00_2x2x10.h5", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
	rb_m = rb3.get_m();
	const Matrix3x3& rb_mat3 = rb3.get_moi();
	std::cout << "m: " << rb_m << "\nmoi:\n" << rb_mat3 << "\n\n";

	RigidTetrahedronMesh rb4;
	rb4.init_mesh("../../Asset/ball_mesh_r1.00.h5", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
	rb_m = rb4.get_m();
	const Matrix3x3& rb_mat4 = rb4.get_moi();
	std::cout << "m: " << rb_m << "\nmoi:\n" << rb_mat4 << "\n\n";
}


text:
#include "cv_utils/IntegralHistogram-Inl.h"

#include <gtest/gtest.h>
#include <boost/scoped_ptr.hpp>

using namespace cv;
using namespace boost;

namespace cv_utils {

class IntegralHistTest : public ::testing::Test {
protected:
  Mat_<double> image;

  virtual void SetUp() {
    image = Mat_<double>::zeros(3,4);
    image(2,0) = 4.0;
    image(0,0) = 3.0;
    image(1,3) = 1.0;
    image(0,1) = 3.0;
  }
};

TEST_F(IntegralHistTest, BasicTest) {
  scoped_ptr<IntegralHistogram<double> > hist(
    IntegralHistogram<double>::Calculate(image, 5));

  EXPECT_EQ((*hist)(0,0,0), 0);
  EXPECT_EQ((*hist)(1,1,0), 0);
  EXPECT_EQ((*hist)(3,4,0), 8);
  EXPECT_EQ((*hist)(3,4,1), 1);
  EXPECT_EQ((*hist)(3,4,2), 0);
  EXPECT_EQ((*hist)(3,4,3), 2);
  EXPECT_EQ((*hist)(3,4,4), 1);
  EXPECT_EQ((*hist)(1,2,3), 2);
  EXPECT_EQ((*hist)(1,4,0), 2);
  hist.reset(NULL);
}

TEST_F(IntegralHistTest, GetArrayHistTest) {
  scoped_ptr<IntegralHistogram<double> > hist(
    IntegralHistogram<double>::Calculate(image, 5));
  const cv::Mat_<double> pixHist = hist->GetArrayHist(3,4);
  EXPECT_EQ(pixHist(0), 8);
  EXPECT_EQ(pixHist(1), 1);
  EXPECT_EQ(pixHist(2), 0);
  EXPECT_EQ(pixHist(3), 2);
  EXPECT_EQ(pixHist(4), 1);
}

TEST_F(IntegralHistTest, GetArrayHistPointTest) {
  scoped_ptr<IntegralHistogram<double> > hist(
    IntegralHistogram<double>::Calculate(image, 5));
  const cv::Mat_<double> pixHist = hist->GetArrayHist(Point(4,3));
  EXPECT_EQ(pixHist(0), 8);
  EXPECT_EQ(pixHist(1), 1);
  EXPECT_EQ(pixHist(2), 0);
  EXPECT_EQ(pixHist(3), 2);
  EXPECT_EQ(pixHist(4), 1);
}

TEST_F(IntegralHistTest, GetHistInRegionTest) {
  scoped_ptr<IntegralHistogram<double> > hist(
    IntegralHistogram<double>::Calculate(image, 5));
  const cv::Mat_<double> pixHist = hist->GetHistInRegion(Rect(0, 1, 4, 2));
  EXPECT_EQ(pixHist(0), 6);
  EXPECT_EQ(pixHist(1), 1);
  EXPECT_EQ(pixHist(2), 0);
  EXPECT_EQ(pixHist(3), 0);
  EXPECT_EQ(pixHist(4), 1);
}

TEST_F(IntegralHistTest, WeightedEntryTest) {
  Mat_<double> weights = Mat_<double>::ones(3,4)*3;
  weights(1,3) = 7;
  scoped_ptr<IntegralHistogram<double> > hist(
    IntegralHistogram<double>::Calculate<double>(image,
                                                 5,
                                                 NULL,
                                                 weights));

  const cv::Mat_<double> pixHist = hist->GetArrayHist(3,4);
  EXPECT_EQ(pixHist(0), 24);
  EXPECT_EQ(pixHist(1), 7);
  EXPECT_EQ(pixHist(2), 0);
  EXPECT_EQ(pixHist(3), 6);
  EXPECT_EQ(pixHist(4), 3);
}

TEST_F(IntegralHistTest, LinearInterpTest) {
  image(0,2) = 1.3;

  scoped_ptr<IntegralHistogram<double> > hist(
    IntegralHistogram<double>::Calculate<double>(
      image,
      5,
      NULL,
      Mat_<double>(),
      IntegralHistogram<double>::LINEAR_INTERP));

  const cv::Mat_<double> pixHist = hist->GetArrayHist(3,4);
  EXPECT_FLOAT_EQ(pixHist(0), 7);
  EXPECT_FLOAT_EQ(pixHist(1), 1.7);
  EXPECT_FLOAT_EQ(pixHist(2), 0.3);
  EXPECT_FLOAT_EQ(pixHist(3), 2);
  EXPECT_FLOAT_EQ(pixHist(4), 1);
}

} // namespace

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

ext: cc


text:
//  synchronizaion.hpp  --------------------------------------------------------------//

//  Copyright 2010 Vicente J. Botet Escriba
//  Copyright 2015 Andrey Semashev

//  Distributed under the Boost Software License, Version 1.0.
//  See http://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_DETAIL_WINAPI_SYNCHRONIZATION_HPP
#define BOOST_DETAIL_WINAPI_SYNCHRONIZATION_HPP

#include <boost/detail/winapi/basic_types.hpp>
#include <boost/detail/winapi/critical_section.hpp>
#include <boost/detail/winapi/wait.hpp>
#include <boost/detail/winapi/event.hpp>
#include <boost/detail/winapi/mutex.hpp>
#include <boost/detail/winapi/semaphore.hpp>
#include <boost/detail/winapi/init_once.hpp>
#include <boost/detail/winapi/srw_lock.hpp>
#include <boost/detail/winapi/condition_variable.hpp>
#include <boost/detail/winapi/apc.hpp>

#ifdef BOOST_HAS_PRAGMA_ONCE
#pragma once
#endif

#endif // BOOST_DETAIL_WINAPI_SYNCHRONIZATION_HPP

ext: hpp


text:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * File:   EventServiceModuleManager.cpp
 * Author: ubuntu
 *
 * Created on January 18, 2018, 2:47 PM
 */

#include <boost/dll/alias.hpp>
#include <boost/dll/shared_library.hpp>
#include <boost/shared_ptr.hpp>

#include "keto/event/EventServiceModuleManager.hpp"
#include "keto/event/EventServiceModule.hpp"
#include "keto/common/MetaInfo.hpp"

#include "keto/common/Log.hpp"

namespace keto {
namespace event {

EventServiceModuleManager::EventServiceModuleManager() {
}

EventServiceModuleManager::~EventServiceModuleManager() {
}

// meta methods
const std::string EventServiceModuleManager::getName() const {
    return "EventServiceModuleManager";
}
const std::string EventServiceModuleManager::getDescription() const {
    return "The event service manager for KETO";
}

const std::string EventServiceModuleManager::getVersion() const {
    return keto::common::MetaInfo::VERSION;
}

// lifecycle methods
void EventServiceModuleManager::start() {
    modules[keto::event::EventServiceInterface::KETO_EVENT_SERVICE_MODULE] =
            std::make_shared<EventServiceModule>();
    KETO_LOG_INFO << "[EventService] The event service has been started";

}

void EventServiceModuleManager::stop() {
    modules.clear();
    KETO_LOG_INFO << "[EventService] The event service is being stopped";
}

const std::vector<std::string> EventServiceModuleManager::listModules() {
    std::vector<std::string> keys;
    std::transform(
        this->modules.begin(),
        this->modules.end(),
        std::back_inserter(keys),
        [](const std::map<std::string,std::shared_ptr<keto::module::ModuleInterface>>::value_type
            &pair){return pair.first;});
    return keys;
}

const std::shared_ptr<keto::module::ModuleInterface>
    EventServiceModuleManager::getModule(const std::string& name) {
    return modules[name];
}

boost::shared_ptr<EventServiceModuleManager> EventServiceModuleManager::create_module() {
    return boost::shared_ptr<EventServiceModuleManager>(new EventServiceModuleManager());
}

BOOST_DLL_ALIAS(
    keto::event::EventServiceModuleManager::create_module,
    create_module
)

}
}

ext: cpp

max_stars_repo_name: burntjam/keto

max_issues_repo_name: burntjam/keto

max_forks_repo_name: burntjam/keto


text:
#include <boost/test/unit_test.hpp>
#include "Hypercube.hpp"

BOOST_AUTO_TEST_SUITE( Hypercube_tests );

BOOST_AUTO_TEST_CASE( test3d_1i ) {
  BOOST_MESSAGE("Testing 3d, 1 iter");

  Hypercube hg( {3,3,3} );

  HypercubeSlice& h = hg.slice({HypercubeSlice::ALL, 0, 0});
  int64_t ii = 0;
  for (auto i : h) {
    BOOST_MESSAGE(i << " " << ii);
    BOOST_CHECK(i == ii);
    ii++;
  }
}

BOOST_AUTO_TEST_CASE( test3d_2i ) {
  BOOST_MESSAGE("Testing 3d, 2 iter x y");

  Hypercube hg({3,3,3});

  HypercubeSlice& h = hg.slice({HypercubeSlice::ALL, HypercubeSlice::ALL, 1});
  int64_t ii = 9;
  for (auto i : h) {
    BOOST_MESSAGE(i << " " << ii);
    BOOST_CHECK(i == ii);
    ii++;
  }
}

BOOST_AUTO_TEST_CASE( test3d_2i_apart ) {
  BOOST_MESSAGE("Testing 3d, 2 iter x z");

  std::vector<int64_t> shares {3,3,3};
  Hypercube hg(shares);

  HypercubeSlice& h = hg.slice({HypercubeSlice::ALL, 1, HypercubeSlice::ALL});
  int64_t ii = 0;

  int64_t expected[9] = {3,4,5,
                         12,13,14,
                         21,22,23};

  for (auto i : h) {
    BOOST_MESSAGE(i << " " << expected[ii]);
    BOOST_CHECK(expected[ii] == i);
    ii++;
  }
}

BOOST_AUTO_TEST_CASE( test4d ) {
  BOOST_MESSAGE("Testing 4d");

  std::vector<int64_t> shares {2,2,2,2};
  Hypercube hg(shares);

  HypercubeSlice& h = hg.slice({0,0,HypercubeSlice::ALL, HypercubeSlice::ALL});
  int64_t ii = 0;

  int64_t expected[4] = {0, 4, 8, 12};

  for (auto i : h) {
    BOOST_MESSAGE(i << " " << expected[ii]);
    BOOST_CHECK(expected[ii] == i);
    ii++;

    BOOST_CHECK(ii < 5);
  }
}

BOOST_AUTO_TEST_SUITE_END();

max_stars_repo_name: EvilMcJerkface/grappa

max_issues_repo_name: EvilMcJerkface/grappa

max_forks_repo_name: EvilMcJerkface/grappa


text:
/*
 * Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
 */

#include <algorithm>
#include <boost/uuid/uuid_io.hpp>
#include <base/parse_object.h>
#include <ifmap/ifmap_link.h>
#include <ifmap/ifmap_table.h>
#include <vnc_cfg_types.h>

#include <cmn/agent_cmn.h>
#include <cfg/cfg_init.h>
#include <oper/config_manager.h>
#include <oper/multicast_policy.h>

#include <oper/agent_sandesh.h>

using namespace autogen;
using namespace std;

SandeshTraceBufferPtr
    MulticastPolicyTraceBuf(SandeshTraceBufferCreate("MulticastPolicy", 5000));

MulticastPolicyTable *MulticastPolicyTable::mp_table_;

bool MulticastPolicyEntry::IsLess(const DBEntry &rhs) const {
    const MulticastPolicyEntry &a =
                            static_cast<const MulticastPolicyEntry &>(rhs);
    return (mp_uuid_ < a.mp_uuid_);
}

string MulticastPolicyEntry::ToString() const {
    std::stringstream uuidstring;
    uuidstring << mp_uuid_;
    return uuidstring.str();
}

DBEntryBase::KeyPtr MulticastPolicyEntry::GetDBRequestKey() const {
    MulticastPolicyKey *key = new MulticastPolicyKey(mp_uuid_);
    return DBEntryBase::KeyPtr(key);
}

void MulticastPolicyEntry::SetKey(const DBRequestKey *key) {
    const MulticastPolicyKey *k = static_cast<const MulticastPolicyKey *>(key);
    mp_uuid_ = k->mp_uuid_;
}

SourceGroupInfo::Action MulticastPolicyEntry::GetAction(IpAddress source,
                                    IpAddress group) const {

    std::vector<SourceGroupInfo>::const_iterator it = mcast_sg_.begin();
    while (it != mcast_sg_.end()) {
        if ((it->source == source) && (it->group == group)) {
            return it->action;
        }
        it++;
    }

    return SourceGroupInfo::ACTION_DENY;
}

std::auto_ptr<DBEntry> MulticastPolicyTable::AllocEntry(const DBRequestKey *k)
                                    const {

    const MulticastPolicyKey *key = static_cast<const MulticastPolicyKey *>(k);
    MulticastPolicyEntry *mp = new MulticastPolicyEntry(key->mp_uuid_);
    return std::auto_ptr<DBEntry>(static_cast<DBEntry *>(mp));
}

DBEntry *MulticastPolicyTable::OperDBAdd(const DBRequest *req) {
    MulticastPolicyKey *key = static_cast<MulticastPolicyKey *>(req->key.get());
    MulticastPolicyEntry *mp = new MulticastPolicyEntry(key->mp_uuid_);
    ChangeHandler(mp, req);
    return mp;
}

bool MulticastPolicyTable::OperDBOnChange(DBEntry *entry,
                                    const DBRequest *req) {

    MulticastPolicyEntry *mp = static_cast<MulticastPolicyEntry *>(entry);
    bool ret = ChangeHandler(mp, req);
    return ret;
}

bool MulticastPolicyTable::OperDBDelete(DBEntry *entry, const DBRequest *req) {
    std::vector<SourceGroupInfo> mcast_sg;
    MulticastPolicyEntry *mp = static_cast<MulticastPolicyEntry *>(entry);
    mp->set_mcast_sg(mcast_sg);
    return true;
}

bool MulticastPolicyTable::IsEqual(
                const std::vector<SourceGroupInfo> &lhs,
                const std::vector<SourceGroupInfo> &rhs) const {

    if (lhs.size() != rhs.size()) {
        return false;
    }

    vector<SourceGroupInfo>::const_iterator lit = lhs.begin();
    vector<SourceGroupInfo>::const_iterator rit = rhs.begin();
    while (lit != lhs.end() && rit != rhs.end()) {
        if ((lit->source != rit->source) ||
            (lit->group != rit->group) ||
            (lit->action != rit->action)) {
            return false;
        }
        ++lit;
        ++rit;
    }
    return true;
}

bool MulticastPolicyTable::ChangeHandler(DBEntry *entry, const DBRequest *req) {
    bool ret = false;
    MulticastPolicyEntry *mp = static_cast<MulticastPolicyEntry *>(entry);
    MulticastPolicyData *data = static_cast<MulticastPolicyData *>(req->data.get());

    if (!IsEqual(mp->mcast_sg(), data->mcast_sg_)) {
        mp->set_mcast_sg(data->mcast_sg_);
        ret = true;
    }

    if (mp->name() != data->name_) {
        mp->set_name(data->name_);
        ret = true;
    }

    return ret;
}

DBTableBase *MulticastPolicyTable::CreateTable(DB *db,
                                    const std::string &name) {
    mp_table_ = new MulticastPolicyTable(db, name);
    mp_table_->Init();
    return mp_table_;
};

bool MulticastPolicyTable::IFNodeToUuid(IFMapNode *node,
                                    boost::uuids::uuid &u) {
    MulticastPolicy *cfg = static_cast<MulticastPolicy *>(node->GetObject());
    assert(cfg);
    autogen::IdPermsType id_perms = cfg->id_perms();
    CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong, u);
    return true;
}

bool MulticastPolicyTable::IFNodeToReq(IFMapNode *node, DBRequest &req,
                                    const boost::uuids::uuid &u) {
    MulticastPolicy *cfg = static_cast<MulticastPolicy *>(node->GetObject());
    assert(cfg);

    assert(!u.is_nil());

    if ((req.oper == DBRequest::DB_ENTRY_DELETE) || node->IsDeleted()) {
        req.oper = DBRequest::DB_ENTRY_DELETE;
        req.key.reset(new MulticastPolicyKey(u));
        agent()->mp_table()->Enqueue(&req);
        return false;
    }

    agent()->config_manager()->AddMulticastPolicyNode(node);
    return false;
}

bool MulticastPolicyTable::ProcessConfig(IFMapNode *node, DBRequest &req,
                                    const boost::uuids::uuid &u) {

    if (node->IsDeleted())
        return false;

    MulticastPolicy *cfg = static_cast<MulticastPolicy *>(node->GetObject());
    assert(cfg);

    req.oper = DBRequest::DB_ENTRY_ADD_CHANGE;

    autogen::MulticastPolicy *data =
                    static_cast<autogen::MulticastPolicy *>(node->GetObject());

    autogen::IdPermsType id_perms = data->id_perms();

    std::vector<autogen::MulticastSourceGroup> cfg_sg_list =
                                    data->multicast_source_groups();
    std::vector<autogen::MulticastSourceGroup>::const_iterator it =
                                    cfg_sg_list.begin();

    std::vector<SourceGroupInfo> sg_list;
    SourceGroupInfo sg;
    boost::system::error_code ec;
    while (it != cfg_sg_list.end()) {
        sg.source = IpAddress::from_string(it->source_address, ec);
        sg.group = IpAddress::from_string(it->group_address, ec);
        sg.action = (it->action == "pass") ?
                            SourceGroupInfo::ACTION_PASS :
                            SourceGroupInfo::ACTION_DENY;
        sg_list.push_back(sg);
        it++;
    }

    MulticastPolicyKey *mp_key = new MulticastPolicyKey(u);
    MulticastPolicyData *mp_data =
                new MulticastPolicyData(agent(), node, node->name(), sg_list);

    req.key.reset(mp_key);
    req.data.reset(mp_data);
    agent()->mp_table()->Enqueue(&req);
    return false;
}

bool MulticastPolicyEntry::DBEntrySandesh(Sandesh *sresp,
                                    std::string &name) const {

    MulticastPolicyResp *resp = static_cast<MulticastPolicyResp *>(sresp);
    std::string str_uuid = UuidToString(GetMpUuid());

    MulticastPolicySandeshData data;
    std::vector<MulticastPolicyEntrySandeshData> entries;
    std::vector<SourceGroupInfo>::const_iterator it =
                mcast_sg_.begin();
    uint32_t id = 0;
    while (it != mcast_sg_.end()) {
        MulticastPolicyEntrySandeshData entry;
        entry.set_entry_id(id);
        entry.set_source_address(it->source.to_string());
        entry.set_group_address(it->group.to_string());
        entry.set_action((it->action == SourceGroupInfo::ACTION_PASS) ?
                                    "pass" : "deny");
        entries.push_back(entry);
        it++;
    }
    data.set_entries(entries);

    std::vector<MulticastPolicySandeshData> &list =
                const_cast<std::vector<MulticastPolicySandeshData>&>
                                    (resp->get_mp_list());
    list.push_back(data);

    return true;
}

void MulticastPolicyReq::HandleRequest() const {
    AgentSandeshPtr sand(new AgentMulticastPolicySandesh(context(),
                                    get_uuid()));
    sand->DoSandesh(sand);
}

AgentSandeshPtr MulticastPolicyTable::GetAgentSandesh(
                                    const AgentSandeshArguments *args,
                                    const std::string &context) {

    return AgentSandeshPtr(new AgentMulticastPolicySandesh(context,
                                    args->GetString("uuid")));
}

max_stars_repo_name: jnpr-pranav/contrail-controller

max_issues_repo_name: jnpr-pranav/contrail-controller

max_forks_repo_name: jnpr-pranav/contrail-controller


text:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright 2012 The MITRE Corporation                                      *
 *                                                                           *
 * 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 <opencv2/imgproc/imgproc.hpp>
#include <Eigen/Dense>

#include <openbr/plugins/openbr_internal.h>
#include <openbr/core/opencvutils.h>

using namespace cv;

namespace br
{

/*!
 * \ingroup transforms
 * \brief Creates a Delaunay triangulation based on a set of points
 * \author Scott Klum \cite sklum
 */
class DelaunayTransform : public UntrainableTransform
{
    Q_OBJECT

    Q_PROPERTY(float scaleFactor READ get_scaleFactor WRITE set_scaleFactor RESET reset_scaleFactor STORED false)
    Q_PROPERTY(bool warp READ get_warp WRITE set_warp RESET reset_warp STORED false)
    BR_PROPERTY(float, scaleFactor, 1)
    BR_PROPERTY(bool, warp, true)

    void project(const Template &src, Template &dst) const
    {
        QList<QPointF> points = src.file.points();
        QList<QRectF> rects = src.file.rects();

        if (points.empty() || rects.empty()) {
            dst = src;
            if (Globals->verbose) qWarning("Delauney triangulation failed because points or rects are empty.");
            return;
        }

        int cols = src.m().cols;
        int rows = src.m().rows;

        // Assume rect appended last was bounding box
        points.append(rects.last().topLeft());
        points.append(rects.last().topRight());
        points.append(rects.last().bottomLeft());
        points.append(rects.last().bottomRight());

        Subdiv2D subdiv(Rect(0,0,cols,rows));
        // Make sure points are valid for Subdiv2D
        // TODO: Modify points to make them valid
        for (int i = 0; i < points.size(); i++) {
            if (points[i].x() < 0 || points[i].y() < 0 || points[i].y() >= rows || points[i].x() >= cols) {
                dst = src;
                if (Globals->verbose) qWarning("Delauney triangulation failed because points lie on boundary.");
                return;
            }
            subdiv.insert(OpenCVUtils::toPoint(points[i]));
        }

        std::vector<Vec6f> triangleList;
        subdiv.getTriangleList(triangleList);

        QList<QPointF> validTriangles;

        for (size_t i = 0; i < triangleList.size(); i++) {
            // Check the triangle to make sure it's falls within the matrix
            bool valid = true;

            QList<QPointF> vertices;
            vertices.append(QPointF(triangleList[i][0],triangleList[i][1]));
            vertices.append(QPointF(triangleList[i][2],triangleList[i][3]));
            vertices.append(QPointF(triangleList[i][4],triangleList[i][5]));
            for (int j = 0; j < 3; j++) if (vertices[j].x() > cols || vertices[j].y() > rows || vertices[j].x() < 0 || vertices[j].y() < 0) valid = false;

            if (valid) validTriangles.append(vertices);
        }

        if (warp) {
            dst.m() = Mat::zeros(rows,cols,src.m().type());

            QList<float> procrustesStats = src.file.getList<float>("ProcrustesStats");

            Eigen::MatrixXf R(2,2);
            R(0,0) = procrustesStats.at(0);
            R(1,0) = procrustesStats.at(1);
            R(1,1) = procrustesStats.at(2);
            R(0,1) = procrustesStats.at(3);

            cv::Scalar mean(2);
            mean[0] = procrustesStats.at(4);
            mean[1] = procrustesStats.at(5);

            float norm = procrustesStats.at(6);

            QList<Point2f> mappedPoints;

            for (int i = 0; i < validTriangles.size(); i+=3) {
                // Matrix to store original (pre-transformed) triangle vertices
                Eigen::MatrixXf srcMat(3, 2);

                for (int j = 0; j < 3; j++) {
                    srcMat(j,0) = (validTriangles[i+j].x()-mean[0])/norm;
                    srcMat(j,1) = (validTriangles[i+j].y()-mean[1])/norm;
                }

                Eigen::MatrixXf dstMat = srcMat*R;

                Point2f srcPoints[3];
                for (int j = 0; j < 3; j++) srcPoints[j] = OpenCVUtils::toPoint(validTriangles[i+j]);

                Point2f dstPoints[3];
                for (int j = 0; j < 3; j++) {
                    // Scale and shift destination points
                    Point2f warpedPoint = Point2f(dstMat(j,0)*scaleFactor+cols/2,dstMat(j,1)*scaleFactor+rows/2);
                    dstPoints[j] = warpedPoint;
                    mappedPoints.append(warpedPoint);
                }

                Mat buffer(rows,cols,src.m().type());

                warpAffine(src.m(), buffer, getAffineTransform(srcPoints, dstPoints), Size(cols,rows));

                Mat mask = Mat::zeros(rows, cols, CV_8UC1);
                Point maskPoints[1][3];
                maskPoints[0][0] = dstPoints[0];
                maskPoints[0][1] = dstPoints[1];
                maskPoints[0][2] = dstPoints[2];
                const Point* ppt = { maskPoints[0] };

                fillConvexPoly(mask, ppt, 3, Scalar(255,255,255), 8);

                Mat output(rows,cols,src.m().type());

                if (i > 0) {
                    Mat overlap;
                    bitwise_and(dst.m(),mask,overlap);
                    mask.setTo(0, overlap!=0);
                }

                bitwise_and(buffer,mask,output);

                dst.m() += output;
            }

            // Overwrite any rects
            Rect boundingBox = boundingRect(mappedPoints.toVector().toStdVector());
            dst.file.setRects(QList<QRectF>() << OpenCVUtils::fromRect(boundingBox));
        } else dst = src;

        dst.file.setList<QPointF>("DelaunayTriangles", validTriangles);
    }
};

BR_REGISTER(Transform, DelaunayTransform)

} // namespace br

#include "metadata/delaunay.moc"

max_stars_repo_name: gaatyin/openbr

max_issues_repo_name: William-New/openbr

max_forks_repo_name: William-New/openbr


text: #include <boost/asio/ip/unicast.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
#ifndef LOAD_PARAMS_H
#define LOAD_PARAMS_H

#include <iostream>
#include <string>
#include <typeinfo>
#include <boost/foreach.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/ptree.hpp>

class LoadParams
{
private:

    bool find_param_name;

    void set_param(const std::string param_string, bool &param);

    //未実装
    //void set_param(const std::string param_string, short int &param);
    //未実装
    //void set_param(const std::string param_string, unsigned short int &param);
    void set_param(const std::string param_string, int &param);
    //未実装
    //void set_param(const std::string param_string, unsigned int &param);
    void set_param(const std::string param_string, long int &param);
    void set_param(const std::string param_string, unsigned long int &param);
    void set_param(const std::string param_string, long long int &param);
    void set_param(const std::string param_string, unsigned long long int &param);

    //未実装
    //void set_param(const std::string param_string, char &param);
    //未実装
    //void set_param(const std::string param_string, signed char &param);
    //未実装
    //void set_param(const std::string param_string, unsigned char &param);

    void set_param(const std::string param_string, float &param);
    void set_param(const std::string param_string, double &param);
    void set_param(const std::string param_string, long double &param);

    void set_param(const std::string param_string, std::string &param);

    template<typename Param>
    void set_param(std::string param_string, Param &param);

public:

    LoadParams();
    ~LoadParams();

    template<typename Param>
    void get_param(std::string id, Param &param);
};

inline LoadParams::LoadParams():
    find_param_name (false)
{}

inline LoadParams::~LoadParams()
{}

inline void LoadParams::set_param(const std::string param_string, bool &param)
{
    if(param_string == "1" || param_string == "true")
    {
        param = true;
    }
    else if(param_string == "0" || param_string == "false")
    {
        param = false;
    }
    else
    {
        std::cout << "[ERROR]: " << "param is typed as 'bool'. But param's type is not bool" << "\n"
                  << "Check the xml file" << std::endl;
        exit(0);
    }
}

inline void LoadParams::set_param(const std::string param_string, int &param)
{
    param = std::stoi(param_string);
}

inline void LoadParams::set_param(const std::string param_string, unsigned long int &param)
{
    param = std::stoul(param_string);
}

inline void LoadParams::set_param(const std::string param_string, unsigned long long int &param)
{
    param = std::stoull(param_string);
}

inline void LoadParams::set_param(const std::string param_string, float &param)
{
    param = std::stof(param_string);
}

inline void LoadParams::set_param(const std::string param_string, double &param)
{
    param = std::stod(param_string);
}

inline void LoadParams::set_param(const std::string param_string, long double &param)
{
    param = std::stold(param_string);
}

inline void LoadParams::set_param(const std::string param_string, std::string &param)
{
    param = param_string;
}

template<typename Param>
inline void LoadParams::set_param(const std::string param_string, Param &param)
{
    std::cout << "[ERROR]: " << typeid(param).name() << " is not defined in loadParams.hpp" << std::endl;
    exit(0);
}

template<typename Param>
inline void LoadParams::get_param(std::string param_name, Param &param)
{
    using namespace boost::property_tree;

    find_param_name = false;
    ptree pt;

    try
    {
        xml_parser::read_xml("./../launch/setting.xml", pt);
    }
    catch(xml_parser_error& e)
    {
        std::wcout << "[ERROR]: " << e.what() << std::endl;
        std::wcout << "[ERROR]: " << "Check path and filename of xml file" << std::endl;
        exit(0);
    }

    BOOST_FOREACH(ptree::value_type &v, pt.get_child("data"))
    {
        std::string name = v.second.get_child("<xmlattr>.name").data();
        if(name == param_name)
        {
            std::string p = v.second.get_child("<xmlattr>.value").data();
            set_param(p, param);
            find_param_name = true;
            break;
        }
    }

    if(!find_param_name)
    {
        std::cout << "[ERROR]: " << "Could not find paramerter name : " << param_name << std::endl;
        exit(0);
    }
}

#endif //LOAD_PARAMS_H


text:
#include "stdafx.h"
#include "JavaModelLib/internal/core/BaseJavaType.h"
#include <JavaModelLib/internal/core/PackageFragment.h>
#include <JavaModelLib/internal/core/BinaryField.h>
#include <JavaModelLib/internal/core/BinaryMethod.h>
#include  <JavaModelLib/internal/core/Initializer.h>
#include  <map>
#include <boost/algorithm/string.hpp>
#include <PathModelLib/MosesPath/MosesPath.h>

namespace Jikes { // Open namespace Jikes block

	namespace JavaModel {
		IType* BaseJavaType::DeepCopyButNoChildren(IJavaElement* parent)
		{
			auto clone = reinterpret_cast<BaseJavaType*>(ShallowCopy(parent));
			if(clone)
				clone->HelpToDeepCopy(*this);
			return clone;
		}

		PathModel::MosesPath* BaseJavaType::getMosesPath()
		{
			if (moses)
				return moses;
			if (!fParent)
				return nullptr;

			if (fParent->fLEType == TYPE)
			{
				auto parent_moses = reinterpret_cast<MemberInFileMoses*>(fParent->getMosesPath());
				if (!parent_moses)
					return nullptr;
				vector<wstring> enclosing_types(parent_moses->enclosing_types);
				enclosing_types.push_back(parent_moses->name);
				moses = new MemberInFileMoses(
					parent_moses->proj,
					parent_moses->root,
					parent_moses->pkg,
					parent_moses->file,
					enclosing_types,
					fName,
					MosesPath::TYPE,isBinary());

			}

			else
			{
				auto parent_moses = reinterpret_cast<FileMoses*> (fParent->getMosesPath());
				if (!parent_moses)
					return nullptr;

				moses = new MemberInFileMoses(parent_moses->proj,
					parent_moses->root,
					parent_moses->pkg,
					parent_moses->file,
					{},
					fName,
					MosesPath::TYPE, isBinary());
			}
			return  moses;

		}
		void BaseJavaType::addChild(IJavaElement* child)
		{

		}

		const vector<IField*> *BaseJavaType::getFields(){
			auto _info = reinterpret_cast<SourceTypeElementInfo*>(getElementInfo());
			if (!_info)
				return nullptr;
			return _info->getFields();
		}

		std::vector<IJavaElement*>* BaseJavaType::getChildrenOfType(
			IJavaElementType _type)
		{
			auto _info = reinterpret_cast<SourceTypeElementInfo*>(getElementInfo());
			if (!_info)
				return nullptr;
			return _info->getChildrenOfType(_type);
		};

		BaseJavaType::BaseJavaType(IJavaElement* parent, const wstring& name) :
			IType(parent, name),
			status(0),
			file_symbol(nullptr), info(nullptr)
		{
		}

		BaseJavaType::BaseJavaType(BaseJavaType& o) : IType(o),
			status(o.status),
			file_symbol(nullptr), info(nullptr)

		{

		}

		IJavaElement* BaseJavaType::DeepCopy(IJavaElement* parent)
		{
			auto clone = reinterpret_cast<BaseJavaType*>(ShallowCopy(parent));
			if(clone)
				clone->HelpToDeepCopy(*this);
			return clone;
		}

		wstring BaseJavaType::getFullName()
		{
			wstring _strType;
			if (IsInterface())
			{
				_strType = L"interface";
			}
			else if (IsEnum())
			{
				_strType = L"enum";
			}
			else if (isClass())
			{
				_strType = L"class";
			}
			else if (IsPrimitiveType())
			{

			}
			else if (IsArrayType())
			{

			}
			wstring ret;
			auto modifiStr = getModifersString();
			if (!modifiStr.empty())
				ret = +L" ";

			ret+= _strType + L" " + fName + L" in ";

			getElementInfo();
			ret += boost::join(info->qualifiedTypeNames, wstring(1, '.'));
			return ret;
		}

		bool BaseJavaType::hasChildren(){
			auto _info = reinterpret_cast<SourceTypeElementInfo*>(getElementInfo());
			if (!_info)
				return false;
			return  info->all_children.size();
		}

		std::vector<IJavaElement*>* BaseJavaType::getChildren()
		{
			auto _info = reinterpret_cast<SourceTypeElementInfo*>(getElementInfo());
			if (!_info)
				return nullptr;

			return _info->getChildren();
		}

		BaseJavaType::~BaseJavaType()
		{
			if (info){
				delete info;
			}
		}

		void  BaseJavaType::SortOutLineNameIdentity()
		{
			auto _info = reinterpret_cast<SourceTypeElementInfo*>(getElementInfo());
			if (_info)
				_info->SortOutLineNameIdentity();
		}

		void BaseJavaType::GetIndendentInfoAndSepareteFromParent()
		{
			Member::GetIndendentInfoAndSepareteFromParent();
			file_symbol = false;
		}
		void BaseJavaType::HelpToDeepCopy(BaseJavaType& o)
		{
		    if(o.info) {
				delete info;
				info = new SourceTypeElementInfo();
				info->HelpToDeepCopy(*(o.info), this);
		    }
		}

		void BaseJavaType::HelpToDeepCopyButNoChildren(BaseJavaType& o)
		{
			if (o.info) {
				delete info;
				info = new SourceTypeElementInfo();
				info->HelpToDeepCopyButNoChildren(*(o.info), this);
			}
		}

		IInitializer* BaseJavaType::getInitializer(int start_pos){
			auto _info = reinterpret_cast<SourceTypeElementInfo*>(getElementInfo());

			if (!_info)
				return nullptr;

			return _info->getInitializer(start_pos);
		}

		std::wstring BaseJavaType::getJavaCardDocUrlFragment(){
			auto _info = reinterpret_cast<SourceTypeElementInfo*>(getElementInfo());
			if (!_info)
				return{};
			wstring ret;
			ret = boost::join(_info->qualifiedTypeNames, wstring(1, '/')) + L"/" + fName + L".html";
			return ret;
		}

		const std::vector<IType*>* BaseJavaType::getTypes() {
			auto _info = reinterpret_cast<SourceTypeElementInfo*>(getElementInfo());
			if (!_info)
				return nullptr;
			return _info->getTypes();
		}

		IMethod* BaseJavaType::getMethod(const wstring& name,
			const vector<wstring>& parameterTypes)
		{
			auto _info = reinterpret_cast<SourceTypeElementInfo*>(getElementInfo());

			if (!_info)
				return nullptr;

			return _info->getMethod(name, parameterTypes);

		}

		IField* BaseJavaType::getField(const wstring& name)
		{
			auto _info = reinterpret_cast<SourceTypeElementInfo*>(getElementInfo());

			if (!_info)
				return nullptr;

			return _info->getField(name);
		}

		const vector<IMethod*>* BaseJavaType::getMethods() {

			auto _info = reinterpret_cast<SourceTypeElementInfo*>(getElementInfo());

			if (!_info)
				return nullptr;

			return _info->getMethods();
		}

		IType* BaseJavaType::getType(const wstring& name)
		{
			auto _info = reinterpret_cast<SourceTypeElementInfo*>(getElementInfo());

			if (!_info)
				return nullptr;

			return _info->getType(name);

		};

	} // Close namespace JavaModel block

} // Close namespace Jikes block

max_stars_repo_name: kuafuwang/JCDT

max_issues_repo_name: kuafuwang/JCDT

max_forks_repo_name: kuafuwang/JCDT


text:
/**
 *  @file
 *  @copyright defined in eos/LICENSE.txt
 */

#include <iostream>
#include <iomanip>
#include <limits>
#include <random>

#include <boost/program_options.hpp>

namespace po = boost::program_options;

int main(int argc, const char **argv) {

   unsigned int seed = std::mt19937::default_seed;

   unsigned int num_cases = 10;

   po::options_description desc("Options");
   desc.add_options()
      ("help,h", "Print this help message and exit")
      ("seed,s", po::value<unsigned int>(&seed)->default_value(seed), "random seed")
      ("num-cases,n", po::value<unsigned int>(&num_cases)->default_value(num_cases), "number of test cases to generate" )
      ("avoid-specials", po::bool_switch()->default_value(false), "Avoid printing test cases for special values of double" )
   ;

   po::variables_map vm;
   po::store(po::parse_command_line(argc, argv, desc), vm);
   po::notify(vm);

   if( vm.count("help") ) {
      std::cout << desc << std::endl;
      return 1;
   }

   std::cout << "Seed: " << seed << std::endl;
   std::mt19937 gen(seed);

   double lbound = std::numeric_limits<double>::lowest();
   double ubound = std::numeric_limits<double>::max();

   std::uniform_int_distribution<uint64_t> dis(0, std::numeric_limits<uint64_t>::max());

   std::cout.precision(std::numeric_limits<double>::digits10 + 1);

   auto print_triplet = [&]( double d, int left_padding = 0 ) {
      std::cout << std::setw(left_padding) << "";
      std::cout << "[\"0x" << std::hex << *(uint64_t*)(&d) << "\", \""
                << std::hexfloat << d << "\", \"" << std::fixed << d << "\"]";
   };

   if( num_cases > 0 ) {
      std::cout << std::endl;
      std::cout <<    "Randomly generated double test cases (raw hex dump, hexidecimal float, decimal fixed) "
                      "within the interval [" << std::fixed << lbound << ", " << ubound << "]:" << std::endl
                <<    " [" << std::endl;
      for( int n = 1, end = num_cases; n <= end; )
      {

         uint64_t x = dis(gen);
         double v = *(double*)(&x);

         if( !(lbound <= v && v <= ubound) ) continue;

         print_triplet(v, 2);
         if( n != end )
            std::cout << ",";

         std::cout << std::endl;

         ++n;
      }
      std::cout << "]" << std::endl;
   }

   if( !vm["avoid-specials"].as<bool>() ) {
      std::cout << std::endl;
      std::cout << "Special double value test cases (raw hex dump, hexidecimal float, decimal fixed):" << std::endl;

      using nld = std::numeric_limits<double>;

      std::cout << std::endl << " lowest():        "; print_triplet(nld::lowest());
      std::cout << std::endl << " min():           "; print_triplet(nld::min());
      std::cout << std::endl << " max():           "; print_triplet(nld::max());
      std::cout << std::endl << " epsilon():       "; print_triplet(nld::epsilon());
      std::cout << std::endl << " round_error():   "; print_triplet(nld::round_error());
      std::cout << std::endl << " +0:              "; print_triplet(0.0);
      std::cout << std::endl << " -0:              "; print_triplet(-0.0);
      std::cout << std::endl << " infinity():      "; print_triplet(nld::infinity());
      std::cout << std::endl << " -infinity():     "; print_triplet(-nld::infinity());
      std::cout << std::endl << " quiet_NaN():     "; print_triplet(nld::quiet_NaN());
      std::cout << std::endl << " signaling_NaN(): "; print_triplet(nld::signaling_NaN());
      std::cout << std::endl << " denorm_min():    "; print_triplet(nld::denorm_min());
      std::cout << std::endl;

   }

   return 0;
}


text:
/*
Copyright (c) 2016, José María Foces Vivancos
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the <organization> nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL JOSÉ MARÍA FOCES VIVANCOS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <ostream>
#include <misc.h>
#include <boost/log/trivial.hpp>
#include <boost/format.hpp>
#include <boost/regex.hpp>

std::string hexa_print(const unsigned char* array, int len){
	std::string result;
	std::stringstream stream;
	for (int i = 0; i < len;i++){
		stream << str(boost::format("%02x") % (unsigned short)array[i]);
	}
	result = stream.str();
	return result;
}

std::string hexa_print(const char* array, int len){

	return hexa_print((unsigned char*) array,len);
}

bool match_regex(std::string target, boost::regex regex){
	bool ret_value = false;
	boost::match_results<std::string::const_iterator> what;
	std::string::const_iterator start, end;
	boost::match_flag_type flags = boost::match_all;
	start = target.begin();
	end = target.end();
	if (boost::regex_search(start,end,what,regex,flags)){
		BOOST_LOG_TRIVIAL(debug) << "Packet Matches regex";
		ret_value = true;
	}
	return ret_value;
}

max_issues_repo_name: JmFoces/Rehtse

max_forks_repo_name: JmFoces/Rehtse


text:
/**
 * Reactive
 *
 * (c) 2015-2016 Axel Etcheverry
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

#include <boost/test/unit_test.hpp>
#include <reactive/http/protocol.hpp>
#include <reactive/http/request.hpp>
#include <reactive/http/exception.hpp>

BOOST_AUTO_TEST_SUITE(reactive_http_request)

BOOST_AUTO_TEST_CASE(test_constructor)
{
    reactive::http::request request;

    BOOST_CHECK_EQUAL(request.getUserAgent(), REACTIVE_HTTP_REQUEST_USER_AGENT);
    BOOST_CHECK_EQUAL(request.getMethod(), "GET");
    BOOST_CHECK_EQUAL(request.getVersion(), "1.1");

    BOOST_CHECK_EQUAL(request.isGet(),      true);
    BOOST_CHECK_EQUAL(request.isHead(),     false);
    BOOST_CHECK_EQUAL(request.isPost(),     false);
    BOOST_CHECK_EQUAL(request.isPut(),      false);
    BOOST_CHECK_EQUAL(request.isDelete(),   false);
    BOOST_CHECK_EQUAL(request.isTrace(),    false);
    BOOST_CHECK_EQUAL(request.isOptions(),  false);
    BOOST_CHECK_EQUAL(request.isConnect(),  false);
    BOOST_CHECK_EQUAL(request.isPatch(),    false);
}

BOOST_AUTO_TEST_CASE(test_content)
{
    reactive::http::request request;

    request.setContent("Hello World");

    BOOST_CHECK_EQUAL(request.getContent(), "Hello World");
}

BOOST_AUTO_TEST_CASE(test_content_type)
{
    reactive::http::request request;

    request.setContentType("application/json");

    BOOST_CHECK_EQUAL(request.getContentType(), "application/json");

    request.setContentType("application/json; charset=utf-8");

    BOOST_CHECK_EQUAL(request.getContentType(), "application/json");
}

BOOST_AUTO_TEST_CASE(test_read_request)
{
    std::string data;

    data.append("GET / HTTP/1.0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cookie: foo=bar; foo1=bar2");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Encoding: gzip, deflate");
    data.append(reactive::http::protocol::CRLF);
    data.append("Referer: http://www.cplusplus.com/reference/string/string/");
    data.append(reactive::http::protocol::CRLF);
    data.append("Connection: keep-alive");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    //data.append("Hello World");

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.getUserAgent(), "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    BOOST_CHECK_EQUAL(request.getMethod(), "GET");
    BOOST_CHECK_EQUAL(request.getVersion(), "1.0");
    BOOST_CHECK_EQUAL(request.isGet(), true);
    BOOST_CHECK_EQUAL(request.isXmlHttpRequest(), false);
    BOOST_CHECK_EQUAL(request.isUpgrade(), false);

    BOOST_CHECK_EQUAL(request.getCookies().has("foo"), true);

    BOOST_CHECK_EQUAL(request.getCookies().has("foo1"), true);

    BOOST_CHECK_EQUAL(request.getCookies().has("foo2"), false);

    BOOST_CHECK_EQUAL(request.getCookies().get("foo").value, "bar");

    //BOOST_CHECK_EQUAL(request.getContent(), "Hello World");
}

BOOST_AUTO_TEST_CASE(test_is_upgrade)
{
    std::string data;

    data.append("GET /demo HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: example.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Upgrade: WebSocket");
    data.append(reactive::http::protocol::CRLF);
    data.append("WebSocket-Protocol: sample");
    data.append(reactive::http::protocol::CRLF);
    data.append("Origin: http://example.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Connection: Upgrade");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request(data);
    BOOST_CHECK_EQUAL(request.isUpgrade(), true);
}

BOOST_AUTO_TEST_CASE(test_is_connection_keep_alive)
{
    std::string data;

    data.append("GET / HTTP/1.0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cookie: foo=bar; foo1=bar2");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Encoding: gzip, deflate");
    data.append(reactive::http::protocol::CRLF);
    data.append("Referer: http://www.cplusplus.com/reference/string/string/");
    data.append(reactive::http::protocol::CRLF);
    data.append("Connection: keep-alive");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request(data);
    BOOST_CHECK_EQUAL(request.isConnectionKeepAlive(), true);
    BOOST_CHECK_EQUAL(request.isConnectionClose(), false);
}

BOOST_AUTO_TEST_CASE(test_is_connection_close)
{
    std::string data;

    data.append("GET / HTTP/1.0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cookie: foo=bar; foo1=bar2");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Encoding: gzip, deflate");
    data.append(reactive::http::protocol::CRLF);
    data.append("Referer: http://www.cplusplus.com/reference/string/string/");
    data.append(reactive::http::protocol::CRLF);
    data.append("Connection: close");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request(data);
    BOOST_CHECK_EQUAL(request.isConnectionKeepAlive(), false);
    BOOST_CHECK_EQUAL(request.isConnectionClose(), true);
}

BOOST_AUTO_TEST_CASE(test_x_forwarded_for)
{
    std::string data;

    data.append("GET / HTTP/1.0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cookie: foo=bar; foo1=bar2");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Encoding: gzip, deflate");
    data.append(reactive::http::protocol::CRLF);
    data.append("X-Forwarded-For: 90.2.244.246");
    data.append(reactive::http::protocol::CRLF);
    data.append("Referer: http://www.cplusplus.com/reference/string/string/");
    data.append(reactive::http::protocol::CRLF);
    data.append("Connection: keep-alive");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    //data.append("Hello World");

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.info.ip, "90.2.244.246");
}

BOOST_AUTO_TEST_CASE(test_x_client)
{
    std::string data;

    data.append("GET / HTTP/1.0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cookie: foo=bar; foo1=bar2");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Encoding: gzip, deflate");
    data.append(reactive::http::protocol::CRLF);
    data.append("X-Client: 90.2.244.246");
    data.append(reactive::http::protocol::CRLF);
    data.append("Referer: http://www.cplusplus.com/reference/string/string/");
    data.append(reactive::http::protocol::CRLF);
    data.append("Connection: keep-alive");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    //data.append("Hello World");

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.info.ip, "90.2.244.246");
}

/*
BOOST_AUTO_TEST_CASE(test_read_bad_request)
{
    std::string data;

    data.append("GET /");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cookie: foo=bar; foo1=bar2");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Encoding: gzip, deflate");
    data.append(reactive::http::protocol::CRLF);
    data.append("Referer: http://www.cplusplus.com/reference/string/string/");
    data.append(reactive::http::protocol::CRLF);
    data.append("Connection: keep-alive");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    data.append("Hello World");

    try {
        reactive::http::request request(data);
    } catch (swift::http::exception::HttpException e) {
        BOOST_CHECK_EQUAL(e.what(), "Bad Request");
        BOOST_CHECK_EQUAL(e.getStatusCode(), 400);
    }

    std::string data1;

    data1.append("GET / HTTP/1.1");
    data1.append(reactive::http::protocol::CRLF);
    data1.append("Host: www.google.com");
    data1.append(reactive::http::protocol::CRLF);
    data1.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data1.append(reactive::http::protocol::CRLF);
    data1.append("Cookie: foo=bar; foo1=bar2");
    data1.append(reactive::http::protocol::CRLF);
    data1.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.8");
    data1.append(reactive::http::protocol::CRLF);
    data1.append("Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3");
    data1.append(reactive::http::protocol::CRLF);
    data1.append("Accept-Encoding: gzip, deflate");
    data1.append(reactive::http::protocol::CRLF);
    data1.append("Referer: http://www.cplusplus.com/reference/string/string/");
    data1.append(reactive::http::protocol::CRLF);
    data1.append("Connection");
    data1.append(reactive::http::protocol::CRLF);
    data1.append(reactive::http::protocol::CRLF);
    data1.append("Hello World");

    try {
        reactive::http::request request(data1);
    } catch (swift::http::exception::HttpException e) {
        BOOST_CHECK_EQUAL(e.what(), "Bad Request");
        BOOST_CHECK_EQUAL(e.getStatusCode(), 400);
    }
}*/

BOOST_AUTO_TEST_CASE(test_make_request)
{
    std::string data;

    data.append("GET / HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("X-Custom-Line: great");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Reactive (+https://github.com/euskadi31/reactive)");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cookie: foo=bar");
    // Connection is keep-alive by default for HTTP 1.1 but it is the server
    // setting it explicitly
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    data.append("Hello World");

    reactive::http::request request_;

    request_.setMethod("GET");
    request_.setUrl("http://www.google.com");
    request_.getCookies().add("foo", "bar");
    request_.getHeaders().add("X-Custom-Line", "great");
    request_.setContent("Hello World");

    BOOST_CHECK_EQUAL(request_.getHeaders().get("X-Custom-Line").value, "great");
    BOOST_CHECK_EQUAL(request_.toString(), data);
}

BOOST_AUTO_TEST_CASE(test_make_request_with_cookies)
{
    std::string data;

    data.append("GET / HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Reactive (+https://github.com/euskadi31/reactive)");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cookie: foo=bar; foo1=bar1");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request;

    request.setMethod("GET");
    request.setUrl("http://www.google.com");
    request.getCookies().add("foo", "bar");
    request.getCookies().add("foo1", "bar1");

    BOOST_CHECK_EQUAL(request.toString(), data);
}

BOOST_AUTO_TEST_CASE(test_request_init)
{
    std::string data;

    data.append("GET /electric?aa=123 HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cookie: foo=bar; foo1=bar1");

    reactive::http::request req;

    std::string data_basic = data;
    data_basic.append(reactive::http::protocol::CRLF);
    data_basic.append(reactive::http::protocol::CRLF);

    req.parse(data_basic);
    BOOST_CHECK_EQUAL(req.getVersion(), "1.1");
    BOOST_CHECK_EQUAL(req.getMethod(), "GET");
    BOOST_CHECK_EQUAL(req.getUrl().getPath(), "/electric");
    BOOST_CHECK_EQUAL(req.getUrl().getQuery(), "aa=123");
    BOOST_CHECK_EQUAL(req.getUserAgent(), "Reactive (+https://github.com/euskadi31/reactive)");

    std::string data_with_ua = data;
    data_with_ua.append(reactive::http::protocol::CRLF);
    data_with_ua.append("User-Agent: Super Test Web Agent");
    data_with_ua.append(reactive::http::protocol::CRLF);
    data_with_ua.append(reactive::http::protocol::CRLF);

    req.parse(data_with_ua);
    BOOST_CHECK_EQUAL(req.getVersion(), "1.1");
    BOOST_CHECK_EQUAL(req.getMethod(), "GET");
    BOOST_CHECK_EQUAL(req.getUrl().getPath(), "/electric");
    BOOST_CHECK_EQUAL(req.getUrl().getQuery(), "aa=123");
    BOOST_CHECK_EQUAL(req.getData().size(), 0U);
    BOOST_CHECK_EQUAL(req.getUserAgent(), "Super Test Web Agent");

    req.parse(data_basic);
    BOOST_CHECK_EQUAL(req.getVersion(), "1.1");
    BOOST_CHECK_EQUAL(req.getMethod(), "GET");
    BOOST_CHECK_EQUAL(req.getUrl().getPath(), "/electric");
    BOOST_CHECK_EQUAL(req.getUrl().getQuery(), "aa=123");
    // This is bad because reset has not been called
    BOOST_CHECK_EQUAL(req.getUserAgent(), "Super Test Web Agent");

    req.reset();

    req.parse(data_basic);
    BOOST_CHECK_EQUAL(req.getVersion(), "1.1");
    BOOST_CHECK_EQUAL(req.getMethod(), "GET");
    BOOST_CHECK_EQUAL(req.getUrl().getPath(), "/electric");
    BOOST_CHECK_EQUAL(req.getUrl().getQuery(), "aa=123");
    // This value is due to the reset
    BOOST_CHECK_EQUAL(req.getUserAgent(), "Reactive (+https://github.com/euskadi31/reactive)");
}

BOOST_AUTO_TEST_CASE(test_x_requested_with)
{
    std::string data;

    data.append("GET /electric?aa=123 HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("X-Requested-With: XMLHttpRequest");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.isXmlHttpRequest(), true);
}

BOOST_AUTO_TEST_CASE(test_forwarded)
{
    std::string data;

    data.append("GET /electric HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("X-Forwarded-For: bad_ip");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request;
    request.info.ip_version = reactive::net::ip::IPV4;
    request.info.ip = "192.168.0.12";
    request.info.port = "52459";
    request.info.local_ip = "192.168.0.15";
    request.info.local_port = "8080";

    request.parse(data);

    BOOST_CHECK_EQUAL(request.info.ip_version, reactive::net::ip::UNDEFINED);
}

BOOST_AUTO_TEST_CASE(test_post_request)
{
    std::string data;

    data.append("POST /electric?aa=123 HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Type: application/x-www-form-urlencoded");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cookie: foo=bar; foo1=bar1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Length: 11");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    data.append("foo=bar&a=b");

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.getUserAgent(), "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    BOOST_CHECK_EQUAL(request.getMethod(), "POST");
    BOOST_CHECK_EQUAL(request.getVersion(), "1.1");
    BOOST_CHECK_EQUAL(request.isPost(), true);
    BOOST_CHECK_EQUAL(request.isXmlHttpRequest(), false);

    BOOST_CHECK_EQUAL(request.getCookies().has("foo"), true);

    BOOST_CHECK_EQUAL(request.getCookies().has("foo1"), true);

    BOOST_CHECK_EQUAL(request.getCookies().has("foo2"), false);

    BOOST_CHECK_EQUAL(request.getCookies().get("foo").value, "bar");

    BOOST_CHECK_EQUAL(request.getContent(), "foo=bar&a=b");

    BOOST_CHECK_EQUAL(request.getData().size(), 2U);
}

BOOST_AUTO_TEST_CASE(test_has_query_argument)
{
    std::string data;

    data.append("GET /electric?aa=123 HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.hasQueryArgument("aa"), true);
    BOOST_CHECK_EQUAL(request.hasQueryArgument("bb"), false);
}

BOOST_AUTO_TEST_CASE(test_get_query_argument_exception)
{
    std::string data;

    data.append("GET /electric?aa=123 HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request(data);

    BOOST_CHECK_THROW(request.getQueryArgument<std::string>("bb"), reactive::http::exception);
    BOOST_CHECK_THROW(request.getQueryArgument<int>("bb"), reactive::http::exception);
    BOOST_CHECK_THROW(request.getQueryArgument<int64_t>("bb"), reactive::http::exception);
    BOOST_CHECK_THROW(request.getQueryArgument<double>("bb"), reactive::http::exception);
    BOOST_CHECK_THROW(request.getQueryArgument<bool>("bb"), reactive::http::exception);
}

BOOST_AUTO_TEST_CASE(test_get_query_argument_string)
{
    std::string data;

    data.append("GET /electric?aa=123 HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.getQueryArgument<std::string>("aa"), "123");
    BOOST_CHECK_EQUAL(request.getQueryArgument<std::string>("aa", ""), "123");
    BOOST_CHECK_EQUAL(request.getQueryArgument<std::string>("bb", ""), "");
}

BOOST_AUTO_TEST_CASE(test_get_query_argument_int)
{
    std::string data;

    data.append("GET /electric?aa=123 HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.getQueryArgument<int>("aa"), 123);
    BOOST_CHECK_EQUAL(request.getQueryArgument<int>("aa", 456), 123);
    BOOST_CHECK_EQUAL(request.getQueryArgument<int>("bb", 456), 456);
}

BOOST_AUTO_TEST_CASE(test_get_query_argument_int64)
{
    std::string data;

    data.append("GET /electric?aa=123 HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.getQueryArgument<int64_t>("aa"), 123);
    BOOST_CHECK_EQUAL(request.getQueryArgument<int64_t>("aa", 456), 123);
    BOOST_CHECK_EQUAL(request.getQueryArgument<int64_t>("bb", 456), 456);
}

BOOST_AUTO_TEST_CASE(test_get_query_argument_bool)
{
    std::string data;

    data.append("GET /electric?aa=1&bb=0&cc=true&dd=True&ee=TRUE HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.getQueryArgument<bool>("aa"), true);
    BOOST_CHECK_EQUAL(request.getQueryArgument<bool>("bb"), false);
    BOOST_CHECK_EQUAL(request.getQueryArgument<bool>("cc"), true);
    BOOST_CHECK_EQUAL(request.getQueryArgument<bool>("dd"), true);
    BOOST_CHECK_EQUAL(request.getQueryArgument<bool>("ee"), true);
    BOOST_CHECK_EQUAL(request.getQueryArgument<bool>("ff", true), true);
    BOOST_CHECK_EQUAL(request.getQueryArgument<bool>("ee", false), true);
    BOOST_CHECK_EQUAL(request.getQueryArgument<bool>("bb", true), false);
}

BOOST_AUTO_TEST_CASE(test_get_query_argument_double)
{
    std::string data;

    data.append("GET /electric?aa=1.1 HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.getQueryArgument<double>("aa"), 1.1);
    BOOST_CHECK_EQUAL(request.getQueryArgument<double>("aa", 2.2), 1.1);
    BOOST_CHECK_EQUAL(request.getQueryArgument<double>("bb", 2.2), 2.2);
}

BOOST_AUTO_TEST_CASE(test_has_body_argument)
{
    std::string data;

    data.append("POST /electric HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Type: application/x-www-form-urlencoded");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Length: 6");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    data.append("aa=123");

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.hasBodyArgument("aa"), true);
    BOOST_CHECK_EQUAL(request.hasBodyArgument("bb"), false);
}

BOOST_AUTO_TEST_CASE(test_get_body_argument_exception)
{
    std::string data;

    data.append("POST /electric HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Type: application/x-www-form-urlencoded");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Length: 6");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    data.append("aa=123");

    reactive::http::request request(data);

    BOOST_CHECK_THROW(request.getBodyArgument<std::string>("bb"), reactive::http::exception);
    BOOST_CHECK_THROW(request.getBodyArgument<int>("bb"), reactive::http::exception);
    BOOST_CHECK_THROW(request.getBodyArgument<double>("bb"), reactive::http::exception);
    BOOST_CHECK_THROW(request.getBodyArgument<int64_t>("bb"), reactive::http::exception);
    BOOST_CHECK_THROW(request.getBodyArgument<bool>("bb"), reactive::http::exception);
}

BOOST_AUTO_TEST_CASE(test_get_body_argument_string)
{
    std::string data;

    data.append("POST /electric HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Type: application/x-www-form-urlencoded");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Length: 6");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    data.append("aa=123");

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.getBodyArgument<std::string>("aa"), "123");
    BOOST_CHECK_EQUAL(request.getBodyArgument<std::string>("aa", ""), "123");
    BOOST_CHECK_EQUAL(request.getBodyArgument<std::string>("bb", ""), "");
}

BOOST_AUTO_TEST_CASE(test_get_body_argument_int)
{
    std::string data;

    data.append("POST /electric HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Type: application/x-www-form-urlencoded");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Length: 6");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    data.append("aa=123");

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.getBodyArgument<int>("aa"), 123);
    BOOST_CHECK_EQUAL(request.getBodyArgument<int>("aa", 456), 123);
    BOOST_CHECK_EQUAL(request.getBodyArgument<int>("bb", 456), 456);
}

BOOST_AUTO_TEST_CASE(test_get_body_argument_int64)
{
    std::string data;

    data.append("POST /electric HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Type: application/x-www-form-urlencoded");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Length: 6");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    data.append("aa=123");

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.getBodyArgument<int64_t>("aa"), 123);
    BOOST_CHECK_EQUAL(request.getBodyArgument<int64_t>("aa", 456), 123);
    BOOST_CHECK_EQUAL(request.getBodyArgument<int64_t>("bb", 456), 456);
}

BOOST_AUTO_TEST_CASE(test_get_body_argument_bool)
{
    std::string data;

    data.append("POST /electric HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Type: application/x-www-form-urlencoded");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Length: 33");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    data.append("aa=1&bb=0&cc=true&dd=True&ee=TRUE");

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.getBodyArgument<bool>("aa"), true);
    BOOST_CHECK_EQUAL(request.getBodyArgument<bool>("bb"), false);
    BOOST_CHECK_EQUAL(request.getBodyArgument<bool>("cc"), true);
    BOOST_CHECK_EQUAL(request.getBodyArgument<bool>("dd"), true);
    BOOST_CHECK_EQUAL(request.getBodyArgument<bool>("ee"), true);
    BOOST_CHECK_EQUAL(request.getBodyArgument<bool>("ff", true), true);
    BOOST_CHECK_EQUAL(request.getBodyArgument<bool>("ee", false), true);
    BOOST_CHECK_EQUAL(request.getBodyArgument<bool>("bb", true), false);
}

BOOST_AUTO_TEST_CASE(test_get_body_argument_double)
{
    std::string data;

    data.append("POST /electric HTTP/1.1");
    data.append(reactive::http::protocol::CRLF);
    data.append("Host: www.google.com");
    data.append(reactive::http::protocol::CRLF);
    data.append("Cache-Control: max-age=0");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Type: application/x-www-form-urlencoded");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    data.append(reactive::http::protocol::CRLF);
    data.append("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4");
    data.append(reactive::http::protocol::CRLF);
    data.append("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    data.append(reactive::http::protocol::CRLF);
    data.append("Content-Length: 6");
    data.append(reactive::http::protocol::CRLF);
    data.append(reactive::http::protocol::CRLF);
    data.append("aa=1.1");

    reactive::http::request request(data);

    BOOST_CHECK_EQUAL(request.getBodyArgument<double>("aa"), 1.1);
    BOOST_CHECK_EQUAL(request.getBodyArgument<double>("aa", 2.2), 1.1);
    BOOST_CHECK_EQUAL(request.getBodyArgument<double>("bb", 2.2), 2.2);
}

BOOST_AUTO_TEST_SUITE_END()

max_stars_repo_name: ReactiveFramework/ReactiveFramework

max_issues_repo_name: ReactiveFramework/ReactiveFramework

max_forks_repo_name: ReactiveFramework/ReactiveFramework