summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorcleeland <cleeland@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2001-11-06 20:19:02 +0000
committercleeland <cleeland@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2001-11-06 20:19:02 +0000
commitb38277cc60b4bde4e273f645bbc7cbfcbcf2f1bb (patch)
tree97b2383d2b8a5360e5df7e2dc54249e5adcb6d99 /tests
parentfedf6c36522243ebeab58a1afa0b5084c944e9bc (diff)
downloadATCD-b38277cc60b4bde4e273f645bbc7cbfcbcf2f1bb.tar.gz
* tests/Collection_Test.cpp: Committed an old change that uses an
actual class as the element in the Unbounded_Set rather than an int. I wrote this to get a better understanding of how the iterator and accessors on the iterator worked. * tests/SString_Test.cpp (main): Added a test for the rep() method that insures that the char array returned is equivalent to the string in the ACE_CString from which it's obtained.
Diffstat (limited to 'tests')
-rw-r--r--tests/Collection_Test.cpp68
-rw-r--r--tests/SString_Test.cpp8
2 files changed, 67 insertions, 9 deletions
diff --git a/tests/Collection_Test.cpp b/tests/Collection_Test.cpp
index 3679376a41c..7844ae555de 100644
--- a/tests/Collection_Test.cpp
+++ b/tests/Collection_Test.cpp
@@ -23,7 +23,29 @@ ACE_RCSID(tests, Collection_Test, "$Id$")
#include "ace/Containers.h"
-typedef int DATA;
+typedef void (*deletion_func)(void* p);
+struct UglyThing
+{
+ void *alloc_;
+ deletion_func dfunc_;
+
+ UglyThing (void* alloc = 0, deletion_func dfunc = 0);
+ int operator== (const UglyThing& r) const;
+};
+
+UglyThing::UglyThing (void* alloc, deletion_func dfunc)
+ : alloc_ (alloc)
+ , dfunc_ (dfunc)
+{
+}
+
+int
+UglyThing::operator== (const UglyThing& r) const
+{
+ return this->alloc_ == r.alloc_;
+}
+
+typedef UglyThing DATA;
typedef ACE_Unbounded_Set<DATA> UNBOUNDED_SET;
typedef ACE_Unbounded_Set_Iterator<DATA> UNBOUNDED_SET_ITERATOR;
typedef ACE_Unbounded_Set_Const_Iterator<DATA> UNBOUNDED_SET_CONST_ITERATOR;
@@ -38,11 +60,16 @@ void iterate_const(const UNBOUNDED_SET& set)
{
DATA *data = 0;
iterator.next (data);
+
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%x,%x\n"),
+ data->alloc_, data->dfunc_));
+
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d\n"),
(*data)));
DATA data_second = *iterator;
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d\n"),
(data_second)));
+
iterator.advance ();
}
}
@@ -50,38 +77,57 @@ void iterate_const(const UNBOUNDED_SET& set)
int main (int, ACE_TCHAR *[])
{
- ACE_START_TEST (ACE_TEXT ("Collection_Test"));
+ // ACE_START_TEST (ACE_TEXT ("Collection_Test"));
+ deletion_func NO_DFUNC = (deletion_func)0;
{
UNBOUNDED_SET unbounded_set;
- unbounded_set.insert (1);
- unbounded_set.insert (2);
+ unbounded_set.insert (UglyThing ((void*)&unbounded_set, NO_DFUNC));
+ unbounded_set.insert (UglyThing ((void*)&main, NO_DFUNC));
{
for (UNBOUNDED_SET::iterator iterator = unbounded_set.begin ();
iterator != unbounded_set.end ();
++iterator)
{
- ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d\n"),
- (*iterator)));
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%x,%x\n"),
+ (*iterator).alloc_, (*iterator).dfunc_));
}
}
+ unbounded_set.insert (UglyThing (0, NO_DFUNC));
+ unbounded_set.remove (UglyThing ((void*)&main, NO_DFUNC));
+
{
UNBOUNDED_SET_ITERATOR iterator (unbounded_set);
while (!iterator.done ())
{
DATA *data = 0;
iterator.next (data);
- ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d\n"),
- (*data)));
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%x,%x\n"),
+ data->alloc_, data->dfunc_));
iterator.advance ();
}
}
iterate_const (unbounded_set);
+
+ unbounded_set.reset ();
+
+ {
+ DATA *data;
+ UNBOUNDED_SET_ITERATOR i (unbounded_set);
+
+ while (i.next (data) != 0)
+ {
+ ACE_DEBUG ((LM_DEBUG, "%x,%x\n", data->alloc_, data->dfunc_));
+ i.advance ();
+ }
+ }
+ iterate_const (unbounded_set);
}
+#if 0
{
ARRAY array;
}
@@ -131,8 +177,9 @@ int main (int, ACE_TCHAR *[])
}
}
}
+#endif
- ACE_END_TEST;
+ // ACE_END_TEST;
return 0;
}
@@ -143,15 +190,18 @@ template class ACE_Unbounded_Set<DATA>;
template class ACE_Unbounded_Set_Iterator<DATA>;
template class ACE_Unbounded_Set_Const_Iterator<DATA>;
+template class ACE_Node<DATA>;
#if (ACE_SIZEOF_INT != 4)
// These might be already instantiated in ace/stats.cpp
// (if ACE_INT32 == int)
template class ACE_Node<DATA>;
#endif /* ACE_SIZEOF_INT != 4 */
+#if 0
template class ACE_Array<DATA>;
template class ACE_Array_Base<DATA>;
template class ACE_Array_Iterator<DATA>;
+#endif
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Unbounded_Set<DATA>
#pragma instantiate ACE_Unbounded_Set_Iterator<DATA>
diff --git a/tests/SString_Test.cpp b/tests/SString_Test.cpp
index 181c472b6b8..d2290faefd3 100644
--- a/tests/SString_Test.cpp
+++ b/tests/SString_Test.cpp
@@ -19,6 +19,7 @@
// ============================================================================
#include "test_config.h"
+#include "ace/Auto_Ptr.h"
#include "ace/SString.h"
ACE_RCSID(tests, SString_Test, "$Id$")
@@ -143,6 +144,13 @@ main (int, ACE_TCHAR *[])
// Clear
s0.clear();
ACE_ASSERT (s0.length() == 0);
+
+ // Rep
+ ACE_Auto_Basic_Array_Ptr<char> s (s1.rep ());
+ ACE_ASSERT (ACE_OS::strlen (s.get ()) == s1.length ());
+
+ ACE_CString s7 (s.get ());
+ ACE_ASSERT (s1 == s7);
}
{