Commit e7bb6984 authored by baire's avatar baire
Browse files

added a simple test case for SipUrl and decode the "sip:" prefix

parent 4f7e7db4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ T3DK_CXX_SOURCES = $(wildcard *.cpp)

T3DK_CDGEN_HEADER	= codec.h

#T3DK_CODETS		= c++/codet.cpp
T3DK_CODETS		= sip_codets.cpp

CPPFLAGS		= -I. -I/opt/boost-mingw/include

+1 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ namespace t3devlib {
	void SAInit()
	{	
		Port::RegisterType ("TestSystem", "SipPort", &createPort<EchoPort>);
		Port::RegisterType ("TestSystem", "SipTestPort", &createPort<EchoPort>);
	}

	void CDInit()
+62 −0
Original line number Diff line number Diff line
#include "gen_classes.h"

#include <regex.h>


namespace t3devlib { namespace gen {

class Regex {
public:
	Regex(const char* regex) {

		if (regcomp (&mRegex, regex, 0)) 
		{
			std::cerr << "bad regex: " << regex << endl;
			abort();
		}
	}

	bool Match (Buffer& buffer) {

		const char* start =  buffer.GetValue().c_str() + (buffer.GetPosition() / 8);

		return !regexec (&mRegex, start, 16, mMatches, 0);
	}

	int GetMatchedLength() {
		return (mMatches[0].rm_eo - mMatches[0].rm_so)*8;
	}

	void Error (Variable* v, Buffer& buffer) throw (DecodeError) {
		const char* start =  buffer.GetValue().c_str() + (buffer.GetPosition() / 8);

		std::string message ("cannot match regex in '");
		message.append (start, 8);
		message += "...'";
		throw DecodeError (v, message);
	}

private:
	regex_t		mRegex;
	regmatch_t	mMatches[16];
};

void SipUrl::PreDecodeField (int id, Buffer& buffer) throw (DecodeError)
{

	static Regex reg_scheme ("^sip:");

	switch (id) {
	case id_scheme:
		if (reg_scheme.Match (buffer)) {
			SetHypFieldLength (id_scheme, reg_scheme.GetMatchedLength());
		} else {
			reg_scheme.Error (this, buffer);
		}
		break;

	}
}


}} // namespaces
+40 −0
Original line number Diff line number Diff line
module Simple_Testcases
{
  	import from TestSystem all;
  	import from LibSip_SIPTypesAndValues all;
//  	import from Simple_Templates all;


	template SipUrl m_simpleUrl (charstring user, charstring host) := {
		scheme :=	"sip:",
		userInfo := {
        	       userOrTelephoneSubscriber := user,
        	       password := omit
		},
		hostPort := {
			host := host,
			portField := omit
		},
		urlParameters := omit,
		headers :=	omit
	}
	
	testcase TC_SIMPLE_0001() runs on SipTest system SipTest {

		// Preamble
		connect (self:testPort, self:testPort);

		// Test Body
		testPort.send ("sip:user@host");
	
		alt {
			[] testPort.receive (m_simpleUrl ("user", "host")) {
				setverdict (pass);
			}
			[] testPort.receive (SipUrl: ?) {
				setverdict (fail);
			}
		}

	}
}
+3 −0
Original line number Diff line number Diff line
@@ -6,11 +6,14 @@
 */
module TestExecution { 
	
	import from Simple_Testcases { testcase all } ;
	import from Sanity_Testcases { testcase all } ;
	import from LibSip_SIPTypesAndValues all;

  control {

  	execute(TC_SIMPLE_0001());

	execute(TC_SANITY_0001());
	execute(TC_SANITY_0002());

Loading