summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames H. Hill <hilljh82@gmail.com>2008-01-14 16:17:45 +0000
committerJames H. Hill <hilljh82@gmail.com>2008-01-14 16:17:45 +0000
commit9d2050f28c440295e040e9e7580e5d4ea9d0e33d (patch)
treedc3356acce3dc9b0274eccc7c9cd09ae27ce8400
parent83c37b91831b80e00f281b9f9f9277e0c7d82651 (diff)
downloadATCD-9d2050f28c440295e040e9e7580e5d4ea9d0e33d.tar.gz
Mon Jan 14 16:14:11 UTC 2008 James H. Hill <hillj@isis.vanderbilt.edu>
-rw-r--r--ACE/ChangeLog9
-rw-r--r--ACE/tests/STL_algorithm_Test_T.cpp72
2 files changed, 64 insertions, 17 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog
index 1eb1dabcdf1..71c028b1fa3 100644
--- a/ACE/ChangeLog
+++ b/ACE/ChangeLog
@@ -1,3 +1,12 @@
+Mon Jan 14 16:14:11 UTC 2008 James H. Hill <hillj@isis.vanderbilt.edu>
+
+ * tests/STL_algorithm_Test_T.cpp:
+
+ Changed the std::for_each functor object to an actual class
+ that will count the number of elements handled. It would
+ be nice to eventually validate that the number of elements
+ handled is equal to the number of elements in the container.
+
Mon Jan 14 14:06:33 UTC 2008 James H. Hill <hillj@isis.vanderbilt.edu>
* tests/Hash_Map_Manager_Test.cpp:
diff --git a/ACE/tests/STL_algorithm_Test_T.cpp b/ACE/tests/STL_algorithm_Test_T.cpp
index 6972fd20df2..cb9f63d71b5 100644
--- a/ACE/tests/STL_algorithm_Test_T.cpp
+++ b/ACE/tests/STL_algorithm_Test_T.cpp
@@ -7,34 +7,72 @@
#include <algorithm>
#include <typeinfo>
-template <typename ITEM>
-static void
-for_each_callback (ITEM & item)
+template <typename T>
+class Element_Counter
{
- // do nothing; just testing compilation and execution
- ACE_DEBUG ((LM_DEBUG,
- "algorithm test: for_each_callback\n"));
+public:
+ Element_Counter (void)
+ : count_ (0)
+ {
- ACE_UNUSED_ARG (item);
-}
+ }
+
+ void operator () (typename T::value_type & item)
+ {
+ ++ this->count_;
+ ACE_UNUSED_ARG (item);
+ }
+
+ const Element_Counter & operator = (const Element_Counter & ec)
+ {
+ this->count_ = ec.count_;
+ return *this;
+ }
+
+ typename T::difference_type get_count (void) const
+ {
+ return this->count_;
+ }
+
+private:
+ // Number of elements iterated over.
+ typename T::difference_type count_;
+};
template <typename T>
int test_STL_algorithm (T & container)
{
- // We are only validating that the container's iterators compile with
- // the <algorithm> header.
+ // We are only validating that the container's iterators
+ // compile with the <algorithm> header.
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("running STL algorithm test for `%s'\n"),
typeid (T).name ()));
- // Test the (reverse) iterator using std::for_each.
- std::for_each (container.begin (),
- container.end (),
- &for_each_callback <typename T::value_type>);
+ // Test the forward iterator using std::for_each.
+ ACE_DEBUG ((LM_DEBUG,
+ "testing forward iterator\n"));
- std::for_each (container.rbegin (),
- container.rend (),
- &for_each_callback <typename T::value_type>);
+ typename T::difference_type count =
+ std::for_each (container.begin (),
+ container.end (),
+ Element_Counter <T> ()).get_count ();
+
+ ACE_DEBUG ((LM_DEBUG,
+ "std::for_each handled %d elements\n",
+ count));
+
+ // Test the reverse iterator using std::for_each.
+ ACE_DEBUG ((LM_DEBUG,
+ "testing reverse iterator\n"));
+
+ count =
+ std::for_each (container.rbegin (),
+ container.rend (),
+ Element_Counter <T> ()).get_count ();
+
+ ACE_DEBUG ((LM_DEBUG,
+ "std::for_each handled %d elements\n",
+ count));
return 0;
}