std::size_t DummySessionConnection::lookup_idx(const logsvc::prot::FileHandle fh) const
 {
   std::size_t idx = egen::lookup(fh, fh_to_idx,
                                  std::numeric_limits<std::size_t>::max());
   BOOST_REQUIRE_NE(idx, std::numeric_limits<std::size_t>::max());
   return idx;
 }
void checkGet(const openfluid::utils::RESTClient& Client)
{
  openfluid::utils::RESTClient::Reply Reply;

  Reply = Client.getResource("/users");
  std::cout << "GET /users : " << Reply.getStatusCode() << std::endl;
  BOOST_REQUIRE(Reply.isOK());
  BOOST_REQUIRE_EQUAL(Reply.getStatusCode(),200);
  BOOST_REQUIRE_NE(Reply.getContent().indexOf("\"username\": \"Bret\""),-1);

  Reply = Client.getResource("/users/23");
  std::cout << "GET /users/23 : " << Reply.getStatusCode() << std::endl;
  std::cout << "  - " << Reply.getNetworkErrorCode() << ": " <<
               Reply.getNetworkErrorString().toStdString() << std::endl;
  BOOST_REQUIRE(!Reply.isOK());
  BOOST_REQUIRE_EQUAL(Reply.getStatusCode(),404);

  Reply = Client.getResource("/users/2");
  std::cout << "GET /users/2 : " << Reply.getStatusCode() << std::endl;
  BOOST_REQUIRE(Reply.isOK());
  BOOST_REQUIRE_EQUAL(Reply.getStatusCode(),200);
  BOOST_REQUIRE_NE(Reply.getContent().indexOf("\"username\": \"Antonette\""),-1);
}
Beispiel #3
0
static void add_widget(gui2::tgrid& grid
		, gui2::twidget* widget
		, const std::string& id
		, const unsigned row
		, const unsigned column)
{
	BOOST_REQUIRE_NE(widget, static_cast<gui2::twidget*>(NULL));

	widget->set_id(id);
	grid.set_child(widget
			, row
			, column
			, gui2::tgrid::VERTICAL_GROW_SEND_TO_CLIENT
				| gui2::tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT
			, 0);
}
	void test_popup_resolutions(const tresolution_list& resolutions)
	{
		bool interact = false;
		for(int i = 0; i < 2; ++i) {
			BOOST_FOREACH(const tresolution& resolution, resolutions) {
				video().make_test_fake(resolution.first, resolution.second);

				boost::scoped_ptr<gui2::tpopup> dlg(twrapper<T>::create());
				BOOST_REQUIRE_MESSAGE(dlg.get(), "Failed to create a dialog.");

				const std::string id = gui2::unit_test_mark_popup_as_tested(*(dlg.get()));

				std::string exception;
				try {
					dlg->show(video(), interact);
					gui2::twindow* window = gui2::unit_test_window((*dlg.get()));
					BOOST_REQUIRE_NE(window, static_cast<void*>(NULL));
					window->draw();
				} catch(gui2::tlayout_exception_width_modified&) {
					exception = "gui2::tlayout_exception_width_modified";
				} catch(gui2::tlayout_exception_width_resize_failed&) {
					exception = "gui2::tlayout_exception_width_resize_failed";
				} catch(gui2::tlayout_exception_height_resize_failed&) {
					exception = "gui2::tlayout_exception_height_resize_failed";
				} catch(twml_exception& e) {
					exception = e.dev_message;
				} catch(std::exception& e) {
					exception = e.what();
				} catch(...) {
					exception = "unknown";
				}
				BOOST_CHECK_MESSAGE(exception.empty(),
						"Test for '" << id
						<< "' Failed\nnew widgets = " << gui2::new_widgets
						<< " small gui = " << game_config::small_gui
						<< " resolution = " << resolution.first
						<< 'x' << resolution.second
						<< "\nException caught: " << exception << '.');
			}

			interact = true;
		}
Beispiel #5
0
static void test_remove_backend(session &sess) {
	server_node &node = get_setup()->nodes[0];


	server_config &config = node.config();
	config_data &last_backend = config.backends.back();
	const uint32_t backend_id = std::stoi(last_backend.string_value("backend_id"));

	ELLIPTICS_REQUIRE(enable_result, sess.remove_backend(node.remote(), backend_id));

	/* Request all backends status and check that removed backend is missed */
	ELLIPTICS_REQUIRE(async_status_result, sess.request_backends_status(node.remote()));
	sync_backend_status_result result = async_status_result;

	BOOST_REQUIRE_EQUAL(result.size(), 1);

	backend_status_result_entry entry = result.front();

	for (size_t i = 0; i < backends_count; ++i) {
		auto status = entry.backend(i);
		BOOST_REQUIRE_NE(status->backend_id, backend_id);
	}
}
Beispiel #6
0
static void test_control()
{
	std::cerr << __func__ << ": " << typeid(T).name() << ".\n";

	T control;
	boost::scoped_ptr<gui2::iterator::twalker_> visitor(control.create_walker());

	BOOST_REQUIRE_NE(visitor.get(), static_cast<void*>(NULL));

	/***** INITIAL STATE *****/

	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::twalker_::widget), false);
	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::twalker_::grid), true);
	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::twalker_::child), true);

	BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::twalker_::widget), &control);
	BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::twalker_::grid), static_cast<void*>(NULL));
	BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::twalker_::child), static_cast<void*>(NULL));

	/***** VISITING WIDGET *****/

	BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::twalker_::widget), gui2::iterator::twalker_::invalid);
	BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::twalker_::grid), gui2::iterator::twalker_::fail);
	BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::twalker_::child), gui2::iterator::twalker_::fail);

	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::twalker_::widget), true);
	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::twalker_::grid), true);
	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::twalker_::child), true);

	BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::twalker_::widget), static_cast<void*>(NULL));
	BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::twalker_::grid), static_cast<void*>(NULL));
	BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::twalker_::child), static_cast<void*>(NULL));

	/***** POST END *****/

	BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::twalker_::widget), gui2::iterator::twalker_::fail);
}
Beispiel #7
0
static void test_control()
{
	//std::cerr << __func__ << ": " << typeid(T).name() << ".\n";

	T control;
	const std::unique_ptr<gui2::iteration::walker_base> visitor(control.create_walker());

	BOOST_REQUIRE_NE(visitor.get(), static_cast<void*>(nullptr));

	/***** INITIAL STATE *****/

	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iteration::walker_base::self), false);
	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iteration::walker_base::internal), true);
	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iteration::walker_base::child), true);

	BOOST_CHECK_EQUAL(visitor->get(gui2::iteration::walker_base::self), &control);
	BOOST_CHECK_EQUAL(visitor->get(gui2::iteration::walker_base::internal), static_cast<void*>(nullptr));
	BOOST_CHECK_EQUAL(visitor->get(gui2::iteration::walker_base::child), static_cast<void*>(nullptr));

	/***** VISITING WIDGET *****/

	BOOST_CHECK_EQUAL(visitor->next(gui2::iteration::walker_base::self), gui2::iteration::walker_base::invalid);
	BOOST_CHECK_EQUAL(visitor->next(gui2::iteration::walker_base::internal), gui2::iteration::walker_base::fail);
	BOOST_CHECK_EQUAL(visitor->next(gui2::iteration::walker_base::child), gui2::iteration::walker_base::fail);

	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iteration::walker_base::self), true);
	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iteration::walker_base::internal), true);
	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iteration::walker_base::child), true);

	BOOST_CHECK_EQUAL(visitor->get(gui2::iteration::walker_base::self), static_cast<void*>(nullptr));
	BOOST_CHECK_EQUAL(visitor->get(gui2::iteration::walker_base::internal), static_cast<void*>(nullptr));
	BOOST_CHECK_EQUAL(visitor->get(gui2::iteration::walker_base::child), static_cast<void*>(nullptr));

	/***** POST END *****/

	BOOST_CHECK_EQUAL(visitor->next(gui2::iteration::walker_base::self), gui2::iteration::walker_base::fail);
}
Beispiel #8
0
static void test_grid()
{
	/* An empty grid behaves the same as a control so test here. */
	test_control<gui2::tgrid>();

	std::cerr << __func__ << ": Detailed test.\n";

	/* Test the child part here. */
	gui2::tgrid grid(2 ,2);
	add_widget(grid, new gui2::tlabel(), "(1,1)", 0, 0);
	add_widget(grid, new gui2::tlabel(), "(1,2)", 0, 1);
	add_widget(grid, new gui2::tlabel(), "(2,1)", 1, 0);
	add_widget(grid, new gui2::tlabel(), "(2,2)", 1, 1);

	boost::scoped_ptr<gui2::iterator::twalker_> visitor(grid.create_walker());

	/***** LABEL 1,1 *****/

	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::twalker_::child), false);

	BOOST_REQUIRE_NE(visitor->get(gui2::iterator::twalker_::child), static_cast<void*>(NULL));
	BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::twalker_::child)->id(), "(1,1)");

	/***** LABEL 2,1 *****/

	BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::twalker_::child), gui2::iterator::twalker_::valid);

	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::twalker_::child), false);

	BOOST_REQUIRE_NE(visitor->get(gui2::iterator::twalker_::child), static_cast<void*>(NULL));
	BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::twalker_::child)->id(), "(2,1)");

	/***** LABEL 1,2 *****/

	BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::twalker_::child), gui2::iterator::twalker_::valid);

	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::twalker_::child), false);

	BOOST_REQUIRE_NE(visitor->get(gui2::iterator::twalker_::child), static_cast<void*>(NULL));
	BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::twalker_::child)->id(), "(1,2)");

	/***** LABEL 2,2 *****/

	BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::twalker_::child), gui2::iterator::twalker_::valid);

	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::twalker_::child), false);

	BOOST_REQUIRE_NE(visitor->get(gui2::iterator::twalker_::child), static_cast<void*>(NULL));
	BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::twalker_::child)->id(), "(2,2)");

	/***** END *****/

	BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::twalker_::child), gui2::iterator::twalker_::invalid);

	BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::twalker_::child), true);

	BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::twalker_::child), static_cast<void*>(NULL));

	/***** POST END *****/

	BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::twalker_::child), gui2::iterator::twalker_::fail);
}
BOOST_AUTO_TEST_CASE_TEMPLATE( move_random_data_through_the_buffer, sizes, test_sizes )
{
    std::vector< std::uint8_t >   test_data = this->random_data( 20 );
    std::vector< std::uint8_t >   received_data;
    std::vector< std::size_t >    transmit_sizes;
    std::vector< std::size_t >    receive_sizes;

    const std::size_t max_rx_size_value = std::tuple_element< 0, sizes >::type::value;
    const std::size_t min_size          = std::tuple_element< 1, sizes >::type::value;
    const std::size_t max_size          = std::tuple_element< 2, sizes >::type::value;

    max_rx_size( max_rx_size_value );

    auto emergency_counter = 2 * test_data.size();
    bool sequence_number   = false;

    for ( std::size_t send_size = 0; send_size < test_data.size(); --emergency_counter )
    {
        BOOST_REQUIRE( emergency_counter );
        auto read = allocate_receive_buffer();

        // if there is room in the receive buffer, I allocate that memory and simulate a received PDU
        if ( read.size )
        {
            const std::size_t size = std::min< std::size_t >( random_value( min_size, max_size ), test_data.size() - send_size );

            if ( size != 0 )
            {
                transmit_sizes.push_back( size );
            }

            read.buffer[ 1 ] = size;
            read.buffer[ 0 ] = 2;

            if ( sequence_number )
                read.buffer[ 0 ] |= 8;

            sequence_number = !sequence_number;

            std::copy( test_data.begin() + send_size, test_data.begin() + send_size + size, &read.buffer[ 2 ] );
            received( read );

            send_size += size;
        }
        // if there is no more room left, I simulate the receiving of an pdu
        else
        {
            auto next = next_received();
            BOOST_REQUIRE_NE( next.size, 0u );
            BOOST_REQUIRE_NE( next.buffer[ 1 ], 0u );

            receive_sizes.push_back( next.buffer[ 1 ] );
            BOOST_REQUIRE_LE( receive_sizes.size(), transmit_sizes.size() );
            BOOST_REQUIRE_EQUAL( receive_sizes.back(), transmit_sizes[ receive_sizes.size() - 1 ] );

            received_data.insert( received_data.end(), &next.buffer[ 2 ], &next.buffer[ 2 ] + next.buffer[ 1 ] );
            free_received();
        }
    }

    for ( auto next = next_received(); next.size; next = next_received(), --emergency_counter )
    {
        BOOST_REQUIRE( emergency_counter );
        receive_sizes.push_back( next.buffer[ 1 ] );
        BOOST_REQUIRE_LE( receive_sizes.size(), transmit_sizes.size() );
        BOOST_REQUIRE_EQUAL( receive_sizes.back(), transmit_sizes[ receive_sizes.size() - 1 ] );

        received_data.insert( received_data.end(), &next.buffer[ 2 ], &next.buffer[ 2 ] + next.buffer[ 1 ] );
        free_received();
    }

    BOOST_CHECK_EQUAL_COLLECTIONS( test_data.begin(), test_data.end(), received_data.begin(), received_data.end() );
}