diff options
Diffstat (limited to 'proto_test')
-rw-r--r-- | proto_test/main.cpp | 61 |
1 files changed, 60 insertions, 1 deletions
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<service_s> 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<std::string> bad_packets = test_creation(); @@ -147,5 +198,13 @@ int main() std::cout<<"service extraction test: OK"<<std::endl; else std::cout<<"service extraction test: ERROR"<<std::endl; + if(test_command_exchange()) + std::cout<<"command exchange test: OK"<<std::endl; + else + std::cout<<"command exchange test: ERROR"<<std::endl; + if(test_status_packet()) + std::cout<<"status packet test: OK"<<std::endl; + else + std::cout<<"status packet test: ERROR"<<std::endl; return 0; } |