summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2004-09-22 02:22:19 +0000
committercoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2004-09-22 02:22:19 +0000
commite1ed555f39eabc6a0a7526a7f61bef08707ee0ea (patch)
tree701db23cc1e0354a5746d1109c5e8b2efdac78f6
parente25db3aefe4be43b8bf17d90aaeb4964f5ca1b54 (diff)
downloadATCD-e1ed555f39eabc6a0a7526a7f61bef08707ee0ea.tar.gz
Tue Sep 21 22:11:10 2004 Carlos O'Ryan <coryan@atdesk.com>
-rw-r--r--TAO/ChangeLog43
-rw-r--r--TAO/tests/Sequence_Unit_Tests/Sequence_Unit_Tests.mpc16
-rw-r--r--TAO/tests/Sequence_Unit_Tests/bounded_value_sequence_ut.cpp78
-rw-r--r--TAO/tests/Sequence_Unit_Tests/string_traits.hpp79
-rw-r--r--TAO/tests/Sequence_Unit_Tests/string_traits_base.hpp75
-rw-r--r--TAO/tests/Sequence_Unit_Tests/testing_allocation_traits.hpp43
-rw-r--r--TAO/tests/Sequence_Unit_Tests/testing_allocation_traits_ut.cpp155
-rw-r--r--TAO/tests/Sequence_Unit_Tests/testing_counters.hpp104
-rw-r--r--TAO/tests/Sequence_Unit_Tests/testing_string_traits.hpp99
-rw-r--r--TAO/tests/Sequence_Unit_Tests/unbounded_string_sequence.hpp98
-rw-r--r--TAO/tests/Sequence_Unit_Tests/unbounded_string_sequence_ut.cpp186
-rw-r--r--TAO/tests/Sequence_Unit_Tests/unbounded_value_sequence_ut.cpp144
-rw-r--r--TAO/tests/Sequence_Unit_Tests/value_sequence_tester.hpp62
13 files changed, 1002 insertions, 180 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog
index 463f88761d9..c723737e2fb 100644
--- a/TAO/ChangeLog
+++ b/TAO/ChangeLog
@@ -1,3 +1,46 @@
+Tue Sep 21 22:11:10 2004 Carlos O'Ryan <coryan@atdesk.com>
+
+ * tests/Sequence_Unit_Tests/unbounded_string_sequence.hpp:
+ New file, this will implement (obviously enough) unbounded
+ sequences of strings. The implementation is incomplete, but
+ enough is there to show the main ideas and start the cycle:
+ write test -> get test to compile + fail -> get test to pass
+ -> rinse and repeat.
+
+ * tests/Sequence_Unit_Tests/Sequence_Unit_Tests.mpc:
+ * tests/Sequence_Unit_Tests/unbounded_string_sequence_ut.cpp:
+ Initial unit test for unbounded string sequences.
+
+ * tests/Sequence_Unit_Tests/testing_counters.hpp:
+ Helper classes to implement some common testing idioms, namely,
+ count how many times a function is called and raise an exception
+ after a prescribed number of calls.
+
+ * tests/Sequence_Unit_Tests/string_traits.hpp:
+ Implement the element manipulation traits for strings (and wide
+ strings.)
+
+ * tests/Sequence_Unit_Tests/string_traits_base.hpp:
+ Isolate most of the string element manipulation traits from the
+ silly CORBA names for string vs. wstring functions. Apparently
+ they forgot that C++ has overloading.
+
+ * tests/Sequence_Unit_Tests/testing_string_traits.hpp:
+ More helper classes to write unit tests related to string
+ sequences.
+
+ * tests/Sequence_Unit_Tests/testing_allocation_traits.hpp:
+ * tests/Sequence_Unit_Tests/value_sequence_tester.hpp:
+ * tests/Sequence_Unit_Tests/bounded_value_sequence_ut.cpp:
+ * tests/Sequence_Unit_Tests/unbounded_value_sequence_ut.cpp:
+ Refactored the code to use the testing_counters.hpp helpers.
+
+ * tests/Sequence_Unit_Tests/testing_allocation_traits_ut.cpp:
+ Wrote a unit test for the allocation traits used in testing.
+ Normally I would not "test the test" but the helpers in
+ testing_counters.hpp made it desirable to have this extra layer
+ of checking.
+
Tue Sep 21 20:15:01 2004 Carlos O'Ryan <coryan@atdesk.com>
* tests/Sequence_Unit_Tests/generic_sequence.hpp:
diff --git a/TAO/tests/Sequence_Unit_Tests/Sequence_Unit_Tests.mpc b/TAO/tests/Sequence_Unit_Tests/Sequence_Unit_Tests.mpc
index d7e6504a9a1..875a71500c5 100644
--- a/TAO/tests/Sequence_Unit_Tests/Sequence_Unit_Tests.mpc
+++ b/TAO/tests/Sequence_Unit_Tests/Sequence_Unit_Tests.mpc
@@ -13,11 +13,11 @@ project(*Bounded_Simple_Types) : taoexe {
}
}
-// project(*Unbounded_String_Sequence): taoexe, boost_unit_test {
-// Source_Files {
-// unbounded_string_sequence_ut.cpp
-// }
-//}
+project(*Unbounded_String_Sequence): taoexe, boost_unit_test {
+ Source_Files {
+ unbounded_string_sequence_ut.cpp
+ }
+}
//project(*String_Sequence_Element): taoexe, boost_unit_test {
// Source_Files {
@@ -25,6 +25,12 @@ project(*Bounded_Simple_Types) : taoexe {
// }
//}
+project(*Testing_Allocation_Traits): taoexe, boost_unit_test {
+ Source_Files {
+ testing_allocation_traits_ut.cpp
+ }
+}
+
project(*Unbounded_Value_Sequence): taoexe, boost_unit_test {
Source_Files {
unbounded_value_sequence_ut.cpp
diff --git a/TAO/tests/Sequence_Unit_Tests/bounded_value_sequence_ut.cpp b/TAO/tests/Sequence_Unit_Tests/bounded_value_sequence_ut.cpp
index 7cd0e362f20..8cec8745518 100644
--- a/TAO/tests/Sequence_Unit_Tests/bounded_value_sequence_ut.cpp
+++ b/TAO/tests/Sequence_Unit_Tests/bounded_value_sequence_ut.cpp
@@ -77,8 +77,8 @@ struct Tester
void test_set_length_less_than_maximum()
{
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence x;
@@ -87,8 +87,8 @@ struct Tester
BOOST_CHECK_EQUAL(CORBA::ULong(8), x.length());
BOOST_CHECK_EQUAL(true, x.release());
}
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::default_buffer_allocation_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
}
value_type * alloc_and_init_buffer()
@@ -103,8 +103,8 @@ struct Tester
{
value_type * buffer = alloc_and_init_buffer();
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a(4, buffer);
BOOST_CHECK_EQUAL(CORBA::ULong(32), a.maximum());
@@ -116,16 +116,16 @@ struct Tester
BOOST_CHECK_EQUAL(int(16), a[3]);
BOOST_CHECK_EQUAL(false, a.release());
}
- BOOST_CHECK_EQUAL(a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
+ BOOST_CHECK_MESSAGE(f.expect(0), f);
tested_sequence::freebuf(buffer);
}
void test_buffer_constructor_false()
{
value_type * buffer = alloc_and_init_buffer();
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a(4, buffer, false);
BOOST_CHECK_EQUAL(CORBA::ULong(32), a.maximum());
@@ -137,16 +137,16 @@ struct Tester
BOOST_CHECK_EQUAL(int(16), a[3]);
BOOST_CHECK_EQUAL(false, a.release());
}
- BOOST_CHECK_EQUAL( a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
+ BOOST_CHECK_MESSAGE(f.expect(0), f);
tested_sequence::freebuf(buffer);
}
void test_buffer_constructor_true()
{
value_type * buffer = alloc_and_init_buffer();
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a(4, buffer, true);
BOOST_CHECK_EQUAL(CORBA::ULong(32), a.maximum());
@@ -158,21 +158,21 @@ struct Tester
BOOST_CHECK_EQUAL(int(16), a[3]);
BOOST_CHECK_EQUAL(true, a.release());
}
- BOOST_CHECK_EQUAL( a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
}
void test_replace_default()
{
value_type * buffer = alloc_and_init_buffer();
- long c = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls c(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a;
a.replace(4, buffer);
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
BOOST_CHECK_EQUAL(CORBA::ULong(32), a.maximum());
BOOST_CHECK_EQUAL(CORBA::ULong(4), a.length());
@@ -183,22 +183,22 @@ struct Tester
BOOST_CHECK_EQUAL(int(16), a[3]);
BOOST_CHECK_EQUAL(false, a.release());
}
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(0), f);
tested_sequence::freebuf(buffer);
}
void test_replace_false()
{
value_type * buffer = alloc_and_init_buffer();
- long c = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls c(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a;
a.replace(4, buffer, false);
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
BOOST_CHECK_EQUAL(CORBA::ULong(32), a.maximum());
BOOST_CHECK_EQUAL(CORBA::ULong(4), a.length());
@@ -209,22 +209,22 @@ struct Tester
BOOST_CHECK_EQUAL(int(16), a[3]);
BOOST_CHECK_EQUAL(false, a.release());
}
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(0), c);
tested_sequence::freebuf(buffer);
}
void test_replace_true()
{
value_type * buffer = alloc_and_init_buffer();
- long c = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls c(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a;
a.replace(4, buffer, true);
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(1), c);
BOOST_CHECK_EQUAL(CORBA::ULong(32), a.maximum());
BOOST_CHECK_EQUAL(CORBA::ULong(4), a.length());
@@ -235,8 +235,8 @@ struct Tester
BOOST_CHECK_EQUAL(int(16), a[3]);
BOOST_CHECK_EQUAL(true, a.release());
}
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(1), c);
}
void test_get_buffer_const()
@@ -272,8 +272,8 @@ struct Tester
void test_get_buffer_true_with_release_true()
{
value_type * buffer = alloc_and_init_buffer();
- long c = tested_allocation_traits::default_buffer_allocation_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls c(tested_allocation_traits::default_buffer_allocation_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a(4, buffer, true);
BOOST_CHECK_EQUAL(buffer, a.get_buffer(true));
@@ -283,12 +283,12 @@ struct Tester
BOOST_CHECK_EQUAL(0UL, b.length());
BOOST_CHECK(0 != b.get_buffer());
- BOOST_CHECK_EQUAL(++c, tested_allocation_traits::default_buffer_allocation_calls);
+ BOOST_CHECK_MESSAGE(c.expect(1), c);
BOOST_CHECK(buffer != b.get_buffer());
}
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::default_buffer_allocation_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(1), c);
tested_sequence::freebuf(buffer);
}
};
diff --git a/TAO/tests/Sequence_Unit_Tests/string_traits.hpp b/TAO/tests/Sequence_Unit_Tests/string_traits.hpp
new file mode 100644
index 00000000000..85bc08c0b75
--- /dev/null
+++ b/TAO/tests/Sequence_Unit_Tests/string_traits.hpp
@@ -0,0 +1,79 @@
+#ifndef guard_string_traits_hpp
+#define guard_string_traits_hpp
+/**
+ * @file
+ *
+ * @brief Implement the element manipulation traits for string types.
+ *
+ * $Id$
+ *
+ * @author Carlos O'Ryan
+ */
+
+#include "string_traits_base.hpp"
+
+#include <algorithm>
+#include <functional>
+
+namespace TAO
+{
+namespace details
+{
+
+template<typename char_type, class derived>
+struct string_traits_decorator
+{
+ typedef char_type * value_type;
+ typedef char_type const * const_value_type;
+
+ inline static void zero_range(
+ char_type ** begin, char_type ** end)
+ {
+ std::fill(begin, end, static_cast<char_type*>(0));
+ }
+
+ inline static void initialize_range(
+ char_type ** begin, char_type ** end)
+ {
+ std::generate(begin, end, &derived::default_initializer);
+ }
+
+ inline static void copy_range(
+ char_type ** begin, char_type ** end, char ** dst)
+ {
+ std::transform(begin, end, dst, &derived::duplicate);
+ }
+
+ inline static char_type const * initialize_if_zero(char_type * & element)
+ {
+ if (element == 0)
+ {
+ element = derived::default_initializer();
+ }
+ return element;
+ }
+
+ inline static void not_released_from_const(
+ char_type * & dst, char_type const * src)
+ {
+ dst = const_cast<char_type*>(src);
+ }
+
+ inline static void not_released_from_managed(
+ char_type * & dst, char_type const * src)
+ {
+ dst = const_cast<char_type*>(src);
+ }
+};
+
+template<class charT, bool dummy>
+struct string_traits
+ : public string_traits_base<charT>
+ , public string_traits_decorator<charT,string_traits<charT,dummy> >
+{
+};
+
+} // namespace details
+} // namespace CORBA
+
+#endif // guard_string_traits_hpp
diff --git a/TAO/tests/Sequence_Unit_Tests/string_traits_base.hpp b/TAO/tests/Sequence_Unit_Tests/string_traits_base.hpp
new file mode 100644
index 00000000000..6c2cc41cfd8
--- /dev/null
+++ b/TAO/tests/Sequence_Unit_Tests/string_traits_base.hpp
@@ -0,0 +1,75 @@
+#ifndef guard_string_traits_base_hpp
+#define guard_string_traits_base_hpp
+/**
+ * @file
+ *
+ * @brief Isolate the string_traits from the accidental differences
+ * between wstring and string.
+ *
+ * $Id$
+ *
+ * @author Carlos O'Ryan
+ */
+
+#include "tao/CORBA_String.h"
+
+namespace TAO
+{
+namespace details
+{
+
+template<typename charT>
+struct string_traits_base
+{
+};
+
+template<>
+struct string_traits_base<char>
+{
+ typedef char char_type;
+ typedef CORBA::String_var string_var;
+ typedef TAO_String_Manager string_mgr;
+
+ inline static char_type * default_initializer()
+ {
+ return CORBA::string_dup("");
+ }
+
+ inline static char_type * duplicate(char_type const * s)
+ {
+ return CORBA::string_dup(s);
+ }
+
+ inline static void release(char_type * s)
+ {
+ return CORBA::string_free(s);
+ }
+};
+
+template<>
+struct string_traits_base<CORBA::WChar>
+{
+ typedef CORBA::WChar char_type;
+ typedef CORBA::WString_var string_var;
+ typedef TAO_WString_Manager string_mgr;
+
+ inline static char_type * default_initializer()
+ {
+ return CORBA::wstring_dup(L"");
+ }
+
+ inline static char_type * duplicate(char_type const * s)
+ {
+ return CORBA::wstring_dup(s);
+ }
+
+ inline static void release(char_type * s)
+ {
+ return CORBA::wstring_free(s);
+ }
+};
+
+} // namespace details
+} // namespace CORBA
+
+#endif // guard_string_traits_base_hpp
diff --git a/TAO/tests/Sequence_Unit_Tests/testing_allocation_traits.hpp b/TAO/tests/Sequence_Unit_Tests/testing_allocation_traits.hpp
index 541a8ff2fe4..d773ba0c4a2 100644
--- a/TAO/tests/Sequence_Unit_Tests/testing_allocation_traits.hpp
+++ b/TAO/tests/Sequence_Unit_Tests/testing_allocation_traits.hpp
@@ -13,60 +13,43 @@
#include "allocation_traits.hpp"
#include "testing_exception.hpp"
+#include "testing_counters.hpp"
template<typename T, class base>
struct testing_allocation_traits : public base
{
- static long allocbuf_calls;
- static long freebuf_calls;
- static long calls_until_failure_in_allocbuf;
-
- static long default_buffer_allocation_calls;
- static long calls_until_failure_in_default_buffer_allocation;
-
typedef typename base::value_type value_type;
+ static call_counter default_buffer_allocation_calls;
inline static value_type * default_buffer_allocation()
{
- ++default_buffer_allocation_calls;
- if (--calls_until_failure_in_default_buffer_allocation == 0)
- {
- throw testing_exception();
- }
+ default_buffer_allocation_calls();
return base::default_buffer_allocation();
}
+ static call_counter allocbuf_calls;
inline static value_type * allocbuf(CORBA::ULong maximum)
{
- ++allocbuf_calls;
- if (--calls_until_failure_in_allocbuf == 0)
- {
- throw testing_exception();
- }
+ allocbuf_calls();
return base::allocbuf(maximum);
}
+ static call_counter freebuf_calls;
inline static void freebuf(value_type * buffer)
{
- ++freebuf_calls;
+ freebuf_calls();
base::freebuf(buffer);
}
};
-template<typename T, class base>
-long testing_allocation_traits<T,base>::allocbuf_calls = 0;
+template<typename T, class base> call_counter
+testing_allocation_traits<T,base>::allocbuf_calls;
-template<typename T, class base>
-long testing_allocation_traits<T,base>::freebuf_calls = 0;
+template<typename T, class base> call_counter
+testing_allocation_traits<T,base>::freebuf_calls;
-template<typename T, class base>
-long testing_allocation_traits<T,base>::calls_until_failure_in_allocbuf = 0;
-
-template<typename T, class base>
-long testing_allocation_traits<T,base>::default_buffer_allocation_calls = 0;
-
-template<typename T, class base>
-long testing_allocation_traits<T,base>::calls_until_failure_in_default_buffer_allocation = 0;
+template<typename T, class base> call_counter
+testing_allocation_traits<T,base>::default_buffer_allocation_calls;
namespace TAO
{
diff --git a/TAO/tests/Sequence_Unit_Tests/testing_allocation_traits_ut.cpp b/TAO/tests/Sequence_Unit_Tests/testing_allocation_traits_ut.cpp
new file mode 100644
index 00000000000..ae4c9c132b2
--- /dev/null
+++ b/TAO/tests/Sequence_Unit_Tests/testing_allocation_traits_ut.cpp
@@ -0,0 +1,155 @@
+/**
+ * @file
+ *
+ * @brief Unit test for the testing_allocation_traits.
+ *
+ * $Id$
+ *
+ * @author Carlos O'Ryan
+ */
+#include "testing_allocation_traits.hpp"
+
+#include <boost/test/unit_test.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
+
+using namespace TAO::details;
+
+using namespace boost::unit_test_framework;
+
+CORBA::ULong const MAXIMUM = 32;
+
+template<class value_type>
+struct Tester : public boost::enable_shared_from_this<Tester<value_type> >
+{
+ typedef unbounded_allocation_traits<value_type,true> unbounded;
+ typedef bounded_allocation_traits<value_type,MAXIMUM,true> bounded;
+
+ void add_all(test_suite * ts)
+ {
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_default_buffer_allocation_value,
+ shared_from_this()));
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_default_buffer_allocation<unbounded>,
+ shared_from_this()));
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_default_buffer_allocation<bounded>,
+ shared_from_this()));
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_allocbuf<unbounded>,
+ shared_from_this()));
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_allocbuf<bounded>,
+ shared_from_this()));
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_freebuf<unbounded>,
+ shared_from_this()));
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_freebuf<bounded>,
+ shared_from_this()));
+ }
+
+ template<class aspect>
+ void test_allocbuf()
+ {
+ expected_calls c(aspect::allocbuf_calls);
+
+ aspect::allocbuf_calls.failure_countdown(2);
+ value_type * s;
+ BOOST_CHECK_NO_THROW(s = aspect::allocbuf(4));
+ aspect::freebuf(s);
+ BOOST_CHECK_THROW(s = aspect::allocbuf(4), testing_exception);
+ BOOST_CHECK_NO_THROW(s = aspect::allocbuf(4));
+ aspect::freebuf(s);
+
+ BOOST_CHECK_MESSAGE(c.expect(3), c);
+ }
+
+ template<class aspect>
+ void test_freebuf()
+ {
+ expected_calls c(aspect::freebuf_calls);
+
+ aspect::freebuf_calls.failure_countdown(2);
+ value_type * s = aspect::allocbuf(4);
+ BOOST_CHECK_NO_THROW(aspect::freebuf(s));
+ s = aspect::allocbuf(4);
+ BOOST_CHECK_THROW(aspect::freebuf(s), testing_exception);
+ aspect::freebuf(s);
+ s = aspect::allocbuf(4);
+ BOOST_CHECK_NO_THROW(aspect::freebuf(s));
+
+ BOOST_CHECK_MESSAGE(c.expect(4), c);
+ }
+
+ void test_default_buffer_allocation_value()
+ {
+ expected_calls u(unbounded::default_buffer_allocation_calls);
+ expected_calls b(bounded::default_buffer_allocation_calls);
+
+ value_type * s = unbounded::default_buffer_allocation();
+ BOOST_CHECK_MESSAGE(u.expect(1), u);
+ BOOST_CHECK_MESSAGE(b.expect(0), b);
+ BOOST_CHECK_EQUAL(static_cast<value_type*>(0), s);
+ bounded::freebuf(s);
+
+ s = bounded::default_buffer_allocation();
+ BOOST_CHECK_MESSAGE(u.expect(0), u);
+ BOOST_CHECK_MESSAGE(b.expect(1), b);
+ BOOST_CHECK(static_cast<value_type*>(0) != s);
+ bounded::freebuf(s);
+ }
+
+ template<class aspect>
+ void test_default_buffer_allocation()
+ {
+ expected_calls c(aspect::default_buffer_allocation_calls);
+
+ aspect::default_buffer_allocation_calls.failure_countdown(2);
+ value_type * s;
+ BOOST_CHECK_NO_THROW(
+ s = aspect::default_buffer_allocation());
+ aspect::freebuf(s);
+ BOOST_CHECK_THROW(
+ s = aspect::default_buffer_allocation(), testing_exception);
+ BOOST_CHECK_NO_THROW(
+ s = aspect::default_buffer_allocation());
+ aspect::freebuf(s);
+
+ BOOST_CHECK_MESSAGE(c.expect(3), c);
+ }
+
+};
+
+struct Foo { int y; };
+
+test_suite *
+init_unit_test_suite(int, char*[])
+{
+ std::auto_ptr<test_suite> ts(
+ BOOST_TEST_SUITE("testing allocation traits unit test"));
+
+ {
+ boost::shared_ptr<Tester<int> > tester(new Tester<int>);
+ tester->add_all(ts.get());
+ }
+
+ {
+ boost::shared_ptr<Tester<Foo> > tester(new Tester<Foo>);
+ tester->add_all(ts.get());
+ }
+
+ {
+ boost::shared_ptr<Tester<char*> > tester(new Tester<char*>);
+ tester->add_all(ts.get());
+ }
+
+ return ts.release();
+}
+
+#if 0
+// This is just to convince MPC that I do not need a main() to have a
+// program.
+int main() {}
+#endif
diff --git a/TAO/tests/Sequence_Unit_Tests/testing_counters.hpp b/TAO/tests/Sequence_Unit_Tests/testing_counters.hpp
new file mode 100644
index 00000000000..17c745bffd5
--- /dev/null
+++ b/TAO/tests/Sequence_Unit_Tests/testing_counters.hpp
@@ -0,0 +1,104 @@
+#ifndef guard_testing_counter_hpp
+#define guard_testing_counter_hpp
+/**
+ * @file
+ *
+ * @brief Some unit tests need to count how many times a function is
+ * called. Here we implement some simple helper classes for that
+ * purpose.
+ *
+ * $Id$
+ *
+ * @author Carlos O'Ryan
+ */
+
+#include <boost/noncopyable.hpp>
+
+#include <iostream>
+
+/**
+ * @brief Used to count how many times a function gets called. The
+ * unit test should create one instance per function.
+ */
+class call_counter
+{
+public:
+ inline call_counter()
+ : count_(0)
+ , failure_countdown_(0)
+ {}
+
+ inline long current_count() const
+ {
+ return count_;
+ }
+
+ inline void failure_countdown(long countdown)
+ {
+ failure_countdown_ = countdown;
+ }
+
+ inline void operator()()
+ {
+ ++count_;
+ if (--failure_countdown_ == 0)
+ {
+ throw testing_exception();
+ }
+ }
+
+private:
+ long count_;
+ long failure_countdown_;
+};
+
+/**
+ * @brief Used to detect if a testing_counter is "called" the right
+ * number of times.
+ */
+class expected_calls
+ : private boost::noncopyable
+{
+public:
+ inline expected_calls(call_counter const & counter)
+ : current_count_(counter.current_count())
+ , previous_count_(counter.current_count())
+ , counter_(counter)
+ { }
+
+ inline bool expect(long n)
+ {
+ reset();
+ return (previous_count_ + n == current_count_);
+ }
+
+ inline void reset()
+ {
+ previous_count_ = current_count_;
+ current_count_ = counter_.current_count();
+ }
+
+ inline long current_count() const
+ {
+ return current_count_;
+ }
+
+ inline long previous_count() const
+ {
+ return previous_count_;
+ }
+
+private:
+ long current_count_;
+ long previous_count_;
+ call_counter const & counter_;
+};
+
+std::ostream & operator<<(std::ostream & os, expected_calls const & x)
+{
+ return os << "current=" << x.current_count()
+ << ",previous=" << x.previous_count();
+
+}
+
+#endif // guard_testing_counter_hpp
diff --git a/TAO/tests/Sequence_Unit_Tests/testing_string_traits.hpp b/TAO/tests/Sequence_Unit_Tests/testing_string_traits.hpp
new file mode 100644
index 00000000000..ec9a1222218
--- /dev/null
+++ b/TAO/tests/Sequence_Unit_Tests/testing_string_traits.hpp
@@ -0,0 +1,99 @@
+#ifndef guard_testing_string_traits_hpp
+#define guard_testing_string_traits_hpp
+/**
+ * @file
+ *
+ * @brief Specialize the string traits so they can be used in testing.
+ *
+ * $Id$
+ *
+ * @author Carlos O'Ryan
+ */
+
+#include "testing_exception.hpp"
+#include "string_traits.hpp"
+#include "testing_counters.hpp"
+
+template<typename charT>
+struct testing_string_traits
+ : public TAO::details::string_traits_base<charT>
+ , public TAO::details::string_traits_decorator<charT,testing_string_traits<charT> >
+{
+ static call_counter default_initializer_calls;
+ static call_counter duplicate_calls;
+ static call_counter release_calls;
+ static call_counter not_released_from_const_calls;
+ static call_counter not_released_from_managed_calls;
+
+ typedef charT char_type;
+ typedef TAO::details::string_traits<charT,false> real_traits;
+
+ static char_type * default_initializer()
+ {
+ default_initializer_calls();
+ return real_traits::default_initializer();
+ }
+
+ static char_type * duplicate(char_type const * s)
+ {
+ duplicate_calls();
+ return real_traits::duplicate(s);
+ }
+
+ static void release(char_type * s)
+ {
+ release_calls();
+ return real_traits::release(s);
+ }
+
+ static void not_released_from_const(
+ char_type * & dst, char_type const * src)
+ {
+ not_released_from_const_calls();
+ real_traits::not_released_from_const(dst, src);
+ }
+
+ static void not_released_from_managed(
+ char_type * & dst, char_type const * src)
+ {
+ not_released_from_managed_calls();
+ real_traits::not_released_from_managed(dst, src);
+ }
+};
+
+template<typename charT> call_counter
+testing_string_traits<charT>::default_initializer_calls;
+
+template<typename charT> call_counter
+testing_string_traits<charT>::duplicate_calls;
+
+template<typename charT> call_counter
+testing_string_traits<charT>::release_calls;
+
+template<typename charT> call_counter
+testing_string_traits<charT>::not_released_from_const_calls;
+
+template<typename charT> call_counter
+testing_string_traits<charT>::not_released_from_managed_calls;
+
+namespace TAO
+{
+namespace details
+{
+
+template<>
+struct string_traits<char,true>
+ : public testing_string_traits<char>
+{
+};
+
+template<>
+struct string_traits<CORBA::WChar,true>
+ : public testing_string_traits<CORBA::WChar>
+{
+};
+
+} // namespace details
+} // namespace TAO
+
+#endif // guard_testing_string_traits_hpp
diff --git a/TAO/tests/Sequence_Unit_Tests/unbounded_string_sequence.hpp b/TAO/tests/Sequence_Unit_Tests/unbounded_string_sequence.hpp
new file mode 100644
index 00000000000..8784b48cbb2
--- /dev/null
+++ b/TAO/tests/Sequence_Unit_Tests/unbounded_string_sequence.hpp
@@ -0,0 +1,98 @@
+#ifndef TAO_unbounded_string_sequence_hpp
+#define TAO_unbounded_string_sequence_hpp
+/**
+ * @file
+ *
+ * @brief Implement unbounded sequences for strings.
+ *
+ * $Id$
+ *
+ * @author Carlos O'Ryan
+ */
+
+#include "allocation_traits.hpp"
+#include "string_traits.hpp"
+#include "generic_sequence.hpp"
+
+namespace TAO
+{
+
+class unbounded_string_sequence
+{
+public:
+ typedef char * value_type;
+ typedef details::unbounded_allocation_traits<char*,true> allocation_traits;
+ typedef details::string_traits<char,true> element_traits;
+
+ typedef details::generic_sequence<char*, allocation_traits, element_traits> implementation_type;
+
+ inline unbounded_string_sequence()
+ : impl_()
+ {}
+ inline /* explicit */ unbounded_string_sequence(CORBA::ULong maximum)
+ : impl_(maximum)
+ {}
+#if 0
+ inline unbounded_string_sequence(
+ CORBA::ULong maximum,
+ CORBA::ULong length,
+ char * * data,
+ CORBA::Boolean release = false)
+ : impl_(maximum, length, data, release)
+ {}
+#endif /* 0 */
+ /* Use default ctor, operator= and dtor */
+ inline CORBA::ULong maximum() const {
+ return impl_.maximum();
+ }
+ inline CORBA::Boolean release() const {
+ return impl_.release();
+ }
+ inline CORBA::ULong length() const {
+ return impl_.length();
+ }
+
+ inline void length(CORBA::ULong length) {
+ impl_.length(length);
+ }
+ inline char const * operator[](CORBA::ULong i) const {
+ return impl_[i];
+ }
+#if 0
+ inline value_type & operator[](CORBA::ULong i) {
+ return impl_[i];
+ }
+ inline void replace(
+ CORBA::ULong maximum,
+ CORBA::ULong length,
+ char * * data,
+ CORBA::Boolean release = false) {
+ impl_.replace(maximum, length, data, release);
+ }
+ inline char const * const * get_buffer() const {
+ return impl_.get_buffer();
+ }
+ inline char * * get_buffer(CORBA::Boolean orphan = false) {
+ return impl_.get_buffer(orphan);
+ }
+ inline void swap(unbounded_string_sequence & rhs) throw() {
+ impl_.swap(rhs.impl_);
+ }
+ static char * * allocbuf(CORBA::ULong maximum) {
+ return implementation_type::allocbuf(maximum);
+ }
+ static void freebuf(char * * buffer)
+ {
+ implementation_type::freebuf(buffer);
+ }
+
+#endif /* 0 */
+
+private:
+ implementation_type impl_;
+};
+
+
+} // namespace TAO
+
+#endif // TAO_unbounded_string_sequence_hpp
diff --git a/TAO/tests/Sequence_Unit_Tests/unbounded_string_sequence_ut.cpp b/TAO/tests/Sequence_Unit_Tests/unbounded_string_sequence_ut.cpp
new file mode 100644
index 00000000000..3210a4ad5e9
--- /dev/null
+++ b/TAO/tests/Sequence_Unit_Tests/unbounded_string_sequence_ut.cpp
@@ -0,0 +1,186 @@
+/**
+ * @file
+ *
+ * @brief Unit test for unbounded string sequences.
+ *
+ * $Id$
+ *
+ * @author Carlos O'Ryan
+ */
+#include "testing_string_traits.hpp"
+#include "string_traits.hpp"
+#include "testing_allocation_traits.hpp"
+#include "testing_range_checking.hpp"
+
+#include "unbounded_string_sequence.hpp"
+
+#include <boost/test/unit_test.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
+
+using namespace boost::unit_test_framework;
+using namespace TAO;
+
+struct Tester
+ : public boost::enable_shared_from_this<Tester>
+{
+ typedef TAO::details::string_traits<char,true> tested_element_traits;
+ typedef TAO::details::unbounded_allocation_traits<char*,true> tested_allocation_traits;
+ typedef TAO::details::range_checking<char*,true> range;
+
+ typedef TAO::unbounded_string_sequence tested_sequence;
+
+ void add_all(test_suite * ts)
+ {
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_default_constructor, shared_from_this()));
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_ulong_constructor, shared_from_this()));
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_copy_constructor, shared_from_this()));
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_set_length_less_than_maximum,
+ shared_from_this()));
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_set_length_more_than_maximum,
+ shared_from_this()));
+ ts->add(BOOST_CLASS_TEST_CASE(
+ &Tester::test_index_accessor,
+ shared_from_this()));
+ }
+
+ /**
+ * @brief Make sure the default constructor works as expected.
+ */
+ void test_default_constructor()
+ {
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
+ {
+ tested_sequence x;
+
+ BOOST_CHECK_EQUAL(CORBA::ULong(0), x.maximum());
+ BOOST_CHECK_EQUAL(CORBA::ULong(0), x.length());
+ BOOST_CHECK_EQUAL(true, x.release());
+ }
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
+ }
+
+ void test_ulong_constructor()
+ {
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
+ expected_calls i(tested_element_traits::default_initializer_calls);
+ {
+ tested_sequence x(16);
+
+ BOOST_CHECK_EQUAL(CORBA::ULong(16), x.maximum());
+ BOOST_CHECK_EQUAL(CORBA::ULong(0), x.length());
+ BOOST_CHECK_EQUAL(true, x.release());
+ }
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
+ BOOST_CHECK_MESSAGE(i.expect(0), i);
+ }
+
+ void test_copy_constructor()
+ {
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
+ expected_calls i(tested_element_traits::default_initializer_calls);
+ expected_calls d(tested_element_traits::duplicate_calls);
+ {
+ tested_sequence x(16);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
+
+ x.length(8);
+
+ BOOST_CHECK_EQUAL(CORBA::ULong(16), x.maximum());
+ BOOST_CHECK_EQUAL(CORBA::ULong(8), x.length());
+ BOOST_CHECK_EQUAL(true, x.release());
+
+ BOOST_CHECK_MESSAGE(i.expect(8), i);
+
+ tested_sequence y(x);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
+ BOOST_CHECK_EQUAL(CORBA::ULong(16), y.maximum());
+ BOOST_CHECK_EQUAL(CORBA::ULong(8), y.length());
+ BOOST_CHECK_EQUAL(true, y.release());
+
+ BOOST_CHECK_MESSAGE(d.expect(8), d);
+ }
+ BOOST_CHECK_MESSAGE(f.expect(2), f);
+ BOOST_CHECK_MESSAGE(i.expect(0), i);
+ }
+
+ void test_set_length_less_than_maximum()
+ {
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
+ expected_calls i(tested_element_traits::default_initializer_calls);
+ {
+ tested_sequence x(16);
+
+ x.length(8);
+ BOOST_CHECK_EQUAL(CORBA::ULong(16), x.maximum());
+ BOOST_CHECK_EQUAL(CORBA::ULong(8), x.length());
+ BOOST_CHECK_EQUAL(true, x.release());
+
+ BOOST_CHECK_MESSAGE(i.expect(8), i);
+ }
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
+ }
+
+ void test_set_length_more_than_maximum()
+ {
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
+ expected_calls i(tested_element_traits::default_initializer_calls);
+ {
+ tested_sequence x(16);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
+
+ x.length(32);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
+
+ BOOST_CHECK_MESSAGE(i.expect(32), i);
+
+ BOOST_CHECK_EQUAL(CORBA::ULong(32), x.maximum());
+ BOOST_CHECK_EQUAL(CORBA::ULong(32), x.length());
+ BOOST_CHECK_EQUAL(true, x.release());
+ }
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
+ }
+
+ void test_index_accessor()
+ {
+ tested_sequence x(16);
+ x.length(8);
+
+ tested_sequence const & y = x;
+ char const * t = y[4];
+ BOOST_CHECK_MESSAGE(std::strcmp(t, "") == 0,
+ "Unexpected string value " << t);
+ }
+};
+
+test_suite *
+init_unit_test_suite(int, char*[])
+{
+ std::auto_ptr<test_suite> ts(
+ BOOST_TEST_SUITE("unbounded string sequence unit test"));
+
+ boost::shared_ptr<Tester> tester(new Tester);
+ tester->add_all(ts.get());
+
+ return ts.release();
+}
+
+#if 0
+// This is just to convince MPC that I do not need a main() to have a
+// program.
+int main() {}
+#endif
diff --git a/TAO/tests/Sequence_Unit_Tests/unbounded_value_sequence_ut.cpp b/TAO/tests/Sequence_Unit_Tests/unbounded_value_sequence_ut.cpp
index 03396f439a1..335f746c8a8 100644
--- a/TAO/tests/Sequence_Unit_Tests/unbounded_value_sequence_ut.cpp
+++ b/TAO/tests/Sequence_Unit_Tests/unbounded_value_sequence_ut.cpp
@@ -97,11 +97,11 @@ struct Tester
void test_copy_constructor_from_ulong()
{
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence x(16);
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
x.length(8);
BOOST_CHECK_EQUAL(CORBA::ULong(16), x.maximum());
@@ -109,45 +109,43 @@ struct Tester
BOOST_CHECK_EQUAL(true, x.release());
tested_sequence y(x);
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
BOOST_CHECK_EQUAL(CORBA::ULong(16), y.maximum());
BOOST_CHECK_EQUAL(CORBA::ULong(8), y.length());
BOOST_CHECK_EQUAL(true, y.release());
}
- f += 2;
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(f.expect(2), f);
}
void test_assignment_from_ulong()
{
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence x(16);
x.length(8);
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
BOOST_CHECK_EQUAL(CORBA::ULong(16), x.maximum());
BOOST_CHECK_EQUAL(CORBA::ULong(8), x.length());
BOOST_CHECK_EQUAL(true, x.release());
tested_sequence y;
- BOOST_CHECK_EQUAL(a, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
y = x;
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
BOOST_CHECK_EQUAL(CORBA::ULong(16), y.maximum());
BOOST_CHECK_EQUAL(CORBA::ULong(8), y.length());
BOOST_CHECK_EQUAL(true, y.release());
}
- f += 2;
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(f.expect(2), f);
}
void test_ulong_constructor()
{
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence x(16);
@@ -155,26 +153,26 @@ struct Tester
BOOST_CHECK_EQUAL(CORBA::ULong(0), x.length());
BOOST_CHECK_EQUAL(true, x.release());
}
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
}
void test_exception_in_ulong_constructor()
{
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
- tested_allocation_traits::calls_until_failure_in_allocbuf = 1;
+ tested_allocation_traits::allocbuf_calls.failure_countdown(1);
BOOST_CHECK_THROW(tested_sequence x(16), testing_exception);
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
}
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(f.expect(0), f);
}
void test_set_length_less_than_maximum()
{
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence x(16);
@@ -183,41 +181,41 @@ struct Tester
BOOST_CHECK_EQUAL(CORBA::ULong(8), x.length());
BOOST_CHECK_EQUAL(true, x.release());
}
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
}
void test_set_length_more_than_maximum()
{
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence x(16);
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
x.length(32);
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
BOOST_CHECK_EQUAL(CORBA::ULong(32), x.maximum());
BOOST_CHECK_EQUAL(CORBA::ULong(32), x.length());
BOOST_CHECK_EQUAL(true, x.release());
}
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
}
void test_exception_in_set_length()
{
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence x;
- long a = tested_allocation_traits::allocbuf_calls;
- tested_allocation_traits::calls_until_failure_in_allocbuf = 1;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ tested_allocation_traits::allocbuf_calls.failure_countdown(1);
BOOST_CHECK_THROW(x.length(8), testing_exception);
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
}
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
}
value_type * alloc_and_init_buffer()
@@ -232,8 +230,8 @@ struct Tester
{
value_type * buffer = alloc_and_init_buffer();
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a(8, 4, buffer);
BOOST_CHECK_EQUAL(CORBA::ULong(8), a.maximum());
@@ -245,16 +243,16 @@ struct Tester
BOOST_CHECK_EQUAL(int(16), a[3]);
BOOST_CHECK_EQUAL(false, a.release());
}
- BOOST_CHECK_EQUAL(a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
+ BOOST_CHECK_MESSAGE(f.expect(0), f);
tested_sequence::freebuf(buffer);
}
void test_buffer_constructor_false()
{
value_type * buffer = alloc_and_init_buffer();
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a(8, 4, buffer, false);
BOOST_CHECK_EQUAL(CORBA::ULong(8), a.maximum());
@@ -266,16 +264,16 @@ struct Tester
BOOST_CHECK_EQUAL(int(16), a[3]);
BOOST_CHECK_EQUAL(false, a.release());
}
- BOOST_CHECK_EQUAL( a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
+ BOOST_CHECK_MESSAGE(f.expect(0), f);
tested_sequence::freebuf(buffer);
}
void test_buffer_constructor_true()
{
value_type * buffer = alloc_and_init_buffer();
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a(8, 4, buffer, true);
BOOST_CHECK_EQUAL(CORBA::ULong(8), a.maximum());
@@ -287,21 +285,21 @@ struct Tester
BOOST_CHECK_EQUAL(int(16), a[3]);
BOOST_CHECK_EQUAL(true, a.release());
}
- BOOST_CHECK_EQUAL( a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
}
void test_replace_default()
{
value_type * buffer = alloc_and_init_buffer();
- long c = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls c(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a;
a.replace(8, 4, buffer);
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
BOOST_CHECK_EQUAL(CORBA::ULong(8), a.maximum());
BOOST_CHECK_EQUAL(CORBA::ULong(4), a.length());
@@ -312,22 +310,22 @@ struct Tester
BOOST_CHECK_EQUAL(int(16), a[3]);
BOOST_CHECK_EQUAL(false, a.release());
}
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(0), f);
tested_sequence::freebuf(buffer);
}
void test_replace_false()
{
value_type * buffer = alloc_and_init_buffer();
- long c = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls c(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a;
a.replace(8, 4, buffer, false);
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
BOOST_CHECK_EQUAL(CORBA::ULong(8), a.maximum());
BOOST_CHECK_EQUAL(CORBA::ULong(4), a.length());
@@ -338,22 +336,22 @@ struct Tester
BOOST_CHECK_EQUAL(int(16), a[3]);
BOOST_CHECK_EQUAL(false, a.release());
}
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(0), f);
tested_sequence::freebuf(buffer);
}
void test_replace_true()
{
value_type * buffer = alloc_and_init_buffer();
- long c = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls c(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a;
a.replace(8, 4, buffer, true);
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
BOOST_CHECK_EQUAL(CORBA::ULong(8), a.maximum());
BOOST_CHECK_EQUAL(CORBA::ULong(4), a.length());
@@ -364,8 +362,8 @@ struct Tester
BOOST_CHECK_EQUAL(int(16), a[3]);
BOOST_CHECK_EQUAL(true, a.release());
}
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
}
void test_get_buffer_const()
@@ -401,8 +399,8 @@ struct Tester
void test_get_buffer_true_with_release_true()
{
value_type * buffer = alloc_and_init_buffer();
- long c = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls c(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence a(8, 4, buffer, true);
BOOST_CHECK_EQUAL(buffer, a.get_buffer(true));
@@ -412,12 +410,12 @@ struct Tester
BOOST_CHECK_EQUAL(0UL, b.length());
BOOST_CHECK(0 != b.get_buffer());
- BOOST_CHECK_EQUAL(++c, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(1), c);
BOOST_CHECK(buffer != b.get_buffer());
}
- BOOST_CHECK_EQUAL( c, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(c.expect(0), c);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
tested_sequence::freebuf(buffer);
}
diff --git a/TAO/tests/Sequence_Unit_Tests/value_sequence_tester.hpp b/TAO/tests/Sequence_Unit_Tests/value_sequence_tester.hpp
index e780b7ea198..ea1b4c05f52 100644
--- a/TAO/tests/Sequence_Unit_Tests/value_sequence_tester.hpp
+++ b/TAO/tests/Sequence_Unit_Tests/value_sequence_tester.hpp
@@ -62,8 +62,8 @@ struct value_sequence_tester
void test_default_constructor()
{
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence x;
@@ -73,18 +73,18 @@ struct value_sequence_tester
BOOST_CHECK_EQUAL(CORBA::ULong(0), x.length());
BOOST_CHECK_EQUAL(true, x.release());
}
- BOOST_CHECK_EQUAL( a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
}
void test_copy_constructor_from_default()
{
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence x;
- BOOST_CHECK_EQUAL(a, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
BOOST_CHECK_EQUAL(
CORBA::ULong(tested_allocation_traits::default_maximum()),
x.maximum());
@@ -92,13 +92,12 @@ struct value_sequence_tester
BOOST_CHECK_EQUAL(true, x.release());
tested_sequence y(x);
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
BOOST_CHECK_EQUAL(x.maximum(), y.maximum());
BOOST_CHECK_EQUAL(x.length(), y.length());
BOOST_CHECK_EQUAL(x.release(), y.release());
}
- f += 2;
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(f.expect(2), f);
}
void test_index_accessor()
@@ -153,11 +152,11 @@ struct value_sequence_tester
void test_assignment_from_default()
{
- long a = tested_allocation_traits::allocbuf_calls;
- long f = tested_allocation_traits::freebuf_calls;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence x;
- BOOST_CHECK_EQUAL(a, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
BOOST_CHECK_EQUAL(
CORBA::ULong(tested_allocation_traits::default_maximum()),
x.maximum());
@@ -165,17 +164,16 @@ struct value_sequence_tester
BOOST_CHECK_EQUAL(true, x.release());
tested_sequence y;
- BOOST_CHECK_EQUAL(a, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(0), a);
y = x;
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
BOOST_CHECK_EQUAL(x.maximum(), y.maximum());
BOOST_CHECK_EQUAL(x.length(), y.length());
BOOST_CHECK_EQUAL(x.release(), y.release());
}
- f += 2;
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(f.expect(2), f);
}
void test_assignment_values()
@@ -198,40 +196,38 @@ struct value_sequence_tester
void test_exception_in_copy_constructor()
{
- long f;
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence x; x.length(8);
+ f.reset();
- f = tested_allocation_traits::freebuf_calls;
-
- long a = tested_allocation_traits::allocbuf_calls;
- tested_allocation_traits::calls_until_failure_in_allocbuf = 1;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ tested_allocation_traits::allocbuf_calls.failure_countdown(1);
BOOST_CHECK_THROW(tested_sequence y(x), testing_exception);
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
}
- BOOST_CHECK_EQUAL(++f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(f.expect(1), f);
}
void test_exception_in_assignment()
{
- long f;
+ expected_calls f(tested_allocation_traits::freebuf_calls);
{
tested_sequence x; x.length(2);
tested_sequence y; y.length(3);
- long a = tested_allocation_traits::allocbuf_calls;
- f = tested_allocation_traits::freebuf_calls;
- tested_allocation_traits::calls_until_failure_in_allocbuf = 1;
+ expected_calls a(tested_allocation_traits::allocbuf_calls);
+ f.reset();
+ tested_allocation_traits::allocbuf_calls.failure_countdown(1);
BOOST_CHECK_THROW(y = x, testing_exception);
- BOOST_CHECK_EQUAL(++a, tested_allocation_traits::allocbuf_calls);
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(a.expect(1), a);
+ BOOST_CHECK_MESSAGE(f.expect(0), f);
BOOST_CHECK_EQUAL(CORBA::ULong(3), y.length());
}
- ++f /* for x */; ++f /* for y */;
- BOOST_CHECK_EQUAL( f, tested_allocation_traits::freebuf_calls);
+ BOOST_CHECK_MESSAGE(f.expect(2), f);
}
};