File: Standard_StdAllocator_test.cpp

package info (click to toggle)
oce 0.18.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 301,548 kB
  • sloc: cpp: 1,190,609; ansic: 67,225; sh: 11,630; tcl: 7,954; cs: 5,221; python: 2,867; java: 1,522; makefile: 342; xml: 292; perl: 37
file content (53 lines) | stat: -rw-r--r-- 1,685 bytes parent folder | download | duplicates (6)
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
#include <Standard_StdAllocator.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Solid.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <list>
#include <vector>

#include <gtest/gtest.h>

TEST(Standard_StdAllocatorTestSuite, testTraits)
{
    //type definitions
    typedef Handle_Standard_Transient elem_type;
    typedef Standard_StdAllocator<elem_type> allocator_type;

    ASSERT_EQ(sizeof (allocator_type::value_type),sizeof (elem_type));
    ASSERT_EQ(sizeof (allocator_type::pointer),sizeof (void*));
    ASSERT_EQ(sizeof (allocator_type::const_pointer),sizeof (void*));

    ASSERT_EQ(sizeof (allocator_type::size_type),sizeof (size_t));
    ASSERT_EQ(sizeof (allocator_type::difference_type),sizeof (ptrdiff_t));

    typedef int other_elem_type;
    ASSERT_EQ(sizeof (allocator_type::rebind<other_elem_type>::other::value_type), sizeof (other_elem_type));
}

TEST(Standard_StdAllocatorTestSuite, testContainers)
{
    //typed allocator
    std::list<TopoDS_Shape, Standard_StdAllocator<TopoDS_Shape> > aL;
    TopoDS_Solid aSolid = (TopoDS_Solid) BRepPrimAPI_MakeBox (10., 20., 30.);
    aL.push_back (aSolid);
    ASSERT_EQ(aL.size(), size_t (1));

    //type cast
    Standard_StdAllocator<char> aCAlloc;
    std::vector<int, Standard_StdAllocator<int> > aV (aCAlloc);
    aV.push_back(1);
    ASSERT_EQ(aV.size(), size_t (1));

/* disabled for now, it does not compile with g++ 4.7
    //using void-specialization allocator
    std::vector<int, Standard_StdAllocator<void> > aV2;
    aV2.resize(10);
    aV2.push_back(-1);
    ASSERT_EQ(aV2.size(), size_t (11));
 */
}

int main(int argc, char **argv){
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}