diff options
Diffstat (limited to 'proto_test')
| -rw-r--r-- | proto_test/main.cpp | 138 | ||||
| -rw-r--r-- | proto_test/proto_test.project | 103 | 
2 files changed, 241 insertions, 0 deletions
diff --git a/proto_test/main.cpp b/proto_test/main.cpp new file mode 100644 index 0000000..28d04e9 --- /dev/null +++ b/proto_test/main.cpp @@ -0,0 +1,138 @@ + +#include <string> +#include <list> +#include <vector> +#include <iostream> +#include "api_protocol.h" + +using namespace proto; + +void print_vector(const std::vector<unsigned char> &v) +{ +	for(std::vector<unsigned char>::const_iterator i = v.begin(), end = v.end(); i != end; ++i) +		std::cout<<*i; +	std::cout<<std::endl; +} + +std::list<std::string> test_creation() +{ +	std::list<std::string> packets; +	packet *p = packet::cli_make_init_packet(); +	if(!p->is_good()) +		packets.push_back("cli init packet"); +/*	else +		print_vector(p->raw()); */ +	delete p; +	p = packet::cli_make_command_packet("test_svc", "test_cmd"); +	if(!p->is_good()) +		packets.push_back("cli cmd packet"); +/*	else +		print_vector(p->raw()); */ +	delete p; +	p = packet::cli_make_request_services_packet(); +	if(!p->is_good()) +		packets.push_back("cli svc req packet"); +/*	else +		print_vector(p->raw()); */ +	return packets; +} + +bool test_handshake() +{ +	packet *p = packet::cli_make_init_packet(); +	if(packet::serv_validate_client_proto(*p)) +		return true; +	else +		return false; +} + +bool test_client_to_server_command() +{ +	packet *p = packet::cli_make_command_packet("test srv 1", "command with spaces"); +	svc_cmd c = packet::serv_extract_command(*p); +	if(c.service != "test srv 1") +		return false; +	if(c.command != "command with spaces") +		return false; +	return true; +} + +bool test_services_extraction() +{ +	packet *p = packet::cli_make_request_services_packet(); +	if(p->get_type() != TYPE_SERVICES_REQUEST) +		return false; +	std::list<service_s> list1; +	service_s s1; +	s1.service = "test service 1"; +	service_s::cmd c; +	c.command = "command 1"; +	c.description = "some desc"; +	s1.cmds.push_back(c); +	c.command = "command 2"; +	c.description = ""; +	s1.cmds.push_back(c); +	c.command = "command 3"; +	c.description = "command 3 desc"; +	s1.cmds.push_back(c); +	list1.push_back(s1); +	s1.service = "sd,fhjsiufhifhirhwiefbbbbvwyefgweyfuyvbwf service 2 aaaaaaaaaaaaaaaaaa111111111111111111111111asdasdasd"; +	c.command = "2command 1"; +	c.description = "2some desc"; +	s1.cmds.push_back(c); +	c.command = "2command 2"; +	c.description = ""; +	s1.cmds.push_back(c); +	c.command = "2command 3"; +	c.description = "2command 3 desc"; +	s1.cmds.push_back(c); +	list1.push_back(s1); +	s1.service = "sd,fhjsiufhiadadsdfgdffghghjbnfdghdgffhirhwiefbbbbvwyefgweyfuyvbwf service 2 aaaaaaaaaaaaaaaaaa111111111111111111111111asdasdasd"; +	c.command = "32commanasdasdd 1"; +	c.description = "32some desc"; +	s1.cmds.push_back(c); +	c.command = "32command 2"; +	c.description = ""; +	s1.cmds.push_back(c); +	c.command = "32command 3"; +	c.description = "32command 3 desc"; +	s1.cmds.push_back(c); +	list1.push_back(s1); +	delete p; +	p = packet::serv_make_services_packet(list1); +	std::list<service_s> *list2 = packet::cli_extract_services(*p); +	for(std::list<service_s>::iterator i = list2->begin(), end = list2->end(); i != end; ++i) +	{ +		//if(std::find(list1.begin(), list1.end(), *i) == list1.end()) //fuck +		for(std::list<service_s>::iterator ii = list1.begin(), end = list1.end(); ii != end; ++ii) +			if(*ii != *i) +				return false; +	} +	return true; +} + +int main() +{ +	std::list<std::string> bad_packets = test_creation(); +	if(!bad_packets.empty()) +	{ +		std::cout<<"packet creation test: ERROR"<<std::endl; +		for(std::list<std::string>::iterator i = bad_packets.begin(), end = bad_packets.end(); i != end; ++i) +			std::cout<<*i<<std::endl; +	} +	else +		std::cout<<"packet creation test: OK"<<std::endl; +	if(test_handshake()) +		std::cout<<"handshake test: OK"<<std::endl; +	else +		std::cout<<"handshake test: ERROR"<<std::endl; +	if(test_client_to_server_command()) +		std::cout<<"client to server cmd test: OK"<<std::endl; +	else +		std::cout<<"client to server cmd test: ERROR"<<std::endl; +	if(test_services_extraction()) +		std::cout<<"service extraction test: OK"<<std::endl; +	else +		std::cout<<"service extraction test: ERROR"<<std::endl; +	return 0; +} diff --git a/proto_test/proto_test.project b/proto_test/proto_test.project new file mode 100644 index 0000000..ffb4e33 --- /dev/null +++ b/proto_test/proto_test.project @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="utf-8"?> +<CodeLite_Project Name="proto_test" InternalType="Console"> +  <Plugins> +    <Plugin Name="qmake"> +      <![CDATA[00010001N0005Debug000000000000]]> +    </Plugin> +  </Plugins> +  <Description/> +  <Dependencies/> +  <VirtualDirectory Name="src"> +    <File Name="main.cpp"/> +  </VirtualDirectory> +  <Settings Type="Executable"> +    <GlobalSettings> +      <Compiler Options="" C_Options=""> +        <IncludePath Value="."/> +      </Compiler> +      <Linker Options=""> +        <LibraryPath Value="."/> +      </Linker> +      <ResourceCompiler Options=""/> +    </GlobalSettings> +    <Configuration Name="Debug" CompilerType="gnu g++" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> +      <Compiler Options="-g;-O0;-Wall" C_Options="-g;-O0;-Wall" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags=""> +        <IncludePath Value="."/> +        <IncludePath Value="../proto_lib"/> +        <Preprocessor Value="DEBUG"/> +      </Compiler> +      <Linker Options="" Required="yes"> +        <LibraryPath Value="../proto_lib/Debug"/> +        <Library Value="proto"/> +      </Linker> +      <ResourceCompiler Options="" Required="no"/> +      <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/> +      <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>"> +        <![CDATA[]]> +      </Environment> +      <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath=""> +        <PostConnectCommands/> +        <StartupCommands/> +      </Debugger> +      <PreBuild/> +      <PostBuild/> +      <CustomBuild Enabled="no"> +        <RebuildCommand/> +        <CleanCommand/> +        <BuildCommand/> +        <PreprocessFileCommand/> +        <SingleFileCommand/> +        <MakefileGenerationCommand/> +        <ThirdPartyToolName>None</ThirdPartyToolName> +        <WorkingDirectory/> +      </CustomBuild> +      <AdditionalRules> +        <CustomPostBuild/> +        <CustomPreBuild/> +      </AdditionalRules> +      <Completion EnableCpp11="no"> +        <ClangCmpFlagsC/> +        <ClangCmpFlags/> +        <ClangPP/> +        <SearchPaths/> +      </Completion> +    </Configuration> +    <Configuration Name="Release" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> +      <Compiler Options="-O2;-Wall" C_Options="-O2;-Wall" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags=""> +        <IncludePath Value="."/> +      </Compiler> +      <Linker Options="" Required="yes"/> +      <ResourceCompiler Options="" Required="no"/> +      <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/> +      <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>"> +        <![CDATA[]]> +      </Environment> +      <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath=""> +        <PostConnectCommands/> +        <StartupCommands/> +      </Debugger> +      <PreBuild/> +      <PostBuild/> +      <CustomBuild Enabled="no"> +        <RebuildCommand/> +        <CleanCommand/> +        <BuildCommand/> +        <PreprocessFileCommand/> +        <SingleFileCommand/> +        <MakefileGenerationCommand/> +        <ThirdPartyToolName>None</ThirdPartyToolName> +        <WorkingDirectory/> +      </CustomBuild> +      <AdditionalRules> +        <CustomPostBuild/> +        <CustomPreBuild/> +      </AdditionalRules> +      <Completion EnableCpp11="no"> +        <ClangCmpFlagsC/> +        <ClangCmpFlags/> +        <ClangPP/> +        <SearchPaths/> +      </Completion> +    </Configuration> +  </Settings> +</CodeLite_Project>  | 
