TEST(terminal_type_client_test, receiving_terminal_type_reports_terminal_type)
{
    telnetpp::options::terminal_type::client client;
    client.activate();
    client.negotiate(telnetpp::will);

    std::string terminal_type;
    client.on_terminal_type.connect(
        [&terminal_type, &client](std::string const &new_terminal_type)
            -> std::vector<telnetpp::token>
        {
            terminal_type = new_terminal_type;
            return client.request_terminal_type();
        });

    std::string expected("abc");

    expect_tokens(
        {
            telnetpp::element(telnetpp::subnegotiation(
                client.option(),
                { 1 }))
        },
        client.subnegotiate({
            0,
            telnetpp::u8(expected[0]),
            telnetpp::u8(expected[1]),
            telnetpp::u8(expected[2])}));

    ASSERT_EQ(expected, terminal_type);
}
Пример #2
0
TEST(session_test, non_telnet_objects_are_passed_through)
{
    telnetpp::session session(nullptr);

    expect_tokens(
        {
            boost::any{}
        },
        session.send({boost::any{}})
    );
}
Пример #3
0
TEST(session_test, unrouted_dont_results_in_wont)
{
    telnetpp::session session(nullptr);

    expect_tokens( {
            telnetpp::element { telnetpp::negotiation(telnetpp::wont, 0xA0) }
        },
        session.receive( {
            telnetpp::iac,
            telnetpp::dont,
            0xA0
        }));
}
Пример #4
0
TEST(pass_through_test, can_pass_arbitrary_object_as_result_of_negotiation)
{
    pass_through_option option;
    option.set_activatable();
    
    expect_tokens(
        {
            telnetpp::element(telnetpp::negotiation(
                telnetpp::do_, pass_through_option_id)),
            boost::any(test_string)
        },
        option.negotiate(telnetpp::will));
}
TEST(terminal_type_client_test, requesting_terminal_type_sends_terminal_type_request)
{
    telnetpp::options::terminal_type::client client;
    client.activate();
    client.negotiate(telnetpp::will);

    expect_tokens(
        {
            telnetpp::element(telnetpp::subnegotiation(
                client.option(),
                { 1 }))
        },
        client.request_terminal_type());
}
Пример #6
0
TEST(mccp_client_test, empty_subnegotiation_returns_begin_decompression)
{
    telnetpp::options::mccp::client client;
    client.activate();
    client.negotiate(telnetpp::will);

    auto const expected = std::vector<telnetpp::token> {
        boost::any(telnetpp::options::mccp::begin_decompression{})
    };

    // When an empty subnegotiation is received, we should send a
    // begin_decompression tag so that the lower layers know to start treating
    // the very next byte received as the start of a compression stream.
    expect_tokens(expected, client.subnegotiate({}));
}
Пример #7
0
TEST(session_test, reception_of_negotiation_routes_to_installed_server_option)
{
    telnetpp::session session(nullptr);
    telnetpp::options::echo::server server;

    server.set_activatable();
    session.install(server);

    expect_tokens(
        { telnetpp::element(
            telnetpp::negotiation(telnetpp::will, server.option())) },
        session.receive({
            telnetpp::iac,
            telnetpp::do_,
            server.option()
        }));
}
Пример #8
0
TEST(mccp_client_test, deactivated_client_locally_returns_end_decompression)
{
    telnetpp::options::mccp::client client;
    client.activate();
    client.negotiate(telnetpp::will);
    client.subnegotiate({});
    client.deactivate();

    // Upon reception of the WONT packet, the client will be fully deactivated.
    // This means that the very next byte received will no longer be
    // compressed.  Therefore, we should end decompression.
    expect_tokens(
        {
            boost::any(telnetpp::options::mccp::end_decompression{})
        },
        client.negotiate(telnetpp::wont));
}
Пример #9
0
TEST(terminal_read_test, read_partial_command_yields_nothing)
{
    expect_tokens("\x1B[", {});
}
Пример #10
0
TEST(terminal_read_test, read_empty_string_yields_nothing)
{
    expect_tokens("", {});
}
Пример #11
0
void expect_token(
    std::string const &input,
    terminalpp::token const &expected_token)
{
    expect_tokens(input, {expected_token});
}