Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xdmf
Xdmf
Commits
f5cd8422
Commit
f5cd8422
authored
May 25, 2010
by
Kenneth Leiter
Browse files
ENH: Add test for XdmfGridCollection.
parent
28e67e9a
Changes
9
Hide whitespace changes
Inline
Side-by-side
XdmfArray.cpp
View file @
f5cd8422
...
...
@@ -485,7 +485,7 @@ std::string XdmfArray::getType() const
{
return
mHDF5Controller
->
getType
();
}
return
""
;
return
"
None
"
;
}
const
void
*
const
XdmfArray
::
getValuesPointer
()
const
...
...
@@ -536,22 +536,26 @@ void XdmfArray::initialize(const std::string & type, const unsigned int precisio
{
this
->
initialize
<
float
>
();
}
else
if
(
type
.
compare
(
"
Double
"
)
==
0
&&
precision
==
8
)
else
if
(
type
.
compare
(
"
Float
"
)
==
0
&&
precision
==
8
)
{
this
->
initialize
<
double
>
();
}
else
if
(
type
.
compare
(
"UChar"
)
==
0
&&
precision
==
8
)
else
if
(
type
.
compare
(
"UChar"
)
==
0
&&
precision
==
1
)
{
this
->
initialize
<
unsigned
char
>
();
}
else
if
(
type
.
compare
(
"UShort"
)
==
0
&&
precision
==
8
)
else
if
(
type
.
compare
(
"UShort"
)
==
0
&&
precision
==
2
)
{
this
->
initialize
<
unsigned
short
>
();
}
else
if
(
type
.
compare
(
"UInt"
)
==
0
&&
precision
==
8
)
else
if
(
type
.
compare
(
"UInt"
)
==
0
&&
precision
==
4
)
{
this
->
initialize
<
unsigned
int
>
();
}
else
if
(
type
.
compare
(
"None"
)
==
0
)
{
// No-op uninitialized!
}
else
{
assert
(
false
);
...
...
XdmfGrid.cpp
View file @
f5cd8422
...
...
@@ -150,7 +150,7 @@ void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemPrope
}
else
{
assert
(
false
);
//
assert(false);
}
}
}
...
...
XdmfGridCollection.cpp
View file @
f5cd8422
...
...
@@ -65,6 +65,7 @@ void XdmfGridCollection::insert(boost::shared_ptr<XdmfGrid> grid)
void
XdmfGridCollection
::
populateItem
(
const
std
::
map
<
std
::
string
,
std
::
string
>
&
itemProperties
,
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>
&
childItems
)
{
mCollectionType
=
XdmfGridCollectionType
::
New
(
itemProperties
);
for
(
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>::
const_iterator
iter
=
childItems
.
begin
();
iter
!=
childItems
.
end
();
++
iter
)
{
if
(
boost
::
shared_ptr
<
XdmfGrid
>
grid
=
boost
::
shared_dynamic_cast
<
XdmfGrid
>
(
*
iter
))
...
...
XdmfReader.cpp
View file @
f5cd8422
...
...
@@ -6,6 +6,7 @@
#include
"XdmfDomain.hpp"
#include
"XdmfGeometry.hpp"
#include
"XdmfGrid.hpp"
#include
"XdmfGridCollection.hpp"
#include
"XdmfSet.hpp"
#include
"XdmfTopology.hpp"
...
...
@@ -49,7 +50,15 @@ public:
}
else
if
(
itemTag
.
compare
(
XdmfGrid
::
ItemTag
)
==
0
)
{
newItem
=
XdmfGrid
::
New
();
std
::
map
<
std
::
string
,
std
::
string
>::
const_iterator
gridType
=
itemProperties
.
find
(
"GridType"
);
if
(
gridType
->
second
.
compare
(
"Collection"
)
==
0
)
{
newItem
=
XdmfGridCollection
::
New
();
}
else
{
newItem
=
XdmfGrid
::
New
();
}
}
else
if
(
itemTag
.
compare
(
XdmfSet
::
ItemTag
)
==
0
)
{
...
...
@@ -76,7 +85,15 @@ public:
if
(
currNode
->
type
==
XML_ELEMENT_NODE
)
{
std
::
map
<
std
::
string
,
std
::
string
>
itemProperties
;
itemProperties
[
"Content"
]
=
(
const
char
*
)
currNode
->
children
->
content
;
std
::
cout
<<
currNode
->
name
<<
std
::
endl
;
if
(
currNode
->
children
!=
NULL
)
{
itemProperties
[
"Content"
]
=
(
const
char
*
)
currNode
->
children
->
content
;
}
else
{
itemProperties
[
"Content"
]
=
""
;
}
xmlAttrPtr
currAttribute
=
currNode
->
properties
;
while
(
currAttribute
!=
NULL
)
{
...
...
@@ -104,7 +121,7 @@ XdmfReader::~XdmfReader()
std
::
cout
<<
"Deleted XdmfReader "
<<
this
<<
std
::
endl
;
}
boost
::
shared_ptr
<
Xdmf
Domain
>
XdmfReader
::
read
(
const
std
::
string
&
filePath
)
const
boost
::
shared_ptr
<
Xdmf
Item
>
XdmfReader
::
read
(
const
std
::
string
&
filePath
)
const
{
xmlDocPtr
document
;
xmlNodePtr
currNode
;
...
...
@@ -121,7 +138,7 @@ boost::shared_ptr<XdmfDomain> XdmfReader::read(const std::string & filePath) con
xmlFreeDoc
(
document
);
xmlCleanupParser
();
return
boost
::
shared_dynamic_cast
<
XdmfDomain
>
(
toReturn
[
0
]
)
;
return
toReturn
[
0
];
}
XdmfReader.hpp
View file @
f5cd8422
...
...
@@ -19,7 +19,7 @@ public:
XdmfNewMacro
(
XdmfReader
);
boost
::
shared_ptr
<
Xdmf
Domain
>
read
(
const
std
::
string
&
fileName
)
const
;
boost
::
shared_ptr
<
Xdmf
Item
>
read
(
const
std
::
string
&
fileName
)
const
;
protected:
...
...
tests/Cxx/CMakeLists.txt
View file @
f5cd8422
...
...
@@ -5,6 +5,7 @@ set(XdmfCxxTests
TestXdmfDataItem
TestXdmfGeometry
TestXdmfGrid
TestXdmfGridCollection
TestXdmfHDF5Writer
TestXdmfReader
TestXdmfSet
...
...
tests/Cxx/TestXdmfArray.cpp
View file @
f5cd8422
...
...
@@ -14,7 +14,7 @@ int main(int argc, char* argv[])
*/
boost
::
shared_ptr
<
XdmfArray
>
array
=
XdmfArray
::
New
();
assert
(
array
->
getSize
()
==
0
);
assert
(
array
->
getType
()
==
""
);
assert
(
array
->
getType
()
==
"
None
"
);
assert
(
array
->
getPrecision
()
==
0
);
assert
(
array
->
getValuesString
()
==
""
);
assert
(
array
->
getValuesPointer
()
==
NULL
);
...
...
tests/Cxx/TestXdmfGridCollection.cpp
0 → 100644
View file @
f5cd8422
#include
<fstream>
#include
<sstream>
#include
"XdmfGridCollection.hpp"
#include
"XdmfReader.hpp"
#include
"XdmfWriter.hpp"
#include
"XdmfTestDataGenerator.hpp"
int
main
(
int
argc
,
char
*
argv
[])
{
// Test != and == operators
assert
(
XdmfGridCollectionType
::
Spatial
()
==
XdmfGridCollectionType
::
Spatial
());
assert
(
XdmfGridCollectionType
::
Spatial
()
==
XdmfGridCollectionType
::
Temporal
()
==
false
);
assert
(
XdmfGridCollectionType
::
Spatial
()
!=
XdmfGridCollectionType
::
Spatial
()
==
false
);
assert
(
XdmfGridCollectionType
::
Spatial
()
!=
XdmfGridCollectionType
::
Temporal
());
boost
::
shared_ptr
<
XdmfGridCollection
>
gridCollection
=
XdmfGridCollection
::
New
();
gridCollection
->
setName
(
"Collection2"
);
assert
(
gridCollection
->
getName
().
compare
(
"Collection2"
)
==
0
);
boost
::
shared_ptr
<
XdmfGrid
>
childGrid1
=
XdmfTestDataGenerator
::
createHexahedron
();
boost
::
shared_ptr
<
XdmfGrid
>
childGrid2
=
XdmfTestDataGenerator
::
createHexahedron
();
assert
(
gridCollection
->
getNumberOfGrids
()
==
0
);
gridCollection
->
insert
(
childGrid1
);
assert
(
gridCollection
->
getNumberOfGrids
()
==
1
);
assert
(
gridCollection
->
getGrid
(
0
)
==
childGrid1
);
gridCollection
->
removeGrid
(
0
);
assert
(
gridCollection
->
getNumberOfGrids
()
==
0
);
gridCollection
->
insert
(
childGrid1
);
gridCollection
->
insert
(
childGrid2
);
gridCollection
->
setGridCollectionType
(
XdmfGridCollectionType
::
Temporal
());
boost
::
shared_ptr
<
XdmfWriter
>
writer
=
XdmfWriter
::
New
(
"TestXdmfGridCollection1.xmf"
);
gridCollection
->
accept
(
writer
);
boost
::
shared_ptr
<
XdmfReader
>
reader
=
XdmfReader
::
New
();
boost
::
shared_ptr
<
XdmfGridCollection
>
gridCollection2
=
boost
::
shared_dynamic_cast
<
XdmfGridCollection
>
(
reader
->
read
(
"TestXdmfGridCollection1.xmf"
));
boost
::
shared_ptr
<
XdmfWriter
>
writer2
=
XdmfWriter
::
New
(
"TestXdmfGridCollection2.xmf"
);
gridCollection2
->
accept
(
writer2
);
// Compare two files for equality
std
::
ifstream
firstFile
(
"TestXdmfGridCollection1.xmf"
);
std
::
ifstream
secondFile
(
"TestXdmfGridCollection2.xmf"
);
std
::
stringstream
firstBuffer
;
std
::
stringstream
secondBuffer
;
firstBuffer
<<
firstFile
.
rdbuf
();
secondBuffer
<<
secondFile
.
rdbuf
();
std
::
string
firstContents
(
firstBuffer
.
str
());
std
::
string
secondContents
(
secondBuffer
.
str
());
assert
(
firstContents
.
compare
(
secondContents
)
==
0
);
return
0
;
}
tests/Cxx/TestXdmfReader.cpp
View file @
f5cd8422
#include
<fstream>
#include
<sstream>
#include
"XdmfItem.hpp"
#include
"XdmfReader.hpp"
#include
"XdmfWriter.hpp"
...
...
@@ -16,26 +18,26 @@ int main(int argc, char* argv[])
domain
->
accept
(
writer
);
boost
::
shared_ptr
<
XdmfReader
>
reader
=
XdmfReader
::
New
();
boost
::
shared_ptr
<
XdmfDomain
>
readDomain
=
reader
->
read
(
"TestXdmfReader1.xmf"
);
boost
::
shared_ptr
<
XdmfDomain
>
readDomain
=
boost
::
shared_dynamic_cast
<
XdmfDomain
>
(
reader
->
read
(
"TestXdmfReader1.xmf"
)
)
;
boost
::
shared_ptr
<
XdmfWriter
>
writer2
=
XdmfWriter
::
New
(
"TestXdmfReader2.xmf"
);
readDomain
->
accept
(
writer2
);
// Compare two files for equality
std
::
ifstream
firstFile
(
"TestXdmfReader1.xmf"
);
std
::
ifstream
secondFile
(
"TestXdmfReader2.xmf"
);
std
::
string
firstLine
;
std
::
string
secondLine
;
while
(
!
firstFile
.
eof
())
{
std
::
getline
(
firstFile
,
firstLine
);
std
::
getline
(
secondFile
,
secondLine
);
if
(
firstLine
.
compare
(
secondLine
)
!=
0
)
{
assert
(
false
);
}
}
std
::
stringstream
firstBuffer
;
std
::
stringstream
secondBuffer
;
firstBuffer
<<
firstFile
.
rdbuf
();
secondBuffer
<<
secondFile
.
rdbuf
();
std
::
string
firstContents
(
firstBuffer
.
str
());
std
::
string
secondContents
(
secondBuffer
.
str
());
assert
(
firstContents
.
compare
(
secondContents
)
==
0
);
return
0
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment