very first unit test
authorAleš Křenek <ljocha@ics.muni.cz>
Tue, 31 Aug 2004 07:57:17 +0000 (07:57 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Tue, 31 Aug 2004 07:57:17 +0000 (07:57 +0000)
org.glite.lb.common/Makefile
org.glite.lb.common/project/configure.properties.xml
org.glite.lb.common/test/parse.cpp.T [new file with mode: 0644]

index b08a231..75779b8 100644 (file)
@@ -19,9 +19,10 @@ ares_prefix=/opt/ares
 
 -include Makefile.inc
 
-VPATH=${top_srcdir}/src
+VPATH=${top_srcdir}/src:${top_srcdir}/test
 AT3=perl -I${top_srcdir}/project ${top_srcdir}/project/at3
 
+
 SUFFIXES = .T
 
 DEBUG:=-g -O0 -Wall
@@ -33,20 +34,30 @@ CFLAGS:=${DEBUG} -I${top_srcdir}/src -I${top_srcdir}/interface \
        -I${glite_location}/include \
        -I${expat_prefix}/include \
        -I${ares_prefix}/include \
+       ${COVERAGE_FLAGS} \
        -DDATAGRID_EXTENSION
 
+GLOBUS_LIBS:=-L${globus_prefix}/lib \
+        -lglobus_common_${nothrflavour} \
+        -lglobus_gssapi_gsi_${nothrflavour} \
+
 GLITE_LIBS:=-L${glite_location}/lib
-GLOBUS_LIBS:=-L${globus_prefix}/lib
-EXPAT_LIBS:=-L${expat_prefix}/lib
-ARES_LIBS:=-L${ares_prefix}/lib
+EXPAT_LIBS:=-L${expat_prefix}/lib -lexpat
+ARES_LIBS:=-L${ares_prefix}/lib -lares
 LDFLAGS:=-L${stagedir}/lib \
     ${GLITE_LIBS} \
     ${GLOBUS_LIBS} \
     ${EXPAT_LIBS} \
-    ${ARES_LIBS}
+    ${ARES_LIBS} \
+    ${COVERAGE_FLAGS}
+
+TEST_LIBS:=-L${cppunit}/lib -lcppunit
+TEST_INC:=-I${cppunit}/include
+
     
 COMPILE:=libtool --mode=compile ${CC} ${CFLAGS}
 LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/lib ${LDFLAGS} 
+LINKXX:=libtool --mode=link ${CXX} -rpath ${stagedir}/lib ${LDFLAGS} 
 INSTALL:=libtool --mode=install install
 
 OBJS:=lb_gss.o escape.o events.o mini_http.o query_rec.o status.o \
@@ -92,8 +103,11 @@ ${THRLTLIB}: ${THROBJS}
 stage: compile
        $(MAKE) install PREFIX=${stagedir}
 
-check:
-       echo Unit tests missing
+check: check.parse
+
+check.parse: parse.cpp
+       ${CXX} -c ${CFLAGS} ${TEST_INC} $<
+       ${LINKXX} -o $@ parse.o ${LTLIB} ${TEST_LIBS}
 
 dist: distsrc distbin
 
@@ -133,3 +147,8 @@ clean:
        rm -f $@
        ${AT3} $< >$@ || rm -f $@
        chmod -w $@ >/dev/null
+
+%.cpp: %.cpp.T
+       rm -f $@
+       ${AT3} $< >$@ || rm -f $@
+       chmod -w $@ >/dev/null
index 6a4ed99..911dfcf 100644 (file)
@@ -20,6 +20,9 @@
 
        Revision history:
        $Log$
+       Revision 1.2  2004/07/06 20:50:10  flammer
+       Moved to configure.properties.xml
+       
        
 -->
 
@@ -48,6 +51,7 @@ expat_prefix=${with.expat.prefix}
 ares_prefix=${with.ares.prefix}
 thrflavour=${with.globus.thr.flavor}
 nothrflavour=${with.globus.nothr.flavor}
+cppunit=${with.cppunit.prefix}
                        </echo>
            </target>
        </project>
diff --git a/org.glite.lb.common/test/parse.cpp.T b/org.glite.lb.common/test/parse.cpp.T
new file mode 100644 (file)
index 0000000..0b7802e
--- /dev/null
@@ -0,0 +1,121 @@
+#include <iostream>
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+
+#include <glite/lb/producer.h>
+#include <glite/lb/events_parse.h>
+
+class EventParseTest: public  CppUnit::TestFixture
+{
+       CPPUNIT_TEST_SUITE(EventParseTest);
+       CPPUNIT_TEST(regJob);
+       CPPUNIT_TEST_SUITE_END();
+
+public:
+       void regJob();
+
+
+};
+
+static char * compare_events(const edg_wll_Event *e1, const edg_wll_Event *e2)
+{
+       if (e1->any.type != e2->any.type) return "type";
+@@@{
+       selectType $event '_common_';
+       for ($event->getFieldsOrdered) {
+               my $f = selectField $event $_;
+               my $fn = getName $f;
+               my $ft = $f->{type};
+
+               my $a = "e1->any.$fn";
+               my $b = "e2->any.$fn";
+
+               gen "\tif (!(".eval($main::compare{C}->{$ft}).")) return \"$fn\";\n";
+       }
+       
+       gen "\tswitch(e1->any.type) {\n";
+       for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} }
+               $event->getTypes)
+       {
+               my $tu = uc $t;
+               my $tl = lcfirst $t;
+
+               selectType $event $t;
+               gen "\t\tcase EDG_WLL_EVENT\_$tu :\n";
+               for ($event->getFieldsOrdered) {
+                       my $f = selectField $event $_;
+                       my $fn = $f->{name};
+                       my $ft = $f->{type};
+
+                       my $a = "e1->$tl.$fn";
+                       my $b = "e2->$tl.$fn";
+
+                       gen "\t\t\tif (!(".eval($main::compare{C}->{$ft}).")) return \"$fn\";\n";
+               }
+               gen "\t\tbreak;\n";
+       }
+@@@}
+               default: return "default";
+       } /* switch */
+       return NULL;
+}
+
+void EventParseTest::regJob()
+{
+       edg_wll_Context ctx;
+       edg_wll_Event   *e1,*e2;
+       char    *line,*et,*ed;
+
+       edg_wll_InitContext(&ctx);
+       e1 = edg_wll_InitEvent(EDG_WLL_EVENT_REGJOB);
+       e1->any.type = EDG_WLL_EVENT_REGJOB;
+
+       e1->regJob.jdl = strdup("very long job = \"blabla\" \\\\ \n hugh\t;");
+       e1->regJob.ns = strdup("ns address");
+       e1->regJob.jobtype = EDG_WLL_REGJOB_SIMPLE;
+       e1->regJob.seed = strdup("");
+
+       gettimeofday(&e1->any.timestamp,NULL);
+       
+       e1->any.host = strdup("some.host");
+       e1->any.level = 7;
+       e1->any.priority = 0;
+       edg_wlc_JobIdParse("https://some.host:1234/x67qr549qc",&e1->any.jobId);
+       e1->any.seqcode = EDG_WLL_SEQ_BIGHELPER_INITIAL;
+       e1->any.user = strdup("/O=Grid/CN=This User");
+       e1->any.source = EDG_WLL_SOURCE_USER_INTERFACE;
+       e1->any.src_instance = strdup("");
+
+       line = edg_wll_UnparseEvent(ctx,e1);
+       std::cerr << line << std::endl;
+       if (!line) {
+               edg_wll_Error(ctx,&et,&ed);
+               std::cerr << "UnparseEvent(): " << et << " " << ed << std::endl;
+               CPPUNIT_ASSERT(0);
+       }
+       if (edg_wll_ParseEvent(ctx,line,&e2)) {
+               edg_wll_Error(ctx,&et,&ed);
+               std::cerr << "ParseEvent(): " << et << " " << ed << std::endl;
+               CPPUNIT_ASSERT(0);
+       }
+
+       if ((et = compare_events(e1,e2))) {
+               std::cerr << et << std::endl;
+               CPPUNIT_ASSERT(0);
+       }
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION( EventParseTest );
+
+int main (int ac,const char *av[])
+{
+       CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
+       CppUnit::TextUi::TestRunner runner;
+       
+       runner.addTest(suite);
+       return runner.run() ? 0 : 1;
+}