Test for 0022778: Bug in BRepMesh
[occt.git] / src / QANCollection / QANCollection4.cxx
1 // Created on: 2004-03-05
2 // Created by: Mikhail KUZMITCHEV
3 // Copyright (c) 2004-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21
22 #include <QANCollection.hxx>
23 #include <Draw_Interpretor.hxx>
24
25 #include <NCollection_StdAllocator.hxx>
26 #include <NCollection_IncAllocator.hxx>
27 #include <list>
28 #include <vector>
29
30 //=======================================================================
31 //function : QANColStdAllocator1
32 //purpose  : 
33 //=======================================================================
34 static Standard_Integer QANColStdAllocator1(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
35 {
36   if ( argc != 1) {
37     di << "Usage : " << argv[0] << "\n";
38     return 1;
39   }
40
41   //type definitions
42   typedef Handle_Standard_Transient elem_type;
43   typedef NCollection_StdAllocator<elem_type> allocator_type;
44   if ( sizeof (allocator_type::value_type) == sizeof (elem_type) ) {
45     di << "value_type : OK\n";
46   } else {
47     di << "value_type : Error\n";
48   }
49   if ( sizeof (allocator_type::pointer) == sizeof (void*) ) {
50     di << "pointer : OK\n";
51   } else {
52     di << "pointer : Error\n";
53   }
54   if (sizeof (allocator_type::const_pointer)  == sizeof (void*) ) {
55     di << "const_pointer : OK\n";
56   } else {
57     di << "const_pointer : Error\n";
58   }
59
60   elem_type aDummy;
61   allocator_type::reference aRef = aDummy;
62   allocator_type::const_reference aConstRef = aDummy;
63   if ( sizeof (allocator_type::size_type) == sizeof (size_t) ) {
64     di << "size_type : OK\n";
65   } else {
66     di << "size_type : Error\n";
67   }
68   if ( sizeof (allocator_type::difference_type) == sizeof (ptrdiff_t) ) {
69     di << "allocator_type : OK\n";
70   } else {
71     di << "allocator_type : Error\n";
72   }
73
74   typedef int other_elem_type;
75   if ( sizeof (allocator_type::rebind<other_elem_type>::other::value_type) == sizeof (other_elem_type) ) {
76     di << "other_elem_type : OK\n";
77   } else {
78     di << "other_elem_type : Error\n";
79   }
80
81   return 0;
82 }
83
84 //=======================================================================
85 //function : QANColStdAllocator2
86 //purpose  : 
87 //=======================================================================
88 static Standard_Integer QANColStdAllocator2(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
89 {
90   if ( argc != 1) {
91     di << "Usage : " << argv[0] << "\n";
92     return 1;
93   }
94
95   //create incremental allocator outside the scope of objects it will manage
96   Handle(NCollection_IncAllocator) anIncAlloc = new NCollection_IncAllocator();
97
98   {
99     //typed allocator
100     NCollection_StdAllocator<int> aSAlloc (anIncAlloc);
101     std::list<int, NCollection_StdAllocator<int> > aL (aSAlloc);
102     aL.push_back (2);
103     if ( aL.size() == size_t (1) ) {
104       di << "Test1 : OK\n";
105     } else {
106       di << "Test1 : Error\n";
107     }
108
109     //type cast
110     NCollection_StdAllocator<char> aCAlloc;
111     std::vector<int, NCollection_StdAllocator<int> > aV (aCAlloc);
112     aV.push_back (1);
113     if ( aV.size() == size_t (1) ) {
114       di << "Test2 : OK\n";
115     } else {
116       di << "Test2 : Error\n";
117     }
118
119     //using void-specialization allocator
120     std::vector<int, NCollection_StdAllocator<void> > aV2;
121     aV2.resize (10);
122     aV2.push_back (-1);
123     if ( aV2.size() == size_t (11) ) {
124       di << "Test3 : OK\n";
125     } else {
126       di << "Test3 : Error\n";
127     }
128
129     //equality of allocators
130     if ( aSAlloc != aCAlloc ) {
131       di << "Test4 : OK\n";
132     } else {
133       di << "Test4 : Error\n";
134     }
135     NCollection_StdAllocator<int> anIAlloc (anIncAlloc);
136     if ( aSAlloc == anIAlloc ) {
137       di << "Test5 : OK\n";
138     } else {
139       di << "Test5 : Error\n";
140     }
141
142   }
143
144   return 0;
145 }
146
147 void QANCollection::Commands4(Draw_Interpretor& theCommands) {
148   const char *group = "QANCollection";
149
150   theCommands.Add("QANColStdAllocator1", "QANColStdAllocator1", __FILE__, QANColStdAllocator1, group);  
151   theCommands.Add("QANColStdAllocator2", "QANColStdAllocator2", __FILE__, QANColStdAllocator2, group);  
152
153   return;
154 }