File: UnitTestInformationKeys.cxx

package info (click to toggle)
vtk7 7.1.1%2Bdfsg2-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 127,396 kB
  • sloc: cpp: 1,539,584; ansic: 124,382; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 126; objc: 83
file content (165 lines) | stat: -rw-r--r-- 4,543 bytes parent folder | download | duplicates (3)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "vtkInformation.h"
#include "vtkInformationDoubleKey.h"
#include "vtkInformationDoubleVectorKey.h"
#include "vtkInformationStringKey.h"
#include "vtkInformationStringVectorKey.h"
#include "vtkInformationVariantKey.h"
#include "vtkInformationVariantVectorKey.h"
#include "vtkNew.h"
#include "vtkStdString.h"
#include "vtkVariant.h"

template<typename T, typename V>
int UnitTestScalarValueKey(vtkInformation* info, T* key, const V& val)
{
  key->Set(info, val);
  int ok_setget = (val == key->Get(info));
  if (!ok_setget)
  {
    cerr << "Set + Get not reflexive.\n";
  }

  vtkNew<vtkInformation> shinyNew;
  key->ShallowCopy(info, shinyNew.GetPointer());
  int ok_copyget = (val == key->Get(shinyNew.GetPointer()));
  if (!ok_copyget)
  {
    cerr << "Copy + Get not reflexive.\n";
  }

  return ok_setget & ok_copyget;
}

template<typename T, typename V>
int UnitTestVectorValueKey(vtkInformation* info, T* key, const V& val)
{
  key->Set(info, const_cast<V*>(&val), 1);
  int ok_setget = (val == key->Get(info, 0));
  if (!ok_setget)
  {
    cerr << "Set + get not reflexive.\n";
  }
  int ok_setgetcomp = (val == *key->Get(info));
  if (!ok_setgetcomp)
  {
    cerr << "Set + component-wise-get not reflexive.\n";
  }

  vtkNew<vtkInformation> shinyNew;
  key->ShallowCopy(info, shinyNew.GetPointer());
  int ok_copyget = (val == *key->Get(shinyNew.GetPointer()));
  if (!ok_copyget)
  {
    cerr << "Copy + get not reflexive.\n";
  }

  int ok_length = (key->Length(info) == 1);
  if (!ok_length)
  {
    cerr << "Length was " << key->Length(info) << " not 1.\n";
  }
  key->Append(info, val);
  int ok_appendedlength = (key->Length(info) == 2);
  if (!ok_appendedlength)
  {
    cerr << "Appended length was " << key->Length(info) << " not 2.\n";
  }

  return
    ok_setget && ok_setgetcomp && ok_copyget &&
    ok_length && ok_appendedlength;
}

// === String adaptations of tests above ===
// Note these are not specializations.

int UnitTestScalarValueKey(
  vtkInformation* info, vtkInformationStringKey* key,
  const vtkStdString& val)
{
  key->Set(info, val.c_str());
  int ok_setget = (val == key->Get(info));
  if (!ok_setget)
  {
    cerr << "Set + Get not reflexive.\n";
  }

  vtkNew<vtkInformation> shinyNew;
  key->ShallowCopy(info, shinyNew.GetPointer());
  int ok_copyget = (val == key->Get(shinyNew.GetPointer()));
  if (!ok_copyget)
  {
    cerr << "Copy + Get not reflexive.\n";
  }

  return ok_setget & ok_copyget;
}

int UnitTestVectorValueKey(
  vtkInformation* info, vtkInformationStringVectorKey* key,
  const vtkStdString& val)
{
  key->Set(info, val.c_str(), 0);
  int ok_setgetcomp = (val == key->Get(info, 0));
  if (!ok_setgetcomp)
  {
    cerr << "Set + get not reflexive.\n";
  }

  vtkNew<vtkInformation> shinyNew;
  key->ShallowCopy(info, shinyNew.GetPointer());
  int ok_copyget = (val == key->Get(shinyNew.GetPointer(), 0));
  if (!ok_copyget)
  {
    cerr << "Copy + get not reflexive.\n";
  }

  int ok_length = (key->Length(info) == 1);
  if (!ok_length)
  {
    cerr << "Length was " << key->Length(info) << " not 1.\n";
  }
  key->Append(info, val.c_str());
  int ok_appendedlength = (key->Length(info) == 2);
  if (!ok_appendedlength)
  {
    cerr << "Appended length was " << key->Length(info) << " not 2.\n";
  }

  return ok_setgetcomp && ok_copyget && ok_length && ok_appendedlength;
}

int UnitTestInformationKeys(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
{
  int ok = 1;
  vtkNew<vtkInformation> info;
  vtkVariant tvval("foo");
  double tdval = 3.14159;
  vtkStdString tsval = "bar";

  vtkInformationVariantKey* tvskey =
    new vtkInformationVariantKey("Test", "vtkTest");
  ok &= UnitTestScalarValueKey(info.GetPointer(), tvskey, tvval);

  vtkInformationVariantVectorKey* tvvkey =
    new vtkInformationVariantVectorKey("Test", "vtkTest");
  ok &= UnitTestVectorValueKey(info.GetPointer(), tvvkey, tvval);

  vtkInformationDoubleKey* tdskey =
    new vtkInformationDoubleKey("Test", "vtkTest");
  ok &= UnitTestScalarValueKey(info.GetPointer(), tdskey, tdval);

  vtkInformationDoubleVectorKey* tdvkey =
    new vtkInformationDoubleVectorKey("Test", "vtkTest");
  ok &= UnitTestVectorValueKey(info.GetPointer(), tdvkey, tdval);

  vtkInformationStringKey* tsskey =
    new vtkInformationStringKey("Test", "vtkTest");
  ok &= UnitTestScalarValueKey(info.GetPointer(), tsskey, tsval);

  vtkInformationStringVectorKey* tsvkey =
    new vtkInformationStringVectorKey("Test", "vtkTest");
  ok &= UnitTestVectorValueKey(info.GetPointer(), tsvkey, tsval);

  return ! ok;
}