From 728653fbb36727acfb5a4cd480b7fa5d45adfa89 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 13 Feb 2013 20:32:10 +0200 Subject: proto lib fixes more tests --- proto_test/main.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'proto_test/main.cpp') diff --git a/proto_test/main.cpp b/proto_test/main.cpp index ba0b8e8..1083e44 100644 --- a/proto_test/main.cpp +++ b/proto_test/main.cpp @@ -60,7 +60,7 @@ bool test_client_to_server_command() bool test_services_extraction() { packet *p = packet::cli_make_request_services_packet(); - if(p->get_type() != TYPE_SERVICES_REQUEST) + if(p->get_type() != TYPE_SERVICES) return false; std::list list1; service_s s1; @@ -124,6 +124,57 @@ bool test_services_extraction() return true; } +bool test_command_exchange() +{ + packet *p = packet::cli_make_command_packet("test service", "test command"); + svc_cmd c = packet::serv_extract_command(*p); + if(c.command != "test command") + return false; + if(c.service != "test service") + return false; + delete p; + p = packet::serv_make_command_reply_packet("success", STATUS_SUCCESS); + std::string s = packet::cli_parse_command_reply(*p); + if(s != "success") + return false; + if(p->get_status() != STATUS_SUCCESS) + return false; + delete p; + p = packet::serv_make_command_reply_packet("failure", STATUS_FAILURE); + s = packet::cli_parse_command_reply(*p); + if(s != "failure") + return false; + if(p->get_status() != STATUS_FAILURE) + return false; + delete p; + return true; +} + +bool test_status_packet() +{ + packet *p = packet::serv_make_status_packet(TYPE_AUTH, STATUS_SUCCESS); + if(!p->is_good()) + return false; + if(p->get_status() != STATUS_SUCCESS) + return false; + if(p->get_type() != TYPE_AUTH) + return false; + if(!p->is_server_packet()) + return false; + delete p; + p = packet::cli_make_status_packet(TYPE_SERVICES, STATUS_FAILURE); + if(p->get_status() != STATUS_FAILURE) + return false; + if(p->get_type() != TYPE_SERVICES) + return false; + if(!p->is_good()) + return false; + if(!p->is_client_packet()) + return false; + delete p; + return true; +} + int main() { std::list bad_packets = test_creation(); @@ -147,5 +198,13 @@ int main() std::cout<<"service extraction test: OK"<