Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Armin Wehrfritz
Xdmf
Commits
55717ca0
Commit
55717ca0
authored
May 08, 2014
by
Kenneth Leiter
Browse files
ENH: Actually commit binary reader test.
parent
4117b095
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/Cxx/TestXdmfBinaryController.cpp
0 → 100644
View file @
55717ca0
#include
<fstream>
#include
<vector>
#include
"XdmfArray.hpp"
#include
"XdmfArrayType.hpp"
#include
"XdmfBinaryController.hpp"
#include
"XdmfReader.hpp"
#include
"XdmfWriter.hpp"
int
main
(
int
,
char
**
)
{
//
// write binary file
//
std
::
vector
<
int
>
outputData
;
outputData
.
push_back
(
1
);
outputData
.
push_back
(
0
);
outputData
.
push_back
(
-
1
);
outputData
.
push_back
(
100
);
std
::
ofstream
output
(
"binary.bin"
,
std
::
ofstream
::
binary
);
output
.
write
(
reinterpret_cast
<
char
*>
(
&
(
outputData
[
0
])),
sizeof
(
int
)
*
outputData
.
size
());
output
.
close
();
//
// read binary file using XdmfBinaryController
//
shared_ptr
<
XdmfBinaryController
>
binaryController
=
XdmfBinaryController
::
New
(
"binary.bin"
,
XdmfArrayType
::
Int32
(),
XdmfBinaryController
::
NATIVE
,
0
,
std
::
vector
<
unsigned
int
>
(
1
,
4
));
shared_ptr
<
XdmfArray
>
testArray
=
XdmfArray
::
New
();
testArray
->
setHeavyDataController
(
binaryController
);
testArray
->
read
();
assert
(
testArray
->
getSize
()
==
4
);
assert
(
testArray
->
getValue
<
int
>
(
0
)
==
outputData
[
0
]);
assert
(
testArray
->
getValue
<
int
>
(
1
)
==
outputData
[
1
]);
assert
(
testArray
->
getValue
<
int
>
(
2
)
==
outputData
[
2
]);
assert
(
testArray
->
getValue
<
int
>
(
3
)
==
outputData
[
3
]);
testArray
->
release
();
//
// output array to disk
//
shared_ptr
<
XdmfWriter
>
writer
=
XdmfWriter
::
New
(
"TestXdmfBinary.xmf"
);
writer
->
setMode
(
XdmfWriter
::
DistributedHeavyData
);
testArray
->
accept
(
writer
);
//
// read array in
//
shared_ptr
<
XdmfReader
>
reader
=
XdmfReader
::
New
();
shared_ptr
<
XdmfArray
>
array
=
shared_dynamic_cast
<
XdmfArray
>
(
reader
->
read
(
"TestXdmfBinary.xmf"
));
assert
(
array
!=
NULL
);
return
0
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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