From 3a685bb61321ffd442cd7961662adf9cc98cef0b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Voc=C5=AF?= Date: Tue, 31 Aug 2004 15:44:39 +0000 Subject: [PATCH] * first shot at unit testing of il_* protocol suite --- org.glite.lb.common/test/il_int_test.cpp | 43 +++++++++++++++++++++++++++ org.glite.lb.common/test/il_string_test.cpp | 45 +++++++++++++++++++++++++++++ org.glite.lb.common/test/il_test.cpp | 15 ++++++++++ 3 files changed, 103 insertions(+) create mode 100644 org.glite.lb.common/test/il_int_test.cpp create mode 100644 org.glite.lb.common/test/il_string_test.cpp create mode 100644 org.glite.lb.common/test/il_test.cpp diff --git a/org.glite.lb.common/test/il_int_test.cpp b/org.glite.lb.common/test/il_int_test.cpp new file mode 100644 index 0000000..af486f4 --- /dev/null +++ b/org.glite.lb.common/test/il_int_test.cpp @@ -0,0 +1,43 @@ +#include + + +extern "C" { +#include "edg/workload/logging/common/il_string.h" +} + +class IlIntTest: public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( IlIntTest ); + CPPUNIT_TEST( testPutInt ); + CPPUNIT_TEST( testGetInt ); + CPPUNIT_TEST( testLenInt ); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() { + } + + void tearDown() { + } + + void testPutInt() { + put_int(buffer, 17); + CPPUNIT_ASSERT(!strcmp(buffer, "17\n")); + } + + void testGetInt() { + int d; + get_int("17\n", &d); + CPPUNIT_ASSERT(d == 17); + } + + void testLenInt() { + CPPUNIT_ASSERT(3 == len_int(17)); + } + +protected: + char buffer[255]; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( IlIntTest ) ; + diff --git a/org.glite.lb.common/test/il_string_test.cpp b/org.glite.lb.common/test/il_string_test.cpp new file mode 100644 index 0000000..3220726 --- /dev/null +++ b/org.glite.lb.common/test/il_string_test.cpp @@ -0,0 +1,45 @@ +#include + + +extern "C" { +#include "edg/workload/logging/common/il_string.h" +} + +class IlStringTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( IlStringTest ); + CPPUNIT_TEST( testPutString ); + CPPUNIT_TEST( testGetString ); + CPPUNIT_TEST( testLenString ); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() { + } + + void tearDown() { + } + + void testPutString() { + put_string(buffer, "ahoj"); + CPPUNIT_ASSERT( !strcmp(buffer, "4 ahoj\n") ); + } + + void testGetString() { + char *s; + get_string("4 ahoj\n", &s); + CPPUNIT_ASSERT( s != NULL ); + CPPUNIT_ASSERT( !strcmp(s, "ahoj") ); + free(s); + } + + void testLenString() { + int d = len_string("ahoj"); + CPPUNIT_ASSERT( d == 7); + } + +private: + char buffer[255]; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( IlStringTest ); diff --git a/org.glite.lb.common/test/il_test.cpp b/org.glite.lb.common/test/il_test.cpp new file mode 100644 index 0000000..794c0a0 --- /dev/null +++ b/org.glite.lb.common/test/il_test.cpp @@ -0,0 +1,15 @@ +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); + CppUnit::TextTestRunner runner; + + runner.addTest(suite); + runner.setOutputter(CppUnit::CompilerOutputter::defaultOutputter(&runner.result(), std::cerr)); + + return runner.run() ? 0 : 1; +} -- 1.8.2.3