VTK
vtkTestUtilities.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkTestUtilities.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
30 #ifndef vtkTestUtilities_h
31 #define vtkTestUtilities_h
32 
33 #include "vtkSystemIncludes.h"
34 
35 #if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
36 #pragma warning( disable : 4996 ) // 'function': was declared deprecated
37 #endif
38 
40 {
44  static inline char* GetDataRoot(int argc, char* argv[]);
45 
47 
53  static inline char* ExpandDataFileName(int argc, char* argv[],
54  const char* fname,
55  int slash = 0);
57 
58 
61  static inline char* GetArgOrEnvOrDefault(const char* arg,
62  int argc, char* argv[],
63  const char* env,
64  const char* def);
66 
68 
74  static inline char* ExpandFileNameWithArgOrEnvOrDefault(const char* arg,
75  int argc, char* argv[],
76  const char* env,
77  const char* def,
78  const char* fname,
79  int slash = 0);
80 };
82 
83 inline
84 char* vtkTestUtilities::GetDataRoot(int argc, char* argv[])
85 {
87  "-D", argc, argv,
88  "VTK_DATA_ROOT",
89  "../../../../VTKData");
90 }
91 
92 inline
93 char* vtkTestUtilities::ExpandDataFileName(int argc, char* argv[],
94  const char* fname,
95  int slash)
96 {
98  "-D", argc, argv,
99  "VTK_DATA_ROOT",
100  "../../../../VTKData",
101  fname,
102  slash);
103 }
104 
105 inline
107  int argc, char* argv[],
108  const char* env,
109  const char *def)
110 {
111  int index = -1;
112 
113  for (int i = 0; i < argc; i++)
114  {
115  if (strcmp(arg, argv[i]) == 0 && i < argc - 1)
116  {
117  index = i + 1;
118  }
119  }
120 
121  char* value;
122 
123  if (index != -1)
124  {
125  value = new char[strlen(argv[index]) + 1];
126  strcpy(value, argv[index]);
127  }
128  else
129  {
130  char *foundenv = getenv(env);
131  if (foundenv)
132  {
133  value = new char[strlen(foundenv) + 1];
134  strcpy(value, foundenv);
135  }
136  else if (def)
137  {
138  value = new char[strlen(def) + 1];
139  strcpy(value, def);
140  }
141  else
142  {
143  value = NULL;
144  }
145  }
146 
147  return value;
148 }
149 
150 inline
152  int argc,
153  char* argv[],
154  const char* env,
155  const char *def,
156  const char* fname,
157  int slash)
158 {
159  char* fullName;
160 
161  char* value = vtkTestUtilities::GetArgOrEnvOrDefault(arg, argc, argv,
162  env,
163  def);
164  if (value)
165  {
166  fullName = new char[strlen(value) + strlen(fname) + 2 +
167  static_cast<size_t>(slash ? 1 : 0)];
168  fullName[0] = 0;
169  strcat(fullName, value);
170  size_t len = strlen(fullName);
171  fullName[len] = '/';
172  fullName[len+1] = 0;
173  strcat(fullName, fname);
174  }
175  else
176  {
177  fullName = new char[strlen(fname) + 1 + static_cast<size_t>(slash ? 1 : 0)];
178  strcpy(fullName, fname);
179  }
180 
181  if (slash)
182  {
183  strcat(fullName, "/");
184  }
185 
186  delete[] value;
187 
188  return fullName;
189 }
190 
191 #endif // vtkTestUtilities_h
static char * ExpandFileNameWithArgOrEnvOrDefault(const char *arg, int argc, char *argv[], const char *env, const char *def, const char *fname, int slash=0)
static char * ExpandDataFileName(int argc, char *argv[], const char *fname, int slash=0)
static char * GetDataRoot(int argc, char *argv[])
Utility functions used for regression testing.
static char * GetArgOrEnvOrDefault(const char *arg, int argc, char *argv[], const char *env, const char *def)