summaryrefslogtreecommitdiff
path: root/tests/RMCast/RMCast_Fragment_Test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/RMCast/RMCast_Fragment_Test.cpp')
-rw-r--r--tests/RMCast/RMCast_Fragment_Test.cpp315
1 files changed, 0 insertions, 315 deletions
diff --git a/tests/RMCast/RMCast_Fragment_Test.cpp b/tests/RMCast/RMCast_Fragment_Test.cpp
deleted file mode 100644
index 847d6d91963..00000000000
--- a/tests/RMCast/RMCast_Fragment_Test.cpp
+++ /dev/null
@@ -1,315 +0,0 @@
-// $Id$
-
-// ============================================================================
-//
-// = DESCRIPTION
-// Unit test for the fragmentation module of the RMCast library.
-//
-// = AUTHORS
-// Carlos O'Ryan <coryan@uci.edu>
-//
-// ============================================================================
-
-#include "test_config.h"
-#include "ace/RMCast/RMCast_Fragment.h"
-
-ACE_RCSID(tests, RMCast_Fragment_Test, "$Id$")
-
-class ACE_RMCast_Fragment_Tester : public ACE_Task<ACE_MT_SYNCH>
-{
-public:
- ACE_RMCast_Fragment_Tester (void);
-
- virtual int put (ACE_Message_Block *mb,
- ACE_Time_Value *tv = 0);
- virtual int svc (void);
-
-private:
- void initialize (ACE_Message_Block *mb);
- // Initialize the message block with zero data
-
- int compare (ACE_Message_Block *mb);
- // Compare the message block to <received_>
-
-private:
- ACE_RMCast_Fragment<ACE_MT_SYNCH> fragment_;
-
- ACE_Message_Block received_;
- ACE_UINT32 received_bytes_;
- ACE_UINT32 message_sequence_number_;
-};
-
-int
-main (int, ACE_TCHAR *[])
-{
- ACE_START_TEST (ACE_TEXT ("RMCast_Fragment_Test"));
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("This is ACE Version %u.%u.%u\n\n"),
- ACE::major_version(),
- ACE::minor_version(),
- ACE::beta_version()));
-
- ACE_RMCast_Fragment_Tester tester;
-
- if (tester.svc () == -1)
- ACE_ERROR ((LM_ERROR, "Error running the svc() routine\n"));
-
- ACE_END_TEST;
- return 0;
-}
-
-// ****************************************************************
-
-ACE_RMCast_Fragment_Tester::ACE_RMCast_Fragment_Tester (void)
-{
- this->fragment_.next (this);
- this->next (&this->fragment_);
-}
-
-int
-ACE_RMCast_Fragment_Tester::svc (void)
-{
- {
- this->received_.wr_ptr (this->received_.rd_ptr ());
- this->received_bytes_ = 0;
- this->message_sequence_number_ = 0;
-
- ACE_UINT32 n = 128 * 1024;
- ACE_Message_Block big_blob (n);
- big_blob.wr_ptr (n);
-
- this->initialize (&big_blob);
-
- if (this->fragment_.put (&big_blob) == -1)
- return -1;
-
- if (this->received_bytes_ != n)
- ACE_ERROR_RETURN ((LM_ERROR,
- "Unpexpected number of "
- "received bytes (%d/%d)\n",
- this->received_bytes_, n),
- -1);
-
- if (this->compare (&big_blob) == -1)
- {
- ACE_ERROR_RETURN ((LM_ERROR,
- "Mismatched big_blob data\n"),
- -1);
- return -1;
- }
-
- }
-
-
- {
- this->received_.wr_ptr (this->received_.rd_ptr ());
- this->received_bytes_ = 0;
- this->message_sequence_number_ = 0;
-
- const int n = 256;
- const int size = 512;
- ACE_Message_Block small[n];
- small[0].size (size);
- small[0].wr_ptr (size);
-
- for (int i = 1; i != n; ++i)
- {
- small[i].size (size);
- small[i].wr_ptr (size);
- small[i - 1].cont (&small[i]);
- }
- this->initialize (small);
-
- if (this->fragment_.put (small) == -1)
- return -1;
-
- ACE_UINT32 total = n * size;
- if (this->received_bytes_ != total)
- ACE_ERROR_RETURN ((LM_ERROR,
- "Unpexpected number of "
- "received bytes (%d/%d)\n",
- this->received_bytes_, total),
- -1);
-
- if (this->compare (small) == -1)
- {
- ACE_ERROR_RETURN ((LM_ERROR,
- "Mismatched small chain data\n"),
- -1);
- return -1;
- }
-
- }
-
- {
- this->received_.wr_ptr (this->received_.rd_ptr ());
- this->received_bytes_ = 0;
- this->message_sequence_number_ = 0;
-
- const int n = 256;
- ACE_UINT32 total = 0;
-
- ACE_RANDR_TYPE seed =
- ACE_static_cast(ACE_RANDR_TYPE,ACE_OS::gethrtime ());
-
- int size = 64 + ACE_OS::rand_r(seed) % 128;
- ACE_Message_Block small[n];
- small[0].size (size);
- small[0].wr_ptr (size);
- total += size;
-
- for (int i = 1; i != n; ++i)
- {
- size = 64 + ACE_OS::rand_r(seed) % 128;
- total += size;
- small[i].size (size);
- small[i].wr_ptr (size);
- small[i - 1].cont (&small[i]);
- }
- this->initialize (small);
-
- if (this->fragment_.put (small) == -1)
- return -1;
-
- if (this->received_bytes_ != total)
- ACE_ERROR_RETURN ((LM_ERROR,
- "Unpexpected number of "
- "received bytes (%d/%d)\n",
- this->received_bytes_, total),
- -1);
-
- if (this->compare (small) == -1)
- {
- ACE_ERROR_RETURN ((LM_ERROR,
- "Mismatched small chain data\n"),
- -1);
- return -1;
- }
-
- }
- return 0;
-}
-
-void
-ACE_RMCast_Fragment_Tester::initialize (ACE_Message_Block *mb)
-{
- for (ACE_Message_Block *i = mb; i != 0; i = i->cont ())
- {
- char z = 0;
- for (char *j = i->rd_ptr (); j != i->wr_ptr (); ++j)
- {
- *j = ++z;
- }
- }
-}
-
-int
-ACE_RMCast_Fragment_Tester::compare (ACE_Message_Block *mb)
-{
- size_t n = mb->total_size ();
- ACE_Message_Block blob (n);
-
- for (const ACE_Message_Block *i = mb; i != 0; i = i->cont ())
- {
- blob.copy (i->rd_ptr (), i->length ());
- }
-
- if (ACE_OS::memcmp (blob.rd_ptr (),
- this->received_.rd_ptr (),
- n) != 0)
- {
- for (size_t offset = 0; offset < n; offset += 256)
- {
- size_t z = 256;
- if (n - offset < 256)
- z = n - offset;
- ACE_HEX_DUMP ((LM_DEBUG,
- blob.rd_ptr () + offset,
- z,
- "BIG BLOB"));
- ACE_HEX_DUMP ((LM_DEBUG,
- this->received_.rd_ptr () + offset,
- z,
- "RECEIVED"));
- }
- return -1;
- }
- return 0;
-}
-
-int
-ACE_RMCast_Fragment_Tester::put (ACE_Message_Block *mb,
- ACE_Time_Value *)
-{
- ACE_UINT32 header[3];
- size_t fragment_header_size = sizeof(header);
-
- if (mb->length () < fragment_header_size)
- ACE_ERROR_RETURN ((LM_ERROR,
- "Message block too small, "
- "not enough room for the header\n"),
- -1);
-
- ACE_OS::memcpy (header, mb->rd_ptr (), fragment_header_size);
-
- ACE_UINT32 message_size = ACE_NTOHL(header[2]);
- if (this->received_bytes_ == 0)
- {
- this->received_.size (message_size);
- this->received_.wr_ptr (message_size);
- this->message_sequence_number_ = ACE_NTOHL(header[0]);
- }
- else
- {
- if (this->message_sequence_number_ != ACE_NTOHL(header[0]))
- ACE_ERROR_RETURN ((LM_ERROR,
- "Mismatched sequence number\n"),
- -1);
- if (this->received_.length () != message_size)
- ACE_ERROR_RETURN ((LM_ERROR,
- "Mismatched sequence size\n"),
- -1);
- }
-
- size_t offset = ACE_NTOHL(header[1]);
- size_t payload_size = mb->length () - fragment_header_size;
- size_t fragment_size = payload_size;
- if (payload_size > 0)
- {
- ACE_OS::memcpy (this->received_.rd_ptr () + offset,
- mb->rd_ptr () + fragment_header_size,
- payload_size);
- this->received_bytes_ += payload_size;
- offset += payload_size;
- }
-
- for (const ACE_Message_Block *i = mb->cont (); i != 0; i = i->cont ())
- {
- payload_size = i->length ();
- // ACE_DEBUG ((LM_DEBUG,
- // "offset = %d , payload = %d\n", offset, payload_size));
- fragment_size += payload_size;
- ACE_OS::memcpy (this->received_.rd_ptr () + offset,
- i->rd_ptr (), payload_size);
- this->received_bytes_ += payload_size;
- offset += payload_size;
- }
-
- if (fragment_size > this->fragment_.max_fragment_size ())
- ACE_ERROR_RETURN ((LM_ERROR,
- "Invalid fragment size\n"),
- -1);
-
- return 0;
-}
-
-#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
-
-template class ACE_RMCast_Fragment<ACE_MT_SYNCH>;
-
-#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
-
-#pragma instantiate ACE_RMCast_Fragment<ACE_MT_SYNCH>
-
-#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */