1#ifndef DUNE_GRID_IO_FILE_TEST_CHECKVTKFILE_HH
2#define DUNE_GRID_IO_FILE_TEST_CHECKVTKFILE_HH
20inline std::string pyq(
const std::string &s)
22 std::ostringstream result;
23 for(std::size_t i = 0; i < s.size(); ++i)
27 case '\'': result <<
"\\'";
break;
28 case '\\': result <<
"\\\\";
break;
29 case '\n': result <<
"\\n";
break;
31 if(c < 32 || c >= 127)
32 result <<
"\\x" << std::hex << std::setfill(
'0') << std::setw(2)
33 <<
static_cast<int>(c);
43inline std::string shq(
const std::string &s)
45 std::ostringstream result;
47 for(std::size_t i = 0; i < s.size(); ++i)
52 "Can't pass \\0 through the shell");
53 case '\'': result << (pend ?
"" :
"'") <<
"\\'"; pend =
true;
break;
54 default: result << (pend ?
"'" :
"") << c; pend =
false;
break;
57 if(pend) result <<
"'";
61inline int runShell(
const std::string &code)
63 int result = std::system(code.c_str());
68 return WEXITSTATUS(result);
69 if(WIFSIGNALED(result))
70 return WTERMSIG(result) + 256;
75inline int runPython(
const std::string &code)
77 return runShell(
"python -c '"+shq(code)+
"'");
80inline bool is_suffix(
const std::string &s,
const std::string &suffix)
82 return s.size() >= suffix.size() &&
83 s.compare(s.size() - suffix.size(), suffix.size(), suffix) == 0;
86inline int checkVTKFile(
const std::string &name)
88 static const bool havePythonVTK = [] {
91 if(runPython(
"from vtk import *") == 0)
93 std::cerr <<
"warning: python or python vtk module not available. This "
94 <<
"will result in skipped tests, since we cannot check that "
95 <<
"vtk can read the files we wrote." << std::endl;
100 std::cerr <<
"skip: " << name << std::endl;
105 if (is_suffix(name,
".vtu")) reader =
"vtkXMLUnstructuredGridReader";
106 else if(is_suffix(name,
".pvtu")) reader =
"vtkXMLPUnstructuredGridReader";
107 else if(is_suffix(name,
".vtp")) reader =
"vtkXMLPolyDataReader";
108 else if(is_suffix(name,
".pvtp")) reader =
"vtkXMLPPolyDataReader";
110 "Unknown vtk file extension: " << name);
112 std::cout <<
"Loading " << name <<
" using python vtk" << std::endl;
116 "reader = "+reader+
"();"
117 "reader.SetFileName('"+pyq(name)+
"');"
120 "sys.exit(not (reader.GetOutput().GetNumberOfCells() > 0));";
121 int result = runPython(pycode);
122 std::cout << (result == 0 ?
"pass: " :
"fail: ") << name << std::endl;
Default exception for dummy implementations.
Definition: exceptions.hh:261
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216