Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
dbab0a34
Commit
dbab0a34
authored
Aug 20, 2021
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for OFStream
parent
bec8f051
No related branches found
No related tags found
1 merge request
!111
Add ofstream support within the language
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/language/utils/OFStream.hpp
+2
-2
2 additions, 2 deletions
src/language/utils/OFStream.hpp
tests/CMakeLists.txt
+1
-0
1 addition, 0 deletions
tests/CMakeLists.txt
tests/test_OFStream.cpp
+49
-0
49 additions, 0 deletions
tests/test_OFStream.cpp
with
52 additions
and
2 deletions
src/language/utils/OFStream.hpp
+
2
−
2
View file @
dbab0a34
...
...
@@ -5,7 +5,7 @@
#include
<fstream>
class
OFStream
:
public
OStream
class
OFStream
final
:
public
OStream
{
private:
std
::
ofstream
m_fstream
;
...
...
@@ -13,7 +13,7 @@ class OFStream : public OStream
public:
OFStream
(
const
std
::
string
&
filename
);
OFStream
()
=
de
fault
;
OFStream
()
=
de
lete
;
~
OFStream
()
=
default
;
};
...
...
This diff is collapsed.
Click to expand it.
tests/CMakeLists.txt
+
1
−
0
View file @
dbab0a34
...
...
@@ -115,6 +115,7 @@ add_executable (mpi_unit_tests
test_ItemValue.cpp
test_ItemValueUtils.cpp
test_Messenger.cpp
test_OFStream.cpp
test_Partitioner.cpp
test_RandomEngine.cpp
test_SubItemValuePerItem.cpp
...
...
This diff is collapsed.
Click to expand it.
tests/test_OFStream.cpp
0 → 100644
+
49
−
0
View file @
dbab0a34
#include
<catch2/catch_test_macros.hpp>
#include
<catch2/matchers/catch_matchers_all.hpp>
#include
<language/utils/OFStream.hpp>
#include
<utils/Messenger.hpp>
#include
<filesystem>
// clazy:excludeall=non-pod-global-static
TEST_CASE
(
"OFStream"
,
"[language]"
)
{
SECTION
(
"ofstream"
)
{
const
std
::
string
basename
=
"ofstream_"
;
const
std
::
string
filename
=
basename
+
std
::
to_string
(
parallel
::
rank
());
// Ensures that the file is closed after this line
std
::
make_shared
<
OFStream
>
(
filename
)
<<
"foo"
<<
3
<<
" bar
\n
"
;
if
(
parallel
::
rank
()
==
0
)
{
REQUIRE
(
std
::
filesystem
::
is_regular_file
(
filename
));
std
::
ifstream
is
(
filename
);
char
file_content
[
10
];
for
(
size_t
i
=
0
;
i
<
10
;
++
i
)
{
char
c
=
is
.
get
();
file_content
[
i
]
=
c
;
if
(
c
==
'\n'
)
{
file_content
[
i
+
1
]
=
'\0'
;
REQUIRE
(
i
==
8
);
c
=
is
.
get
();
REQUIRE
(
is
.
eof
());
break
;
}
}
std
::
string
content
=
file_content
;
REQUIRE
(
content
==
"foo3 bar
\n
"
);
std
::
filesystem
::
remove
(
filename
);
}
REQUIRE
(
not
std
::
filesystem
::
exists
(
filename
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment