--- /dev/null
+#include "IlTestBase.h"
+
+#include <string.h>
+
+const char *IlTestBase::msg = "DATE=20040831150159.702224 HOST=\"some.host\" PROG=edg-wms LVL=USAGE DG.PRIORITY=0 DG.SOURCE=\"UserInterface\" DG.SRC_INSTANCE=\"\" DG.EVNT=\"RegJob\" DG.JOBID=\"https://some.host:1234/x67qr549qc\" DG.SEQCODE=\"UI=2:NS=0:WM=0:BH=1:JSS=0:LM=0:LRMS=0:APP=0\" DG.USER=\"/C=CZ/O=Cesnet/CN=Michal Vocu\" DG.REGJOB.JDL=\"\" DG.REGJOB.NS=\"ns address\" DG.REGJOB.PARENT=\"\" DG.REGJOB.JOBTYPE=\"SIMPLE\" DG.REGJOB.NSUBJOBS=\"0\" DG.REGJOB.SEED=\"\"";
+
+const char *IlTestBase::msg_enc = " 429\n6 michal\n415 DATE=20040831150159.702224 HOST=\"some.host\" PROG=edg-wms LVL=USAGE DG.PRIORITY=0 DG.SOURCE=\"UserInterface\" DG.SRC_INSTANCE=\"\" DG.EVNT=\"RegJob\" DG.JOBID=\"https://some.host:1234/x67qr549qc\" DG.SEQCODE=\"UI=2:NS=0:WM=0:BH=1:JSS=0:LM=0:LRMS=0:APP=0\" DG.USER=\"/C=CZ/O=Cesnet/CN=Michal Vocu\" DG.REGJOB.JDL=\"\" DG.REGJOB.NS=\"ns address\" DG.REGJOB.PARENT=\"\" DG.REGJOB.JOBTYPE=\"SIMPLE\" DG.REGJOB.NSUBJOBS=\"0\" DG.REGJOB.SEED=\"\"\n";
+
+const struct server_msg IlTestBase::smsg = {
+ "https://some.host:1234/x67qr549qc",
+ (char*)IlTestBase::msg_enc,
+ strlen(IlTestBase::msg_enc),
+ strlen(IlTestBase::msg) + 1,
+ NULL
+};
--- /dev/null
+extern "C" {
+#include "interlogd.h"
+}
+
+class IlTestBase {
+public:
+ static const char *msg;
+ static const char *msg_enc;
+ static const struct server_msg smsg;
+};
--- /dev/null
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "IlTestBase.h"
+
+extern "C" {
+struct event_queue_msg {
+ struct server_msg *msg;
+ struct event_queue_msg *prev;
+};
+}
+
+#include <string>
+using namespace std;
+
+class event_queueTest: public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE( event_queueTest );
+ CPPUNIT_TEST( testEventQueueCreate );
+ CPPUNIT_TEST( testEventQueueInsert );
+ CPPUNIT_TEST( testEventQueueGet );
+ CPPUNIT_TEST( testEventQueueRemove );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp() {
+ server = strdup("localhost:8080");
+ eq = event_queue_create(server);
+ free(server);
+ }
+
+ void tearDown() {
+ struct event_queue_msg *mp;
+ struct server_msg *m;
+
+ for(mp = eq->head; mp != NULL; ) {
+ struct event_queue_msg *mq;
+
+ server_msg_free(mp->msg);
+ mq = mp;
+ mp = mp->prev;
+ free(mq);
+ }
+ eq->head = NULL;
+ event_queue_free(eq);
+ }
+
+ void testEventQueueCreate() {
+ CPPUNIT_ASSERT( eq != NULL );
+ CPPUNIT_ASSERT_EQUAL( string(eq->dest_name), string("localhost") );
+ CPPUNIT_ASSERT_EQUAL( eq->dest_port, 8081 );
+ CPPUNIT_ASSERT( eq->tail == NULL );
+ CPPUNIT_ASSERT( eq->head == NULL );
+ CPPUNIT_ASSERT( eq->tail_ems == NULL );
+ CPPUNIT_ASSERT( eq->mark_this == NULL );
+ CPPUNIT_ASSERT( eq->mark_prev == NULL );
+ CPPUNIT_ASSERT( eq->thread_id == 0 );
+ CPPUNIT_ASSERT( eq->flushing == 0 );
+ CPPUNIT_ASSERT( eq->flush_result == 0 );
+ }
+
+ void testEventQueueInsert() {
+ struct event_queue_msg *mp;
+ struct server_msg *m;
+
+ doSomeInserts();
+ mp = eq->head;
+ m = mp->msg;
+ CPPUNIT_ASSERT_EQUAL( string(m->job_id_s), string("2") );
+ CPPUNIT_ASSERT_EQUAL( mp, eq->tail_ems );
+ mp = mp->prev;
+ m = mp->msg;
+ CPPUNIT_ASSERT_EQUAL( string(m->job_id_s), string("1") );
+ mp = mp->prev;
+ m = mp->msg;
+ CPPUNIT_ASSERT_EQUAL( string(m->job_id_s), string("3") );
+ CPPUNIT_ASSERT_EQUAL( mp, eq->tail );
+ CPPUNIT_ASSERT( mp->prev == NULL );
+ }
+
+ void testEventQueueGet() {
+ struct event_queue_msg *mp;
+ struct server_msg *m,sm;
+ int ret;
+
+ doSomeInserts();
+ mp = eq->head;
+ eq->head = mp->prev;
+ eq->tail_ems = NULL;
+ server_msg_free(mp->msg);
+ free(mp);
+ ret = event_queue_get(eq, &m);
+ CPPUNIT_ASSERT( ret == 0 );
+ CPPUNIT_ASSERT( eq->mark_this == eq->head );
+ CPPUNIT_ASSERT( eq->mark_prev == NULL );
+ CPPUNIT_ASSERT_EQUAL( string("1"), string(m->job_id_s) );
+ sm = IlTestBase::smsg;
+ sm.job_id_s = "4";
+ sm.receipt_to = 1;
+ ret = event_queue_insert(eq, &sm);
+ CPPUNIT_ASSERT( ret == 0 );
+ CPPUNIT_ASSERT( eq->mark_prev == eq->head );
+ CPPUNIT_ASSERT( eq->mark_this == eq->head->prev );
+ ret = event_queue_insert(eq, &sm);
+ CPPUNIT_ASSERT( ret == 0 );
+ CPPUNIT_ASSERT( eq->mark_prev == eq->head->prev );
+ CPPUNIT_ASSERT( eq->mark_this == eq->head->prev->prev );
+ }
+
+ void testEventQueueRemove() {
+ struct event_queue_msg *mp;
+ struct server_msg *m,sm;
+ int ret;
+
+ doSomeInserts();
+ ret = event_queue_get(eq, &m);
+ mp = eq->mark_this->prev;
+ sm = IlTestBase::smsg;
+ sm.job_id_s = "4";
+ sm.receipt_to = 1;
+ event_queue_insert(eq, &sm);
+ ret = event_queue_remove(eq);
+ CPPUNIT_ASSERT( eq->head->prev == mp );
+ CPPUNIT_ASSERT( eq->mark_this == NULL );
+ CPPUNIT_ASSERT( eq->mark_prev == NULL );
+ }
+
+protected:
+ char *server;
+ struct event_queue *eq;
+
+ void doSomeInserts() {
+ struct server_msg m = IlTestBase::smsg;
+
+ m.job_id_s = "1";
+ event_queue_insert(eq, &m);
+ m.receipt_to = 1;
+ m.job_id_s = "2";
+ event_queue_insert(eq, &m);
+ m.job_id_s = "3";
+ m.receipt_to = 0;
+ event_queue_insert(eq, &m);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION( event_queueTest );
--- /dev/null
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "IlTestBase.h"
+
+class event_storeTest: public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE( event_storeTest );
+ CPPUNIT_TEST( event_store_recoverTest );
+ CPPUNIT_TEST( event_store_syncTest );
+ CPPUNIT_TEST( event_store_nextTest );
+ CPPUNIT_TEST( event_store_commitTest );
+ CPPUNIT_TEST( event_store_cleanTest );
+ CPPUNIT_TEST( event_store_findTest );
+ CPPUNIT_TEST( event_store_releaseTest );
+ CPPUNIT_TEST( event_store_initTest );
+ CPPUNIT_TEST( event_store_recover_allTest );
+ CPPUNIT_TEST( event_store_cleanupTest );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp() {
+ }
+
+ void tearDown() {
+ }
+
+ void event_store_recoverTest() {
+ }
+
+ void event_store_syncTest() {
+ }
+
+ void event_store_nextTest() {
+ }
+
+ void event_store_commitTest() {
+ }
+
+ void event_store_cleanTest() {
+ }
+
+ void event_store_findTest() {
+ }
+
+ void event_store_releaseTest() {
+ }
+
+ void event_store_initTest() {
+ }
+
+ void event_store_recover_allTest() {
+ }
+
+ void event_store_cleanupTest() {
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION( event_storeTest );
--- /dev/null
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+extern "C" {
+#include <pthread.h>
+#include "glite/wmsutils/tls/ssl_helpers/ssl_inits.h"
+#include "glite/wmsutils/tls/ssl_helpers/ssl_pthreads.h"
+#include "interlogd.h"
+#include "glite/lb/consumer.h"
+#include "glite/lb/lb_gss.h"
+}
+
+#if defined(IL_NOTIFICATIONS)
+#define DEFAULT_PREFIX "/tmp/notif_events"
+#define DEFAULT_SOCKET "/tmp/notif_interlogger.sock"
+#else
+#define DEFAULT_PREFIX "/tmp/dglogd.log"
+#define DEFAULT_SOCKET "/tmp/interlogger.sock"
+#endif
+
+int TIMEOUT = DEFAULT_TIMEOUT;
+
+gss_cred_id_t cred_handle = GSS_C_NO_CREDENTIAL;
+pthread_mutex_t cred_handle_lock = PTHREAD_MUTEX_INITIALIZER;
+
+char *file_prefix = DEFAULT_PREFIX;
+int bs_only = 0;
+
+char *cert_file = NULL;
+char *key_file = NULL;
+char *CAcert_dir = NULL;
+char *log_server = NULL;
+char *socket_path = DEFAULT_SOCKET;
+
+
+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;
+}
--- /dev/null
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "IlTestBase.h"
+
+extern "C" {
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+#include "interlogd.h"
+
+ extern char *socket_path;
+}
+
+#include <string>
+using namespace std;
+
+class input_queue_socketTest: public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE( input_queue_socketTest );
+ CPPUNIT_TEST( input_queue_getTest );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+
+ void setUp() {
+ struct sockaddr_un saddr;
+ int sock;
+ long offset = 0;
+
+ int ret = input_queue_attach();
+ CPPUNIT_ASSERT(ret == 0);
+
+ sock=socket(PF_UNIX, SOCK_STREAM, 0);
+ CPPUNIT_ASSERT(sock >= 0);
+
+ memset(&saddr, 0, sizeof(saddr));
+ saddr.sun_family = AF_UNIX;
+ strcpy(saddr.sun_path, socket_path);
+ ret = connect(sock, (struct sockaddr *)&saddr, sizeof(saddr.sun_path));
+ CPPUNIT_ASSERT(ret >= 0);
+
+ ret = write(sock, &offset, sizeof(offset));
+ CPPUNIT_ASSERT( ret == sizeof(offset) );
+ ret = write(sock, IlTestBase::msg, strlen(IlTestBase::msg));
+ CPPUNIT_ASSERT( ret == strlen(IlTestBase::msg) );
+ ret = write(sock, "\n", 1);
+ CPPUNIT_ASSERT( ret == 1 );
+ }
+
+ void tearDown() {
+ input_queue_detach();
+ }
+
+
+ void input_queue_getTest() {
+ char *event;
+ long offset;
+ int ret;
+
+ ret = input_queue_get(&event, &offset, 10);
+ CPPUNIT_ASSERT( ret >= 0 );
+ CPPUNIT_ASSERT_EQUAL( 0L, offset );
+ CPPUNIT_ASSERT_EQUAL( string(IlTestBase::msg), string(event) );
+ free(event);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(input_queue_socketTest);
--- /dev/null
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "IlTestBase.h"
+
+#include <string.h>
+
+using namespace std;
+
+class server_msgTest: public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(server_msgTest);
+ CPPUNIT_TEST( server_msg_createTest );
+ CPPUNIT_TEST( server_msg_copyTest );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+
+ void setUp() {
+ msg = server_msg_create((char *)IlTestBase::msg);
+ }
+
+ void tearDown() {
+ server_msg_free(msg);
+ }
+
+ void server_msg_createTest() {
+ CPPUNIT_ASSERT( msg != NULL );
+ CPPUNIT_ASSERT_EQUAL( string(msg->job_id_s), string(IlTestBase::smsg.job_id_s) );
+ CPPUNIT_ASSERT_EQUAL( string(msg->msg), string(IlTestBase::smsg.msg) );
+ CPPUNIT_ASSERT_EQUAL( msg->len, IlTestBase::smsg.len );
+ CPPUNIT_ASSERT_EQUAL( msg->ev_len, IlTestBase::smsg.ev_len );
+ CPPUNIT_ASSERT_EQUAL( msg->es, IlTestBase::smsg.es );
+ CPPUNIT_ASSERT( !server_msg_is_priority(msg) );
+ }
+
+ void server_msg_copyTest() {
+ struct server_msg *msg2;
+
+ msg2 = server_msg_copy(msg);
+ CPPUNIT_ASSERT( msg2 != NULL );
+ CPPUNIT_ASSERT( msg2 != msg );
+ CPPUNIT_ASSERT_EQUAL( string(msg->job_id_s), string(msg2->job_id_s) );
+ CPPUNIT_ASSERT( msg->job_id_s != msg2->job_id_s);
+ CPPUNIT_ASSERT_EQUAL( string(msg->msg), string(msg2->msg) );
+ CPPUNIT_ASSERT( msg->msg != msg2->msg );
+ CPPUNIT_ASSERT_EQUAL( msg->len, msg2->len );
+ CPPUNIT_ASSERT_EQUAL( msg->ev_len, msg2->ev_len );
+ CPPUNIT_ASSERT_EQUAL( msg->es, msg2->es );
+ server_msg_free(msg2);
+ }
+
+private:
+ struct server_msg *msg;
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(server_msgTest);