Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
Trivial serialization for C++ - tscpp
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
Third Party
Trivial serialization for C++ - tscpp
Commits
fd24b193
Commit
fd24b193
authored
7 years ago
by
Federico
Browse files
Options
Downloads
Patches
Plain Diff
Testing error code paths in stream serializers
parent
c5c817dd
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/5_stream_failtest.cpp
+128
-0
128 additions, 0 deletions
examples/5_stream_failtest.cpp
examples/Makefile
+8
-5
8 additions, 5 deletions
examples/Makefile
with
136 additions
and
5 deletions
examples/5_stream_failtest.cpp
0 → 100644
+
128
−
0
View file @
fd24b193
#include
<iostream>
#include
<sstream>
#include
<cassert>
#include
<tscpp.h>
#include
"types.h"
using
namespace
std
;
using
namespace
tscpp
;
int
main
()
{
//eof during type name in InputArchive
{
stringstream
ss
;
InputArchive
ia
(
ss
);
Point3d
p
;
try
{
ia
>>
p
;
assert
(
false
);
}
catch
(
TscppException
&
ex
)
{
assert
(
string
(
ex
.
what
())
==
"eof"
);
assert
(
ex
.
name
()
==
""
);
assert
(
p
.
x
==
0
&&
p
.
y
==
0
&&
p
.
z
==
0
);
}
}
//wrong type in InputArchive
{
stringstream
ss
;
OutputArchive
oa
(
ss
);
Point3d
p
(
1
,
2
,
3
);
oa
<<
p
;
InputArchive
ia
(
ss
);
Point2d
q
;
try
{
ia
>>
q
;
assert
(
false
);
}
catch
(
TscppException
&
ex
)
{
assert
(
ss
.
tellg
()
==
0
);
assert
(
string
(
ex
.
what
())
==
"wrong type"
);
assert
(
ex
.
name
()
==
typeid
(
p
).
name
());
assert
(
q
.
x
==
0
&&
q
.
y
==
0
);
}
}
//eof after type name in InputArchive
{
stringstream
ss
;
OutputArchive
oa
(
ss
);
Point3d
p
(
1
,
2
,
3
);
oa
<<
p
;
string
s
=
ss
.
str
();
s
.
pop_back
();
//Remove one char
ss
.
str
(
s
);
InputArchive
ia
(
ss
);
Point3d
q
;
try
{
ia
>>
q
;
assert
(
false
);
}
catch
(
TscppException
&
ex
)
{
assert
(
string
(
ex
.
what
())
==
"eof"
);
assert
(
ex
.
name
()
==
""
);
}
}
TypePool
tp
;
tp
.
registerType
<
Point2d
>
([
&
](
Point2d
&
t
)
{
assert
(
false
);
});
tp
.
registerType
<
Point3d
>
([
&
](
Point3d
&
t
)
{
assert
(
false
);
});
//eof during type name in UnknownInputArchive
{
stringstream
ss
;
UnknownInputArchive
ia
(
ss
,
tp
);
try
{
ia
.
unserialize
();
assert
(
false
);
}
catch
(
TscppException
&
ex
)
{
assert
(
string
(
ex
.
what
())
==
"eof"
);
assert
(
ex
.
name
()
==
""
);
}
}
//unknown type in UnknownInputArchive
{
stringstream
ss
;
OutputArchive
oa
(
ss
);
MiscData
md
;
oa
<<
md
;
UnknownInputArchive
ia
(
ss
,
tp
);
try
{
ia
.
unserialize
();
assert
(
false
);
}
catch
(
TscppException
&
ex
)
{
assert
(
ss
.
tellg
()
==
0
);
assert
(
string
(
ex
.
what
())
==
"unknown type"
);
assert
(
ex
.
name
()
==
typeid
(
md
).
name
());
}
}
//eof after type name in UnknownInputArchive
{
stringstream
ss
;
OutputArchive
oa
(
ss
);
Point3d
p
(
1
,
2
,
3
);
oa
<<
p
;
string
s
=
ss
.
str
();
s
.
pop_back
();
//Remove one char
ss
.
str
(
s
);
UnknownInputArchive
ia
(
ss
,
tp
);
try
{
ia
.
unserialize
();
assert
(
false
);
}
catch
(
TscppException
&
ex
)
{
assert
(
string
(
ex
.
what
())
==
"eof"
);
assert
(
ex
.
name
()
==
""
);
}
}
cout
<<
"Test passed"
<<
endl
;
}
This diff is collapsed.
Click to expand it.
examples/Makefile
+
8
−
5
View file @
fd24b193
...
...
@@ -7,10 +7,13 @@ all:
$(
CXX
)
$(
CXXFLAGS
)
2_stream_unknown.cpp ../tscpp.cpp
-o
2_stream_unknown
$(
CXX
)
$(
CXXFLAGS
)
3_buffer_known.cpp ../tscpp.cpp
-o
3_buffer_known
$(
CXX
)
$(
CXXFLAGS
)
4_buffer_unknown.cpp ../tscpp.cpp
-o
4_buffer_unknown
$(
CXX
)
$(
CXXFLAGS
)
5_stream_failtest.cpp ../tscpp.cpp
-o
5_stream_failtest
./1_stream_known
./2_stream_unknown
./3_buffer_known
./4_buffer_unknown
./5_stream_failtest
clean
:
rm
-f
1_stream_known 2_stream_unknown 3_buffer_known 4_buffer_unknown
rm
-f
1_stream_known 2_stream_unknown 3_buffer_known 4_buffer_unknown
\
5_stream_failtest
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