File: DataGeneratorsTest.h

package info (click to toggle)
libloki 0.1.7-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,608 kB
  • sloc: cpp: 30,475; ansic: 1,974; makefile: 365; php: 316; perl: 108
file content (64 lines) | stat: -rw-r--r-- 2,022 bytes parent folder | download | duplicates (5)
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
// $Id: DataGeneratorsTest.h 760 2006-10-17 20:36:13Z syntheticpp $

//DataGeneratorsTest.h


#ifndef DATAGENERATORSTEST_H
#define DATAGENERATORSTEST_H

#include <typeinfo>
#include <loki/DataGenerators.h>

struct DataGeneratorsTest : public Test
  {
  DataGeneratorsTest() : Test("DataGeneratorsTest.h")
    {}
  virtual void execute(TestResult& result)
    {
    this->printName(result);
    
    using namespace Loki;
    using namespace Loki::TL;
    
    bool b;
    typedef MakeTypelist<>::Result null_tl;
    typedef MakeTypelist<char,
                         unsigned char,
                         signed char,
                         wchar_t>::Result char_types;
    std::size_t n = Length<char_types>::value;
    
    std::vector<const char*> names;
    names.reserve(n);
    //Some fascist decided that all temporaries should be const.
    //The following line of code stupidity is a direct result of the half-baked idea
    iterate_types<char_types, nameof_type>(std::back_inserter(names));
    b = names.size() == n;
    testAssert("iterate_types - Check Length", b, result);
    
    std::vector<size_t> sizes;
    sizes.reserve(n);
    typedef MakeTypelist<char,
                         short,
                         int,
                         double>::Result some_types;
    iterate_types<some_types, sizeof_type>(std::back_inserter(sizes));
    size_t apriori_size[] = {sizeof(char), sizeof(short), sizeof(int), sizeof(double)};
    b = true;
    for(std::size_t i=0; i<n; ++i)
      b &= sizes[i] == apriori_size[i];
    testAssert("iterate_types - Check Elements", b, result);
    
    sizes.resize(0);
    iterate_types<null_tl, sizeof_type>(sizes);
    b = sizes.size() == 0;
    testAssert("iterate_types - Degenerate Case 1 - Null List", b, result);

    sizes.resize(0);
    iterate_types<Loki::NullType, sizeof_type>(sizes);
    b = sizes.size() == 0;
    testAssert("iterate_types - Degenerate Case 2 - NullType", b, result);
    }
  } datageneratorsTest;

#endif //DATAGENERATORSTEST_H