summaryrefslogtreecommitdiff
path: root/tests/DLList_Test.cpp
blob: 7d079b5d9630cf0e566a65556ac402f6d4a70a34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// $Id$

// ============================================================================
//
// = LIBRARY
//    tests
//
// = FILENAME
//    DLList_Test.cpp
//
// = DESCRIPTION
//      This test illustrates the use of <ACE_DLList>.
//
// = AUTHOR
//    James Hu and Douglas C. Schmidt
//
// ============================================================================

#include "test_config.h"
#include "ace/Containers.h"
#include "ace/SString.h"
#include "ace/Malloc.h"

#if defined(__BORLANDC__) && __BORLANDC__ >= 0x0530
USELIB("..\ace\aced.lib");
//---------------------------------------------------------------------------
#endif /* defined(__BORLANDC__) && __BORLANDC__ >= 0x0530 */

static ASYS_TCHAR * string_table[] =
{
  ASYS_TEXT ("hello"),
  ASYS_TEXT ("guten Tag"),
  ASYS_TEXT ("goodbye"),
  ASYS_TEXT ("auf wiedersehen"),
  ASYS_TEXT ("funny"),
  ASYS_TEXT ("lustig"),
  0
};

static ACE_Static_Allocator<8192> alloc;

typedef ASYS_TCHAR * STRING;
typedef ACE_DLList<STRING> STRLIST;
typedef ACE_DLList_Iterator<STRING> STRLIST_ITERATOR;

static void
run_iterate (STRLIST &list)
{
  STRING *entry;
  size_t i = 0;

  for (STRLIST_ITERATOR iter (list);
       (entry = iter.next ()) != 0;
       iter.advance (), i++)
    {
      ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("iterating (%d): [%s]\n"),
                  i,
                  (ASYS_TCHAR *) *entry));
    }
}

static int
run_test (void)
{
  alloc.dump ();

  STRLIST list;

  size_t i;

  for (i = 0; string_table[i] != 0; i++)
    {
      if (i % 2)
        {
          if (list.insert_tail (&string_table[i]) == 0)
            ACE_ERROR_RETURN ((LM_ERROR,
                               ASYS_TEXT ("%p failed for %s \n"),
                               ASYS_TEXT ("insert"),
                               string_table[i]), -1);
        }
      else
        {
          if (list.insert_head (&string_table[i]) == 0)
            ACE_ERROR_RETURN ((LM_ERROR,
                               ASYS_TEXT ("%p failed for %s \n"),
                               ASYS_TEXT ("insert"),
                               string_table[i]), -1);
        }

      run_iterate (list);
    }

  run_iterate (list);

  list.delete_tail ();
  list.delete_tail ();

  run_iterate (list);

  list.delete_head ();
  list.delete_head ();

  run_iterate (list);

  alloc.dump ();
  return 0;
}

int
main (int, ASYS_TCHAR *[])
{
  ACE_START_TEST (ASYS_TEXT ("ACE_DLList_Test"));

  run_test ();

  ACE_END_TEST;

  return 0;
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_DLList<STRING>;
template class ACE_DLList_Iterator<STRING>;
template class ACE_Static_Allocator<8192>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_DLList<STRING>
#pragma instantiate ACE_DLList_Iterator<STRING>
#pragma instantiate ACE_Static_Allocator<8192>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */