Author: kpvdr
Date: 2007-11-11 14:34:55 -0500 (Sun, 11 Nov 2007)
New Revision: 1283
Added:
store/trunk/cpp/tests/jrnl/unit_test_jerrno.cpp
store/trunk/cpp/tests/jrnl/unit_test_jexception.cpp
store/trunk/cpp/tests/jrnl/unit_test_jinf.cpp
Removed:
store/trunk/cpp/tests/jrnl/JournalUnitTests.cpp
Modified:
store/trunk/cpp/lib/jrnl/jcntl.cpp
store/trunk/cpp/lib/jrnl/jinf.cpp
store/trunk/cpp/lib/jrnl/jinf.hpp
store/trunk/cpp/tests/jrnl/
store/trunk/cpp/tests/jrnl/Makefile.am
store/trunk/cpp/tests/system_test.sh
Log:
Added boost test framework unit tests for some journal classes.
Modified: store/trunk/cpp/lib/jrnl/jcntl.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.cpp 2007-11-10 13:25:32 UTC (rev 1282)
+++ store/trunk/cpp/lib/jrnl/jcntl.cpp 2007-11-11 19:34:55 UTC (rev 1283)
@@ -364,14 +364,7 @@
throw jexception(jerrno::JERR__RTCLOCK, ss.str().c_str(), "jcntl",
"write_infofile");
}
jinf ji(_jid, _jdir.dirname(), _base_filename, ts);
- std::stringstream fn;
- fn << _jdir << "/" << _base_filename <<
"." << JRNL_INFO_EXTENSION;
- std::ofstream of(fn.str().c_str(), std::ofstream::out | std::ofstream::trunc);
- if (!of.good())
- throw jexception(jerrno::JERR__FILEIO, fn.str().c_str(), "jcntl",
"write_infofile");
- std::string s;
- of << ji.xml_str(s);
- of.close();
+ ji.write();
}
#define AIO_CMPL_SLEEP 10000 // 10 ms
Modified: store/trunk/cpp/lib/jrnl/jinf.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jinf.cpp 2007-11-10 13:25:32 UTC (rev 1282)
+++ store/trunk/cpp/lib/jrnl/jinf.cpp 2007-11-11 19:34:55 UTC (rev 1283)
@@ -185,6 +185,18 @@
return _start_file;
}
+void
+jinf::write()
+{
+ std::stringstream fn;
+ fn << _jdir << "/" << _base_filename <<
"." << JRNL_INFO_EXTENSION;
+ std::ofstream of(fn.str().c_str(), std::ofstream::out | std::ofstream::trunc);
+ if (!of.good())
+ throw jexception(jerrno::JERR__FILEIO, fn.str().c_str(), "jcntl",
"write_infofile");
+ of << xml_str();
+ of.close();
+}
+
const u_int16_t
jinf::get_start_file() throw (jexception)
{
@@ -193,8 +205,8 @@
return _start_file;
}
-const std::string&
-jinf::to_string(std::string& s) const
+const std::string
+jinf::to_string() const
{
std::stringstream ss;
ss << std::setfill('0');
@@ -215,20 +227,19 @@
ss << " Read page size (JRNL_RMGR_PAGE_SIZE): " <<
_rmgr_page_size_dblks << " dblks" <<
std::endl;
ss << " Number of read pages (JRNL_RMGR_PAGES): " <<
_rmgr_num_pages << std::endl;
- s.assign(ss.str());
- return s;
+ return ss.str();
}
-const std::string&
-jinf::xml_str(std::string& s) const
+const std::string
+jinf::xml_str() const
{
std::stringstream ss;
// TODO: I'm sure a more elegant way can be found to do this, but direct and
simple
// seems like a good start!
ss << std::setfill('0');
- ss << "<?xml version=\"1.0\"?>" << std::endl;
+ ss << "<?xml version=\"1.0\" ?>" << std::endl;
ss << "<jrnl>" << std::endl;
- ss << " <journal_version value=\"" << (unsigned)_jver
<< "\"/>" << std::endl;
+ ss << " <journal_version value=\"" << (unsigned)_jver
<< "\" />" << std::endl;
ss << " <journal_id>" << std::endl;
ss << " <id_string value=\"" << _jid <<
"\" />" << std::endl;
ss << " <directory value=\"" << _jdir <<
"\" />" << std::endl;
@@ -254,8 +265,7 @@
ss << " <JRNL_RMGR_PAGES value=\"" <<
_rmgr_num_pages << "\" />" << std::endl;
ss << " </journal_file_geometry>" << std::endl;
ss << "</jrnl>" << std::endl;
- s.assign(ss.str());
- return s;
+ return ss.str();
}
void
@@ -295,13 +305,13 @@
_rmgr_page_size_dblks = u_int32_value(buff);
else if(::strstr(buff, "JRNL_RMGR_PAGES"))
_rmgr_num_pages = u_int32_value(buff);
+ else if(::strstr(buff, "nanoseconds"))
+ _ts.tv_nsec = u_int32_value(buff);
else if(::strstr(buff, "seconds"))
{
_ts.tv_sec = u_int32_value(buff);
_tm_ptr = ::localtime(&_ts.tv_sec);
}
- else if(::strstr(buff, "nanoseconds"))
- _ts.tv_nsec = u_int32_value(buff);
}
jinfs.close();
}
Modified: store/trunk/cpp/lib/jrnl/jinf.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jinf.hpp 2007-11-10 13:25:32 UTC (rev 1282)
+++ store/trunk/cpp/lib/jrnl/jinf.hpp 2007-11-11 19:34:55 UTC (rev 1283)
@@ -66,13 +66,16 @@
u_int16_t _start_file;
public:
+ // constructor for reading existing jinf file
jinf(const std::string& jinf_filename, bool validate_flag) throw
(jexception);
+ // constructor for writing jinf file
jinf(const std::string& jid, const std::string& jdir, const
std::string& base_filename,
const timespec& ts);
~jinf();
void validate() throw (jexception);
const u_int16_t analyze() throw (jexception);
+ void write();
inline const u_int8_t jver() const { return _jver; }
inline const std::string& jid() const { return _jid; }
@@ -89,8 +92,8 @@
inline const u_int32_t rmgr_num_pages() const { return _rmgr_num_pages; }
const u_int16_t get_start_file() throw (jexception);
- const std::string& to_string(std::string& s) const;
- const std::string& xml_str(std::string& s) const;
+ const std::string to_string() const;
+ const std::string xml_str() const;
private:
void read(const std::string& jinf_filename) throw (jexception);
Property changes on: store/trunk/cpp/tests/jrnl
___________________________________________________________________
Name: svn:ignore
- .deps
.libs
Makefile
Makefile.in
jtest
+ .deps
.libs
Makefile
Makefile.in
jtest
unit_test_jerrno
unit_test_jexception
unit_test_jinf
Deleted: store/trunk/cpp/tests/jrnl/JournalUnitTests.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/JournalUnitTests.cpp 2007-11-10 13:25:32 UTC (rev 1282)
+++ store/trunk/cpp/tests/jrnl/JournalUnitTests.cpp 2007-11-11 19:34:55 UTC (rev 1283)
@@ -1,106 +0,0 @@
-/**
-* \file JournalUnitTests.cpp
-*
-* Red Hat Messaging - Message Journal
-*
-* This file contains the unit tests for the journal.
-*
-* \author Kim van der Riet
-*
-* Copyright 2007 Red Hat, Inc.
-*
-* This file is part of Red Hat Messaging.
-*
-* Red Hat Messaging is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
-* License as published by the Free Software Foundation; either
-* version 2.1 of the License, or (at your option) any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this library; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
-* USA
-*
-* The GNU Lesser General Public License is available in the file COPYING.
-*/
-
-#include "../test_plugin.h"
-
-#include <jrnl/jexception.hpp>
-
-using namespace rhm::journal;
-using namespace std;
-
-class JournalUnitTests : public CppUnit::TestCase
-{
- CPPUNIT_TEST_SUITE(JournalUnitTests);
- CPPUNIT_TEST(JournalExceptionTest);
- CPPUNIT_TEST_SUITE_END();
-
-public:
-
- void JournalExceptionTest()
- {
- {
- jexception e0;
- CPPUNIT_ASSERT_MESSAGE("e1: Error code bad.", e0.err_code() == 0);
- CPPUNIT_ASSERT_MESSAGE("e1: Additional information bad.",
e0.additional_info() == NULL);
- CPPUNIT_ASSERT_MESSAGE("e1: Throwing class bad.",
e0.throwing_class() == NULL);
- CPPUNIT_ASSERT_MESSAGE("e1: Throwing function bad.",
e0.throwing_fn() == NULL);
- }
- {
- jexception e1(1);
- CPPUNIT_ASSERT_MESSAGE("e1: Error code bad.", e1.err_code() == 1);
- CPPUNIT_ASSERT_MESSAGE("e1: Additional information bad.",
e1.additional_info() == NULL);
- CPPUNIT_ASSERT_MESSAGE("e1: Throwing class bad.",
e1.throwing_class() == NULL);
- CPPUNIT_ASSERT_MESSAGE("e1: Throwing function bad.",
e1.throwing_fn() == NULL);
- }
- {
- jexception e2("exception2");
- CPPUNIT_ASSERT_MESSAGE("e2: Error code bad.", e2.err_code() == 0);
- CPPUNIT_ASSERT_MESSAGE("e2: Additional information bad.",
- ::strcmp(e2.additional_info(), "exception2") == 0);
- CPPUNIT_ASSERT_MESSAGE("e2: Throwing class bad.",
e2.throwing_class() == NULL);
- CPPUNIT_ASSERT_MESSAGE("e2: Throwing function bad.",
e2.throwing_fn() == NULL);
- }
- {
- jexception e3(3, "exception3");
- CPPUNIT_ASSERT_MESSAGE("e3: Error code bad.", e3.err_code() == 3);
- CPPUNIT_ASSERT_MESSAGE("e3: Additional information bad.",
- ::strcmp(e3.additional_info(), "exception3") == 0);
- CPPUNIT_ASSERT_MESSAGE("e3: Throwing class bad.",
e3.throwing_class() == NULL);
- CPPUNIT_ASSERT_MESSAGE("e3: Throwing function bad.",
e3.throwing_fn() == NULL);
- }
- {
- jexception e4(4, "class4", "fn4");
- CPPUNIT_ASSERT_MESSAGE("e4: Error code bad.", e4.err_code() == 4);
- CPPUNIT_ASSERT_MESSAGE("e4: Additional information bad.",
e4.additional_info() == NULL);
- CPPUNIT_ASSERT_MESSAGE("e4: Throwing class bad.",
- ::strcmp(e4.throwing_class(), "class4") == 0);
- CPPUNIT_ASSERT_MESSAGE("e4: Throwing function bad.",
- ::strcmp(e4.throwing_fn(), "fn4") == 0);
- }
- {
- jexception e5(5, "exception5", "class5",
"fn5");
- CPPUNIT_ASSERT_MESSAGE("e5: Error code bad.", e5.err_code() == 5);
- CPPUNIT_ASSERT_MESSAGE("e5: Additional information bad.",
- ::strcmp(e5.additional_info(), "exception5") == 0);
- CPPUNIT_ASSERT_MESSAGE("e5: Throwing class bad.",
- ::strcmp(e5.throwing_class(), "class5") == 0);
- CPPUNIT_ASSERT_MESSAGE("e5: Throwing function bad.",
- ::strcmp(e5.throwing_fn(), "fn5") == 0);
- }
- }
-
-private:
-
-};
-
-// Make this test suite a plugin.
-CPPUNIT_PLUGIN_IMPLEMENT();
-CPPUNIT_TEST_SUITE_REGISTRATION(JournalUnitTests);
Modified: store/trunk/cpp/tests/jrnl/Makefile.am
===================================================================
--- store/trunk/cpp/tests/jrnl/Makefile.am 2007-11-10 13:25:32 UTC (rev 1282)
+++ store/trunk/cpp/tests/jrnl/Makefile.am 2007-11-11 19:34:55 UTC (rev 1283)
@@ -25,26 +25,40 @@
INCLUDES=-I../../lib
-TESTS = run-journal-tests
+TESTS = \
+ unit_test_jexception \
+ unit_test_jerrno \
+ unit_test_jinf \
+ run-journal-tests
check_LTLIBRARIES = \
- JournalUnitTests.la \
- JournalSystemTests.la \
- libdlclose_noop.la
+ JournalSystemTests.la \
+ libdlclose_noop.la
-JournalUnitTests_la_SOURCES = \
- JournalUnitTests.cpp
-JournalUnitTests_la_LDFLAGS = -module -rpath $(abs_builddir)
+check_PROGRAMS = \
+ unit_test_jexception \
+ unit_test_jerrno \
+ unit_test_jinf
+unit_test_jexception_SOURCES = unit_test_jexception.cpp
+unit_test_jexception_LDADD = ../../lib/.libs/jexception.o ../../lib/.libs/jerrno.o
+unit_test_jexception_LDFLAGS = -lboost_unit_test_framework
+
+unit_test_jerrno_SOURCES = unit_test_jerrno.cpp
+unit_test_jerrno_LDADD = ../../lib/.libs/jerrno.o
+unit_test_jerrno_LDFLAGS = -lboost_unit_test_framework
+
+unit_test_jinf_SOURCES = unit_test_jinf.cpp
+unit_test_jinf_LDADD = \
+ ../../lib/.libs/jinf.o \
+ ../../lib/.libs/file_hdr.o \
+ ../../lib/.libs/jexception.o \
+ ../../lib/.libs/jerrno.o
+unit_test_jinf_LDFLAGS = -lboost_unit_test_framework -lrt
+
JournalSystemTests_la_SOURCES = \
JournalSystemTests.cpp \
- jtest.cpp \
- msg_producer.cpp \
- msg_consumer.cpp \
- JournalSystemTests.hpp \
- jtest.hpp \
- msg_producer.hpp \
- msg_consumer.hpp
+ JournalSystemTests.hpp
JournalSystemTests_la_LDFLAGS = -lpthread -module -rpath $(abs_builddir)
JournalSystemTests_la_LIBADD = ../../lib/libbdbstore.la $(CPPUNIT_LIBS)
Added: store/trunk/cpp/tests/jrnl/unit_test_jerrno.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/unit_test_jerrno.cpp (rev 0)
+++ store/trunk/cpp/tests/jrnl/unit_test_jerrno.cpp 2007-11-11 19:34:55 UTC (rev 1283)
@@ -0,0 +1,65 @@
+/**
+* \file unit_test_jexception.cpp
+*
+* Red Hat Messaging - Message Journal
+*
+* This file contains the unit tests for the journal.
+*
+* \author Kim van der Riet
+*
+* Copyright 2007 Red Hat, Inc.
+*
+* This file is part of Red Hat Messaging.
+*
+* Red Hat Messaging is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+* USA
+*
+* The GNU Lesser General Public License is available in the file COPYING.
+*/
+
+#include <boost/test/results_reporter.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/unit_test_log.hpp>
+#include <iostream>
+#include <jrnl/jerrno.hpp>
+
+using namespace boost::unit_test;
+using namespace rhm::journal;
+
+// Test functions of the form
+// void fn() {...}
+
+void test_jerrno()
+{
+ const char* m = "JERR__MALLOC";
+ std::string malloc_msg = std::string(jerrno::err_msg(jerrno::JERR__MALLOC));
+ BOOST_CHECK(malloc_msg.substr(0, ::strlen(m)).compare(m) == 0);
+ BOOST_CHECK(::strcmp(jerrno::err_msg(0), "<Unknown error code>") ==
0);
+}
+
+// Initialize test suite and include test functions
+
+test_suite* init_unit_test_suite(int, char**)
+{
+ std::cout << "--------" << std::endl <<
"unit_test_jerrno: ";
+ test_suite* ts = BOOST_TEST_SUITE("unit_test_jerrno");
+
+ results_reporter::set_level(SHORT_REPORT);
+ unit_test_log_t::instance().set_threshold_level(log_messages);
+
+ ts->add(BOOST_TEST_CASE(&test_jerrno));
+
+ return ts;
+}
Added: store/trunk/cpp/tests/jrnl/unit_test_jexception.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/unit_test_jexception.cpp (rev 0)
+++ store/trunk/cpp/tests/jrnl/unit_test_jexception.cpp 2007-11-11 19:34:55 UTC (rev
1283)
@@ -0,0 +1,205 @@
+/**
+* \file unit_test_jexception.cpp
+*
+* Red Hat Messaging - Message Journal
+*
+* This file contains the unit tests for the journal.
+*
+* \author Kim van der Riet
+*
+* Copyright 2007 Red Hat, Inc.
+*
+* This file is part of Red Hat Messaging.
+*
+* Red Hat Messaging is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+* USA
+*
+* The GNU Lesser General Public License is available in the file COPYING.
+*/
+
+#include <boost/test/results_reporter.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/unit_test_log.hpp>
+#include <iostream>
+#include <jrnl/jexception.hpp>
+
+using namespace boost::unit_test;
+using namespace rhm::journal;
+
+// Test functions of the form
+// void fn() {...}
+
+void test_constructor_1()
+{
+ try
+ {
+ jexception e1;
+ BOOST_CHECK_EQUAL(e1.err_code(), (u_int32_t)0);
+ BOOST_CHECK(e1.additional_info() == NULL);
+ BOOST_CHECK(e1.throwing_class() == NULL);
+ BOOST_CHECK(e1.throwing_fn() == NULL);
+ BOOST_CHECK(e1.what() != NULL);
+ throw e1;
+ }
+ catch (const jexception& e)
+ {
+ BOOST_CHECK_EQUAL(e.err_code(), (u_int32_t)0);
+ BOOST_CHECK(e.additional_info() == NULL);
+ BOOST_CHECK(e.throwing_class() == NULL);
+ BOOST_CHECK(e.throwing_fn() == NULL);
+ BOOST_CHECK(e.what() != NULL);
+ }
+}
+
+void test_constructor_2()
+{
+ u_int32_t err_code = 2;
+ try
+ {
+ jexception e2(err_code);
+ BOOST_CHECK_EQUAL(e2.err_code(), err_code);
+ BOOST_CHECK(e2.additional_info() == NULL);
+ BOOST_CHECK(e2.throwing_class() == NULL);
+ BOOST_CHECK(e2.throwing_fn() == NULL);
+ BOOST_CHECK(e2.what() != NULL);
+ throw e2;
+ }
+ catch (const jexception& e)
+ {
+ BOOST_CHECK_EQUAL(e.err_code(), err_code);
+ BOOST_CHECK(e.additional_info() == NULL);
+ BOOST_CHECK(e.throwing_class() == NULL);
+ BOOST_CHECK(e.throwing_fn() == NULL);
+ BOOST_CHECK(e.what() != NULL);
+ }
+}
+
+void test_constructor_3()
+{
+ const char* err_msg = "exception3";
+ try
+ {
+ jexception e3(err_msg);
+ BOOST_CHECK_EQUAL(e3.err_code(), (u_int32_t)0);
+ BOOST_CHECK(::strcmp(e3.additional_info(), err_msg) == 0);
+ BOOST_CHECK(e3.throwing_class() == NULL);
+ BOOST_CHECK(e3.throwing_fn() == NULL);
+ BOOST_CHECK(e3.what() != NULL);
+ throw e3;
+ }
+ catch (const jexception& e)
+ {
+ BOOST_CHECK_EQUAL(e.err_code(), (u_int32_t)0);
+ BOOST_CHECK(::strcmp(e.additional_info(), err_msg) == 0);
+ BOOST_CHECK(e.throwing_class() == NULL);
+ BOOST_CHECK(e.throwing_fn() == NULL);
+ BOOST_CHECK(e.what() != NULL);
+ }
+}
+
+void test_constructor_4()
+{
+ u_int32_t err_code = 4;
+ const char* err_msg = "exception4";
+ try
+ {
+ jexception e4(err_code, err_msg);
+ BOOST_CHECK_EQUAL(e4.err_code(), err_code);
+ BOOST_CHECK(::strcmp(e4.additional_info(), err_msg) == 0);
+ BOOST_CHECK(e4.throwing_class() == NULL);
+ BOOST_CHECK(e4.throwing_fn() == NULL);
+ BOOST_CHECK(e4.what() != NULL);
+ throw e4;
+ }
+ catch (const jexception& e)
+ {
+ BOOST_CHECK_EQUAL(e.err_code(), err_code);
+ BOOST_CHECK(::strcmp(e.additional_info(), err_msg) == 0);
+ BOOST_CHECK(e.throwing_class() == NULL);
+ BOOST_CHECK(e.throwing_fn() == NULL);
+ BOOST_CHECK(e.what() != NULL);
+ }
+}
+
+void test_constructor_5()
+{
+ u_int32_t err_code = 5;
+ const char* err_class = "class5";
+ const char* err_fn = "fn5";
+ try
+ {
+ jexception e5(err_code, err_class, err_fn);
+ BOOST_CHECK_EQUAL(e5.err_code(), err_code);
+ BOOST_CHECK(e5.additional_info() == NULL);
+ BOOST_CHECK(::strcmp(e5.throwing_class(), err_class) == 0);
+ BOOST_CHECK(::strcmp(e5.throwing_fn(), err_fn) == 0);
+ BOOST_CHECK(e5.what() != NULL);
+ throw e5;
+ }
+ catch (const jexception& e)
+ {
+ BOOST_CHECK_EQUAL(e.err_code(), err_code);
+ BOOST_CHECK(e.additional_info() == NULL);
+ BOOST_CHECK(::strcmp(e.throwing_class(), err_class) == 0);
+ BOOST_CHECK(::strcmp(e.throwing_fn(), err_fn) == 0);
+ BOOST_CHECK(e.what() != NULL);
+ }
+}
+
+void test_constructor_6()
+{
+ u_int32_t err_code = 6;
+ const char* err_msg = "exception6";
+ const char* err_class = "class6";
+ const char* err_fn = "fn6";
+ try
+ {
+ jexception e6(err_code, err_msg, err_class, err_fn);
+ BOOST_CHECK_EQUAL(e6.err_code(), err_code);
+ BOOST_CHECK(::strcmp(e6.additional_info(), err_msg) == 0);
+ BOOST_CHECK(::strcmp(e6.throwing_class(), err_class) == 0);
+ BOOST_CHECK(::strcmp(e6.throwing_fn(), err_fn) == 0);
+ BOOST_CHECK(e6.what() != NULL);
+ throw e6;
+ }
+ catch (const jexception& e)
+ {
+ BOOST_CHECK_EQUAL(e.err_code(), err_code);
+ BOOST_CHECK(::strcmp(e.additional_info(), err_msg) == 0);
+ BOOST_CHECK(::strcmp(e.throwing_class(), err_class) == 0);
+ BOOST_CHECK(::strcmp(e.throwing_fn(), err_fn) == 0);
+ BOOST_CHECK(e.what() != NULL);
+ }
+}
+
+// Initialize test suite and include test functions
+
+test_suite* init_unit_test_suite(int, char**)
+{
+ std::cout << "--------" << std::endl <<
"unit_test_jexception: ";
+ test_suite* ts = BOOST_TEST_SUITE("unit_test_jexception");
+
+ results_reporter::set_level(SHORT_REPORT);
+ unit_test_log_t::instance().set_threshold_level(log_messages);
+
+ ts->add(BOOST_TEST_CASE(&test_constructor_1));
+ ts->add(BOOST_TEST_CASE(&test_constructor_2));
+ ts->add(BOOST_TEST_CASE(&test_constructor_3));
+ ts->add(BOOST_TEST_CASE(&test_constructor_4));
+ ts->add(BOOST_TEST_CASE(&test_constructor_5));
+ ts->add(BOOST_TEST_CASE(&test_constructor_6));
+
+ return ts;
+}
Added: store/trunk/cpp/tests/jrnl/unit_test_jinf.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/unit_test_jinf.cpp (rev 0)
+++ store/trunk/cpp/tests/jrnl/unit_test_jinf.cpp 2007-11-11 19:34:55 UTC (rev 1283)
@@ -0,0 +1,257 @@
+/**
+* \file unit_test_jexception.cpp
+*
+* Red Hat Messaging - Message Journal
+*
+* This file contains the unit tests for the journal.
+*
+* \author Kim van der Riet
+*
+* Copyright 2007 Red Hat, Inc.
+*
+* This file is part of Red Hat Messaging.
+*
+* Red Hat Messaging is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+* USA
+*
+* The GNU Lesser General Public License is available in the file COPYING.
+*/
+
+#include <boost/test/results_reporter.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/unit_test_log.hpp>
+#include <fstream>
+#include <iostream>
+#include <jrnl/file_hdr.hpp>
+#include <jrnl/jcfg.hpp>
+#include <jrnl/jerrno.hpp>
+#include <jrnl/jexception.hpp>
+#include <jrnl/jinf.hpp>
+
+using namespace boost::unit_test;
+using namespace rhm::journal;
+
+// Test functions of the form
+// void fn() {...}
+
+const std::string jid("test journal id");
+const std::string jdir("/tmp");
+const std::string base_filename("test_base");
+timespec ts;
+enum rid_scheme { RID_NONE, RID_LINEAR };
+
+// Helper functions
+void create_journal_filenames(std::vector<std::string>& jfiles);
+void create_journal_files(std::vector<std::string>& jfiles, rid_scheme scheme,
+ u_int32_t min_fid_offs = 0, u_int64_t rid_offs = 0);
+void clean_journal_files(std::vector<std::string>& jfiles);
+void init_fhdr(file_hdr& fh, u_int32_t fid, u_int64_t rid, bool no_enq = false);
+void clean_journal_info_file();
+
+
+void test_write_constructor()
+{
+ ::clock_gettime(CLOCK_REALTIME, &ts);
+ jinf ji(jid, jdir, base_filename, ts);
+ BOOST_CHECK_EQUAL(ji.jver(), RHM_JDAT_VERSION);
+ BOOST_CHECK(ji.jid().compare(jid) == 0);
+ BOOST_CHECK(ji.jdir().compare(jdir) == 0);
+ BOOST_CHECK(ji.base_filename().compare(base_filename) == 0);
+ timespec this_ts = ji.ts();
+ BOOST_CHECK_EQUAL(this_ts.tv_sec, ts.tv_sec);
+ BOOST_CHECK_EQUAL(this_ts.tv_nsec, ts.tv_nsec);
+ BOOST_CHECK_EQUAL(ji.num_files(), (u_int16_t)JRNL_NUM_FILES);
+ BOOST_CHECK_EQUAL(ji.fsize_sblks(), (u_int32_t)JRNL_FILE_SIZE);
+ BOOST_CHECK_EQUAL(ji.sblk_size_dblks(), (u_int16_t)JRNL_SBLK_SIZE);
+ BOOST_CHECK_EQUAL(ji.dblk_size(), (u_int32_t)JRNL_DBLK_SIZE);
+ BOOST_CHECK_EQUAL(ji.wmgr_page_size_dblks(), (u_int32_t)JRNL_WMGR_PAGE_SIZE);
+ BOOST_CHECK_EQUAL(ji.wmgr_num_pages(), (u_int32_t)JRNL_WMGR_PAGES);
+ BOOST_CHECK_EQUAL(ji.rmgr_page_size_dblks(), (u_int32_t)JRNL_RMGR_PAGE_SIZE);
+ BOOST_CHECK_EQUAL(ji.rmgr_num_pages(), (u_int32_t)JRNL_RMGR_PAGES);
+ ji.write();
+}
+
+void test_read_constructor()
+{
+ std::stringstream fn;
+ fn << jdir << "/" << base_filename << "."
<< JRNL_INFO_EXTENSION;
+ jinf ji(fn.str(), false);
+ BOOST_CHECK_EQUAL(ji.jver(), RHM_JDAT_VERSION);
+ BOOST_CHECK(ji.jid().compare(jid) == 0);
+ BOOST_CHECK(ji.jdir().compare(jdir) == 0);
+ BOOST_CHECK(ji.base_filename().compare(base_filename) == 0);
+ const timespec this_ts = ji.ts();
+ BOOST_CHECK_EQUAL(this_ts.tv_sec, ts.tv_sec);
+ BOOST_CHECK_EQUAL(this_ts.tv_nsec, ts.tv_nsec);
+ BOOST_CHECK_EQUAL(ji.num_files(), (u_int16_t)JRNL_NUM_FILES);
+ BOOST_CHECK_EQUAL(ji.fsize_sblks(), (u_int32_t)JRNL_FILE_SIZE);
+ BOOST_CHECK_EQUAL(ji.sblk_size_dblks(), (u_int16_t)JRNL_SBLK_SIZE);
+ BOOST_CHECK_EQUAL(ji.dblk_size(), (u_int32_t)JRNL_DBLK_SIZE);
+ BOOST_CHECK_EQUAL(ji.wmgr_page_size_dblks(), (u_int32_t)JRNL_WMGR_PAGE_SIZE);
+ BOOST_CHECK_EQUAL(ji.wmgr_num_pages(), (u_int32_t)JRNL_WMGR_PAGES);
+ BOOST_CHECK_EQUAL(ji.rmgr_page_size_dblks(), (u_int32_t)JRNL_RMGR_PAGE_SIZE);
+ BOOST_CHECK_EQUAL(ji.rmgr_num_pages(), (u_int32_t)JRNL_RMGR_PAGES);
+}
+
+void test_validate()
+{
+ std::stringstream fn;
+ fn << jdir << "/" << base_filename << "."
<< JRNL_INFO_EXTENSION;
+ jinf ji(fn.str(), true);
+ // TODO: Check validation picks up conflict, but need to be friend to jinf to do it
+}
+
+void test_analyze_empty_journal()
+{
+ std::vector<std::string> jfiles;
+ create_journal_filenames(jfiles);
+
+ create_journal_files(jfiles, RID_NONE);
+
+ std::stringstream fn;
+ fn << jdir << "/" << base_filename << "."
<< JRNL_INFO_EXTENSION;
+ jinf ji(fn.str(), false);
+ try { ji.analyze(); }
+ catch (jexception e)
+ {
+ if (e.err_code() != jerrno::JERR_JINF_JDATEMPTY)
+ BOOST_ERROR("Failed to throw expected exception
jerrno::JERR_JINF_JDATEMPTY");
+ }
+
+ clean_journal_files(jfiles);
+}
+
+void test_analyze_linear_journal()
+{
+ std::vector<std::string> jfiles;
+ for (int i=0; i<JRNL_NUM_FILES; i++)
+ {
+ create_journal_filenames(jfiles);
+
+ create_journal_files(jfiles, RID_LINEAR, i, 0x12340000);
+
+ std::stringstream fn;
+ fn << jdir << "/" << base_filename <<
"." << JRNL_INFO_EXTENSION;
+ jinf ji(fn.str(), false);
+ BOOST_CHECK_EQUAL(ji.analyze(), i);
+
+ clean_journal_files(jfiles);
+ }
+
+ // last test cleans up jinf file
+ clean_journal_info_file();
+}
+
+// Helper functions
+
+void create_journal_filenames(std::vector<std::string>& jfiles)
+{
+ for (int fnum=0; fnum<JRNL_NUM_FILES; fnum++)
+ {
+ std::stringstream fn;
+ fn << jdir << "/" << base_filename <<
".";
+ fn << std::setfill('0') << std::setw(4) << fnum
<< "." << JRNL_DATA_EXTENSION;
+ jfiles.push_back(fn.str());
+ }
+}
+
+void create_journal_files(std::vector<std::string>& jfiles, rid_scheme scheme,
+ u_int32_t min_fid_offs, u_int64_t rid_offs)
+{
+ const u_int64_t rid_incr = 0x10;
+ file_hdr fh;
+ std::vector<std::string>::iterator itr;
+ u_int32_t fid = 0;
+ u_int64_t rid = rid_offs + ((JRNL_NUM_FILES - min_fid_offs) % JRNL_NUM_FILES) *
rid_incr;
+ for (itr=jfiles.begin(); itr<jfiles.end(); itr++)
+ {
+
+ std::ofstream of(itr->c_str(), std::ofstream::out | std::ofstream::trunc);
+ if (!of.good())
+ BOOST_FAIL("Unable to open test journal file " << *itr
<< " for writing.");
+
+ // prepare file_hdr
+ if (scheme == RID_NONE) // create file containing 0s
+ ::memset(&fh, 0, sizeof(file_hdr));
+ else
+ init_fhdr(fh, fid, rid);
+
+ // write file header
+ int cnt = sizeof(file_hdr);
+ of.write((const char*)&fh, cnt);
+
+ // fill remaining sblk with 0s
+ while (cnt++ < JRNL_DBLK_SIZE * JRNL_SBLK_SIZE)
+ of.put(0);
+ of.close();
+
+ if (++fid == min_fid_offs)
+ rid -= rid_incr * (JRNL_NUM_FILES - 1);
+ else
+ rid += rid_incr;
+ }
+}
+
+void clean_journal_info_file()
+{
+ std::stringstream fn;
+ fn << jdir << "/" << base_filename << "."
<< JRNL_INFO_EXTENSION;
+ BOOST_WARN_MESSAGE(::unlink(fn.str().c_str()) == 0, "Failed to remove file
" << fn.str());
+}
+
+void clean_journal_files(std::vector<std::string>& jfiles)
+{
+ for (std::vector<std::string>::iterator itr=jfiles.begin(); itr !=
jfiles.end(); itr++)
+ BOOST_WARN_MESSAGE(::unlink(itr->c_str()) == 0, "Failed to remove file
" << *itr);
+ jfiles.clear();
+}
+
+void init_fhdr(file_hdr& fh, u_int32_t fid, u_int64_t rid, bool no_enq)
+{
+ fh._hdr._magic = RHM_JDAT_FILE_MAGIC;
+ fh._hdr._version = RHM_JDAT_VERSION;
+#if defined(JRNL_BIG_ENDIAN)
+ fh._hdr._eflag = RHM_BENDIAN_FLAG;
+#else
+ fh._hdr._eflag = RHM_LENDIAN_FLAG;
+#endif
+ fh._hdr._uflag = 0;
+ fh._hdr._rid = rid;
+ fh._fid = fid;
+ fh._fro = no_enq ? 0 : 0x200;
+ timespec ts;
+ ::clock_gettime(CLOCK_REALTIME, &ts);
+ fh._ts_sec = ts.tv_sec;
+ fh._ts_nsec = ts.tv_nsec;
+}
+
+// Initialize test suite and include test functions
+
+test_suite* init_unit_test_suite(int, char**)
+{
+ std::cout << "--------" << std::endl <<
"unit_test_jinf: ";
+ test_suite* ts = BOOST_TEST_SUITE("unit_test_jinf");
+
+ results_reporter::set_level(SHORT_REPORT);
+ unit_test_log_t::instance().set_threshold_level(log_messages);
+
+ ts->add(BOOST_TEST_CASE(&test_write_constructor));
+ ts->add(BOOST_TEST_CASE(&test_read_constructor));
+ ts->add(BOOST_TEST_CASE(&test_validate));
+ ts->add(BOOST_TEST_CASE(&test_analyze_empty_journal));
+ ts->add(BOOST_TEST_CASE(&test_analyze_linear_journal));
+
+ return ts;
+}
Modified: store/trunk/cpp/tests/system_test.sh
===================================================================
--- store/trunk/cpp/tests/system_test.sh 2007-11-10 13:25:32 UTC (rev 1282)
+++ store/trunk/cpp/tests/system_test.sh 2007-11-11 19:34:55 UTC (rev 1283)
@@ -21,12 +21,6 @@
#
# The GNU Lesser General Public License is available in the file COPYING.
-#temporarily disable valgrind until broker can shutdown cleanly again
-VALGRIND=
-echo ""
-echo "WARNING: valgrind temporarily disabled until broker can shutdown
cleanly!"
-echo ""
-
if ! test -d "$QPID_DIR" ; then
echo "WARNING: QPID_DIR is not set skipping system tests."
echo "To enable system tests run ./configure --with-qpid-checkout."
@@ -74,7 +68,7 @@
fi
for p in `seq 1 6`; do
log="$abs_srcdir/vg-log.$mode.$p"
- echo "$vg $QPIDD -s $LIBBDBSTORE $JRNLFLAGS"
+ #echo "$vg $QPIDD -s $LIBBDBSTORE $JRNLFLAGS"
$vg $QPIDD -s $LIBBDBSTORE $JRNLFLAGS >> "$abs_srcdir/qpid.log"
2> $log & pid=$!
sleep 5