Beispiel #1
0
static void
test_map_manager (size_t table_size,
                  size_t iterations,
                  int test_iterators)
{
    MAP_MANAGER map (table_size);
    TYPE i;
    TYPE j = 0;
    ssize_t k;

    for (i = 0; i < iterations; ++i)
        ACE_ASSERT (map.bind (i, i) != -1);

    if (test_iterators)
    {
        {
            i = 0;

            ITERATOR end = map.end ();
            for (ITERATOR iter = map.begin ();
                    iter != end;
                    ++iter)
            {
                MAP_ENTRY &entry = *iter;
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            i,
                            entry.ext_id_,
                            entry.int_id_));
                ++i;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (i == iterations);
        }

        {
            i = 0;
            MAP_ENTRY *entry = 0;

            for (ITERATOR iterator (map);
                    iterator.next (entry) != 0;
                    iterator.advance ())
            {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            i,
                            entry->ext_id_,
                            entry->int_id_));
                ++i;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (i == iterations);
        }

        {
            k = iterations - 1;
            REVERSE_ITERATOR rend = map.rend ();

            for (REVERSE_ITERATOR iter = map.rbegin ();
                    iter != rend;
                    ++iter)
            {
                MAP_ENTRY &entry = *iter;
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            k,
                            entry.ext_id_,
                            entry.int_id_));
                k--;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (k == -1);
        }

        {
            k = iterations - 1;
            MAP_ENTRY *entry = 0;

            for (REVERSE_ITERATOR iterator (map);
                    iterator.next (entry) != 0;
                    iterator.advance ())
            {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            k,
                            entry->ext_id_,
                            entry->int_id_));
                k--;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (k == -1);
        }

        {
            i = 0;

            MAP_MANAGER::iterator end = map.end ();
            for (MAP_MANAGER::iterator iter = map.begin ();
                    iter != end;
                    ++iter)
            {
                MAP_MANAGER::ENTRY &entry = *iter;
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            i,
                            entry.ext_id_,
                            entry.int_id_));
                ++i;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (i == iterations);
        }

        {
            i = 0;
            MAP_MANAGER::ENTRY *entry = 0;

            for (MAP_MANAGER::ITERATOR iterator (map);
                    iterator.next (entry) != 0;
                    iterator.advance ())
            {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            i,
                            entry->ext_id_,
                            entry->int_id_));
                ++i;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (i == iterations);
        }

        {
            k = iterations - 1;
            MAP_MANAGER::reverse_iterator rend = map.rend ();

            for (MAP_MANAGER::reverse_iterator iter = map.rbegin ();
                    iter != rend;
                    ++iter)
            {
                MAP_ENTRY &entry = *iter;
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            k,
                            entry.ext_id_,
                            entry.int_id_));
                k--;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (k == -1);
        }

        {
            k = iterations - 1;
            MAP_MANAGER::ENTRY *entry = 0;

            for (MAP_MANAGER::REVERSE_ITERATOR iterator (map);
                    iterator.next (entry) != 0;
                    iterator.advance ())
            {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            k,
                            entry->ext_id_,
                            entry->int_id_));
                k--;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (k == -1);
        }
    }

    for (i = 0; i < iterations; ++i)
    {
        ACE_ASSERT (map.find (i, j) != -1);
        ACE_ASSERT (i == j);
    }

    size_t remaining_entries = iterations;
    for (i = 0; i < iterations; ++i)
    {
        ACE_ASSERT (map.unbind (i) != -1);
        --remaining_entries;
        ACE_ASSERT (map.current_size () == remaining_entries);
    }

    //
    // This is extra for the map manager.
    //
    for (i = 0; i < iterations; ++i)
        ACE_ASSERT (map.bind (i, i) != -1);

    // Unbind in one swoop.
    map.unbind_all ();
    ACE_ASSERT (map.current_size () == 0);

    for (i = 0; i < iterations; ++i)
        ACE_ASSERT (map.bind (i, i) != -1);

    // Unbind one at a time.
    MAP_MANAGER::iterator end = map.end ();
    while (1)
    {
        MAP_MANAGER::iterator iter = map.begin ();
        if (iter == end)
            break;
        ACE_ASSERT (map.unbind ((*iter).ext_id_) != -1);
    }

    ACE_ASSERT (map.current_size () == 0);
}
Beispiel #2
0
static int
iterator_test (void)
{
  const int ITERATIONS = 5;
  ACE_TCHAR buffer[ITERATIONS][BUFSIZ];
  // Use queue size from of 32 Kb (more if using wide-char), instead of the
  // default of 16 Kb (defined by ACE_Message_Queue_Base::DEFAULT_HWM),
  // so that the test runs on machines with 8Kb pagesizes.

  //  QUEUE queue (32 * 1024 * sizeof (ACE_TCHAR));
  QUEUE queue (sizeof(buffer));

  int i;

  for (i = 0; i < ITERATIONS; i++)
    {
      ACE_OS::sprintf (buffer[i],
                       ACE_TEXT ("%d"),
                       i + 1);

      ACE_Message_Block *entry = 0;
      ACE_NEW_RETURN (entry,
                      ACE_Message_Block ((char *) buffer[i],
                                         sizeof buffer[i]),
                      -1);

      if (queue.is_full ())
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("QUEUE:: the message queue is full on iteration %u!\n"),
                           i + 1),
                          -1);

      if (queue.enqueue (entry) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("QUEUE::enqueue\n")),
                          -1);
    }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\nForward Iterations\n")));
  {
    ITERATOR iterator (queue);

    for (ACE_Message_Block *entry = 0;
         iterator.next (entry) != 0;
         iterator.advance ())
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%s\n"),
                  entry->base ()));
  }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\nReverse Iterations\n")));
  {
    REVERSE_ITERATOR iterator (queue);

    for (ACE_Message_Block *entry = 0;
         iterator.next (entry) != 0;
         iterator.advance ())
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%s\n"),
                  entry->base ()));
  }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\nForward Iterations\n")));
  {
    QUEUE::ITERATOR iterator (queue);

    for (ACE_Message_Block *entry = 0;
         iterator.next (entry) != 0;
         iterator.advance ())
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%s\n"),
                  entry->base ()));
  }

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\nReverse Iterations\n")));
  {
    QUEUE::REVERSE_ITERATOR iterator (queue);

    for (ACE_Message_Block *entry = 0;
         iterator.next (entry) != 0;
         iterator.advance ())
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%s\n"),
                  entry->base ()));
  }

  return 0;
}
Beispiel #3
0
int run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Vector_Test"));

  VECTOR vector;
  size_t i;

  for (i = 0; i < TOP; ++i)
    vector.push_back (i);

  ACE_TEST_ASSERT (vector.size () == TOP);
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Size: %d\n"),
              vector.size ()));

  for (i = 0; i < TOP; ++i)
    ACE_TEST_ASSERT (vector[i] == i);

  // Test to be sure the iterator gets the correct count and entries.
  ITERATOR iter (vector);
  DATA *p_item = 0 ;
  size_t iter_count = 0;
  while (!iter.done ())
    {
      if (iter.next (p_item) == 0)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("Fail to get value on iter pass %d\n"),
                    iter_count));
      if (*p_item != iter_count)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("Iter pass %d got %d\n"),
                    iter_count, *p_item));
      iter_count++;
      iter.advance();
    }
  if (iter_count != TOP)
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("Iterated %d elements; expected %d\n"),
                iter_count, TOP));

  for (i = 0; i < (TOP - LEFT); ++i)
    vector.pop_back ();

  ACE_TEST_ASSERT (vector.size () == LEFT);
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Size: %d\n"),
              vector.size ()));

  for (i = 0; i < LEFT; ++i)
    {
      ACE_TEST_ASSERT (vector[i] == i);
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("vector[%d]:%d\n"),
                  i, vector[i]));
    }

  vector.resize(RESIZE, 0);
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("After resize\n")));

  for (i = 0; i < RESIZE ; ++i)
    {
      // The original vector of size LEFT must have the same original contents
      // the new elements should have the value 0 (this value is passed as
      // second argument of the resize() call.
      if (i < LEFT)
        {
          ACE_TEST_ASSERT (vector[i] == i);
        }
      else
        {
          ACE_TEST_ASSERT (vector[i] == 0);
        }
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("vector[%d]:%d\n"),
                  i, vector[i]));
    }

  vector.clear ();
  ACE_TEST_ASSERT (vector.size () == 0);
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Size: %d\n"),
              vector.size ()));

  // test resize (shrink and enlarge with buffer realloc)
  VECTOR vector2;

  // should be around 32
  size_t boundary = vector2.capacity ();

  // we fill everything up with 1
  // 1, 1, 1, 1, 1, 1, 1, 1,
  // 1, 1, 1, 1, 1, 1, 1, 1,
  // 1, 1, 1, 1, 1, 1, 1, 1,
  // 1, 1, 1, 1, 1, 1, 1, 1,
  for (i = 0; i < boundary; ++i)
    vector2.push_back (FILLER1);

  // we throw almost everything away.
  vector2.resize (1, 0);

  // we fill up with another pattern
  // 1, 2, 2, 2, 2, 2, 2, 2,
  // 2, 2, 2, 2, 2, 2, 2, 2,
  // 2, 2, 2, 2, 2, 2, 2, 2,
  // 2, 2, 2, 2, 2, 2, 2, 2,
  // 2,
  for (i = 0; i < boundary; ++i)
    vector2.push_back (FILLER2);

  // now we check the result
  ACE_TEST_ASSERT (vector2[0] == FILLER1);
  for (i = 0; i < boundary; ++i)
    ACE_TEST_ASSERT (vector2[i+1] == FILLER2);

  VECTOR v1;
  VECTOR v2;
  v1.push_back (1);
  v2.push_back (1);
  v1.push_back (2);
  v2.push_back (2);
  if (v1 != v2)
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("Inequality test failed!\n")));
  if (!(v1 == v2))
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("Equality test failed!\n")));

  v1.push_back (3);
  if (v1.size () != 3)
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("v1's size should be 3\n")));

  v1.swap (v2);
  if (v2.size () != 3)
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("v2's size should be 3\n")));

  ACE_END_TEST;

  return 0;
}