Author: kpvdr
Date: 2007-11-12 23:13:39 -0500 (Mon, 12 Nov 2007)
New Revision: 1293
Added:
store/trunk/cpp/tests/jrnl/unit_test_jdir.cpp
Modified:
store/trunk/cpp/tests/jrnl/Makefile.am
store/trunk/cpp/tests/jrnl/unit_test_jerrno.cpp
store/trunk/cpp/tests/jrnl/unit_test_jinf.cpp
Log:
Some unit tests for class jdir
Modified: store/trunk/cpp/tests/jrnl/Makefile.am
===================================================================
--- store/trunk/cpp/tests/jrnl/Makefile.am 2007-11-12 22:57:21 UTC (rev 1292)
+++ store/trunk/cpp/tests/jrnl/Makefile.am 2007-11-13 04:13:39 UTC (rev 1293)
@@ -29,6 +29,7 @@
unit_test_jexception \
unit_test_jerrno \
unit_test_jinf \
+ unit_test_jdir \
run-journal-tests
check_LTLIBRARIES = \
@@ -38,7 +39,8 @@
check_PROGRAMS = \
unit_test_jexception \
unit_test_jerrno \
- unit_test_jinf
+ unit_test_jinf \
+ unit_test_jdir
unit_test_jexception_SOURCES = unit_test_jexception.cpp
unit_test_jexception_LDFLAGS = -lboost_unit_test_framework -lbdbstore -L../../lib/.libs
@@ -49,6 +51,9 @@
unit_test_jinf_SOURCES = unit_test_jinf.cpp
unit_test_jinf_LDFLAGS = -lboost_unit_test_framework -lbdbstore -lrt -L../../lib/.libs
+unit_test_jdir_SOURCES = unit_test_jdir.cpp
+unit_test_jdir_LDFLAGS = -lboost_unit_test_framework -lbdbstore -lrt -L../../lib/.libs
+
JournalSystemTests_la_SOURCES = \
JournalSystemTests.cpp \
JournalSystemTests.hpp
Added: store/trunk/cpp/tests/jrnl/unit_test_jdir.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/unit_test_jdir.cpp (rev 0)
+++ store/trunk/cpp/tests/jrnl/unit_test_jdir.cpp 2007-11-13 04:13:39 UTC (rev 1293)
@@ -0,0 +1,193 @@
+/**
+* \file unit_test_jdir.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/jdir.hpp>
+#include <jrnl/jerrno.hpp>
+#include <jrnl/jexception.hpp>
+
+#define ERRORSTR(e) ::strerror(ret) << " (" << ret <<
")"
+
+using namespace boost::unit_test;
+using namespace rhm::journal;
+
+// Test functions of the form
+// void fn() {...}
+
+void test_constructor()
+{
+ std::string dir("/tmp/A/B/C/D/E/F");
+ std::string bfn("test_base");
+ jdir dir1(dir, bfn);
+ BOOST_CHECK(dir1.dirname().compare(dir) == 0);
+ BOOST_CHECK(dir1.base_filename().compare(bfn) == 0);
+}
+
+void test_create_delete_dir()
+{
+ std::string dir_A("/tmp/A");
+ std::string dir_Ats("/tmp/A/"); // trailing '/'
+ std::string dir_Bts("/tmp/B/"); // trailing '/'
+ std::string dir_C("/tmp/C");
+ std::string dir_Dts("/tmp/D/"); // trailing '/'
+ std::string dir_X("/tmp/X");
+ std::string dir_Xts("/tmp/X/"); // trailing '/'
+ std::string bfn("test_base");
+
+ // Use instance
+ jdir dir1(dir_A, bfn);
+ dir1.create_dir();
+ // check all combos of jdir::exists and jdir::is_dir()
+ BOOST_CHECK(jdir::exists(dir_A));
+ BOOST_CHECK(jdir::exists(dir_Ats));
+ BOOST_CHECK(jdir::exists(dir_A.c_str()));
+ BOOST_CHECK(jdir::exists(dir_Ats.c_str()));
+ BOOST_CHECK(jdir::is_dir(dir_A));
+ BOOST_CHECK(jdir::is_dir(dir_Ats));
+ BOOST_CHECK(jdir::is_dir(dir_Ats.c_str()));
+ BOOST_CHECK(jdir::is_dir(dir_Ats.c_str()));
+
+ // Check non-existent dirs fail
+ BOOST_CHECK(!jdir::exists(dir_X));
+ BOOST_CHECK(!jdir::exists(dir_Xts));
+ try
+ {
+ jdir::is_dir(dir_X);
+ BOOST_ERROR("jdir::is_dir() failed to throw jexeption for non-existent
directory.");
+ }
+ catch(const jexception e)
+ {
+ BOOST_CHECK_EQUAL(e.err_code(), jerrno::JERR_JDIR_STAT);
+ }
+ try
+ {
+ jdir::is_dir(dir_Xts);
+ BOOST_ERROR("jdir::is_dir() failed to throw jexeption for non-existent
directory.");
+ }
+ catch(const jexception e)
+ {
+ BOOST_CHECK_EQUAL(e.err_code(), jerrno::JERR_JDIR_STAT);
+ }
+
+ jdir dir2(dir_Bts, bfn);
+ dir2.create_dir();
+ BOOST_CHECK(jdir::is_dir(dir_Bts));
+
+ // static fn
+ jdir::create_dir(dir_C);
+ BOOST_CHECK(jdir::is_dir(dir_C));
+ jdir::create_dir(dir_Dts);
+ BOOST_CHECK(jdir::is_dir(dir_Dts));
+
+ // Clean up with delete_dir
+ dir1.delete_dir();
+ BOOST_CHECK(!jdir::exists(dir_A));
+ dir2.delete_dir();
+ BOOST_CHECK(!jdir::exists(dir_Bts));
+ // static fn
+ jdir::delete_dir(dir_C);
+ BOOST_CHECK(!jdir::exists(dir_C));
+ jdir::delete_dir(dir_Dts);
+ BOOST_CHECK(!jdir::exists(dir_Dts));
+}
+
+void test_create_delete_dir_recursive()
+{
+ std::string dir_E("/tmp/E/F/G/H");
+ std::string dir_Eb("/tmp/E"); // base dir
+ std::string dir_F("/tmp/F/G/H/I/"); // trailing '/'
+ std::string dir_Fb("/tmp/F"); // base dir
+ std::string dir_G("/tmp/G/H/I/J");
+ std::string dir_Gb("/tmp/G"); // base dir
+ std::string dir_H("/tmp/H/I/J/K/"); // trailing '/'
+ std::string dir_Hb("/tmp/H"); // base dir
+ std::string bfn("test_base");
+
+ // Use instances
+ jdir dir1(dir_E, bfn);
+ dir1.create_dir();
+ BOOST_CHECK(jdir::is_dir(dir_E));
+ jdir dir2(dir_F, bfn);
+ dir2.create_dir();
+ BOOST_CHECK(jdir::is_dir(dir_F));
+
+ // static fn
+ jdir::create_dir(dir_G);
+ BOOST_CHECK(jdir::is_dir(dir_G));
+ jdir::create_dir(dir_H);
+ BOOST_CHECK(jdir::is_dir(dir_H));
+
+ // Clean up with delete_dir
+ dir1.delete_dir();
+ BOOST_CHECK(!jdir::exists(dir_E)); // only H deleted, E/F/G remain
+ BOOST_CHECK(jdir::exists(dir_Eb));
+ jdir::delete_dir(dir_Eb); // delete remaining dirs
+ BOOST_CHECK(!jdir::exists(dir_Eb));
+
+ dir2.delete_dir();
+ BOOST_CHECK(!jdir::exists(dir_F));
+ BOOST_CHECK(jdir::exists(dir_Fb));
+ jdir::delete_dir(dir_Fb);
+ BOOST_CHECK(!jdir::exists(dir_Fb));
+
+ // static fn
+ jdir::delete_dir(dir_G);
+ BOOST_CHECK(!jdir::exists(dir_G));
+ BOOST_CHECK(jdir::exists(dir_Gb));
+ jdir::delete_dir(dir_Gb);
+ BOOST_CHECK(!jdir::exists(dir_Gb));
+
+ jdir::delete_dir(dir_H);
+ BOOST_CHECK(!jdir::exists(dir_H));
+ BOOST_CHECK(jdir::exists(dir_Hb));
+ jdir::delete_dir(dir_Hb);
+ BOOST_CHECK(!jdir::exists(dir_Hb));
+}
+
+// Initialize test suite and include test functions
+
+test_suite* init_unit_test_suite(int, char**)
+{
+ std::cout << "--------" << std::endl <<
"unit_test_jdir: ";
+ test_suite* ts = BOOST_TEST_SUITE("unit_test_jdir");
+
+ results_reporter::set_level(SHORT_REPORT);
+ unit_test_log_t::instance().set_threshold_level(log_messages);
+
+ ts->add(BOOST_TEST_CASE(&test_constructor));
+ ts->add(BOOST_TEST_CASE(&test_create_delete_dir));
+ ts->add(BOOST_TEST_CASE(&test_create_delete_dir_recursive));
+
+ return ts;
+}
Modified: store/trunk/cpp/tests/jrnl/unit_test_jerrno.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/unit_test_jerrno.cpp 2007-11-12 22:57:21 UTC (rev 1292)
+++ store/trunk/cpp/tests/jrnl/unit_test_jerrno.cpp 2007-11-13 04:13:39 UTC (rev 1293)
@@ -1,5 +1,5 @@
/**
-* \file unit_test_jexception.cpp
+* \file unit_test_jerrno.cpp
*
* Red Hat Messaging - Message Journal
*
Modified: store/trunk/cpp/tests/jrnl/unit_test_jinf.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/unit_test_jinf.cpp 2007-11-12 22:57:21 UTC (rev 1292)
+++ store/trunk/cpp/tests/jrnl/unit_test_jinf.cpp 2007-11-13 04:13:39 UTC (rev 1293)
@@ -1,5 +1,5 @@
/**
-* \file unit_test_jexception.cpp
+* \file unit_test_jinf.cpp
*
* Red Hat Messaging - Message Journal
*
@@ -43,9 +43,6 @@
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");
@@ -61,6 +58,9 @@
void clean_journal_info_file();
+// Test functions of the form
+// void fn() {...}
+
void test_write_constructor()
{
::clock_gettime(CLOCK_REALTIME, &ts);
Show replies by date