From 71054e06eae56ad963bc87fe02f2df31e3f6ec0a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Voc=C5=AF?= Date: Thu, 10 Feb 2005 18:09:26 +0000 Subject: [PATCH] * unit tests of the IL communication library --- org.glite.lb.common/Makefile | 4 +- org.glite.lb.common/test/il_msg_test.cpp | 91 ++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 org.glite.lb.common/test/il_msg_test.cpp diff --git a/org.glite.lb.common/Makefile b/org.glite.lb.common/Makefile index 665ef8e..810aa76 100644 --- a/org.glite.lb.common/Makefile +++ b/org.glite.lb.common/Makefile @@ -150,7 +150,7 @@ check.il: il_test test_gss: test_gss.o ${LINKXX} -o $@ test_gss.o ${LTLIB} ${TEST_LIBS} ${EXT_LIBS} -il_test: il_test.o il_int_test.o il_string_test.o +il_test: il_test.o il_int_test.o il_string_test.o il_msg_test.o ${LINKXX} -o $@ $+ ${LTLIB} ${TEST_LIBS} ${EXT_LIBS} test_coverage: @@ -191,7 +191,7 @@ clean: test_gss.o: %.o: %.cpp ${CXX} -c ${CFLAGS} ${GLOBUSINC} ${TEST_INC} $< -il_int_test.o il_string_test.o il_test.o: %.o: %.cpp +il_int_test.o il_string_test.o il_test.o il_msg_test.o: %.o: %.cpp ${CXX} -c ${CFLAGS} ${TEST_INC} $< %.thr.o: %.c diff --git a/org.glite.lb.common/test/il_msg_test.cpp b/org.glite.lb.common/test/il_msg_test.cpp new file mode 100644 index 0000000..c8452f4 --- /dev/null +++ b/org.glite.lb.common/test/il_msg_test.cpp @@ -0,0 +1,91 @@ +#include +#include + +extern "C" { +#include "il_string.h" +#include "il_msg.h" +} + +class IlMsgTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE ( IlMsgTest ); + CPPUNIT_TEST( testEncodeMsg ); + CPPUNIT_TEST( testDecodeMsg ); + CPPUNIT_TEST( testEncodeReply ); + CPPUNIT_TEST( testDecodeReply ); + CPPUNIT_TEST( testReadData ); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() { + len_msg = encode_il_msg(&buffer_msg, "zprava"); + len_rep = encode_il_reply(&buffer_rep, 10, 20, "chyba"); + } + + void tearDown() { + free(buffer_msg); + free(buffer_rep); + } + + void testEncodeMsg() { + CPPUNIT_ASSERT_EQUAL(len_msg, 26); + CPPUNIT_ASSERT(buffer_msg != NULL); + CPPUNIT_ASSERT(!strncmp(buffer_msg, msg, len_msg)); + } + + void testDecodeMsg() { + char *s; + int l; + + l = decode_il_msg(&s, buffer_msg + 17); + CPPUNIT_ASSERT_EQUAL(l, len_msg - 17); + CPPUNIT_ASSERT(s != NULL); + CPPUNIT_ASSERT( !strcmp(s, "zprava") ); + free(s); + } + + void testEncodeReply() { + } + + void testDecodeReply() { + char *s; + int m, n, l; + + l = decode_il_reply(&m, &n, &s, buffer_rep + 17); + CPPUNIT_ASSERT_EQUAL(l, len_rep - 17); + CPPUNIT_ASSERT_EQUAL(m, 10); + CPPUNIT_ASSERT_EQUAL(n, 20); + CPPUNIT_ASSERT( s != NULL ); + CPPUNIT_ASSERT( !strcmp(s, "chyba") ); + free(s); + } + + void testReadData() { + int l; + char *s; + + l = read_il_data(&s, test_reader); + CPPUNIT_ASSERT_EQUAL(l, 9); + CPPUNIT_ASSERT(s != NULL); + CPPUNIT_ASSERT(!strcmp(s, "6 zprava\n")); + free(s); + } + +private: + int len_msg, len_rep; + char *buffer_msg, *buffer_rep; + static const char *msg, *rep; + + static int pos; + static int test_reader(char *buf, int len) { + strncpy(buf, msg+pos, len); + pos += len; + return(len); + } +}; + +const char *IlMsgTest::msg = " 9\n6 zprava\n"; +const char *IlMsgTest::rep = ""; +int IlMsgTest::pos; + +CPPUNIT_TEST_SUITE_REGISTRATION( IlMsgTest ); -- 1.8.2.3