Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jacobsa-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
jacobsa-fuse
Commits
e7b9860f
Commit
e7b9860f
authored
Dec 19, 2016
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
buffer_test: expand the coverage of TestOutMessageGrow.
parent
02e3f789
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
12 deletions
+30
-12
internal/buffer/out_message_test.go
internal/buffer/out_message_test.go
+30
-12
No files found.
internal/buffer/out_message_test.go
View file @
e7b9860f
...
...
@@ -144,26 +144,44 @@ func TestOutMessageReset(t *testing.T) {
func
TestOutMessageGrow
(
t
*
testing
.
T
)
{
var
om
OutMessage
om
.
Reset
()
// Set up garbage where the payload will soon be.
const
payloadSize
=
1234
{
p
:=
om
.
GrowNoZero
(
payloadSize
)
if
p
==
nil
{
t
.
Fatal
(
"GrowNoZero failed"
)
}
// Overwrite with garbage.
err
:=
fillWithGarbage
(
unsafe
.
Pointer
(
&
om
),
int
(
unsafe
.
Sizeof
(
om
)))
if
err
!=
nil
{
t
.
Fatalf
(
"fillWithGarbage: %v"
,
err
)
err
:=
fillWithGarbage
(
p
,
payloadSize
)
if
err
!=
nil
{
t
.
Fatalf
(
"fillWithGarbage: %v"
,
err
)
}
om
.
ShrinkTo
(
OutMessageInitialSize
)
}
// Zero the header.
om
.
Reset
()
// Call Grow.
if
p
:=
om
.
Grow
(
payloadSize
);
p
==
nil
{
t
.
Fatal
(
"Grow failed"
)
}
// Grow to the max size. This should zero the message.
if
p
:=
om
.
Grow
(
MaxReadSize
);
p
==
nil
{
t
.
Fatal
(
"Grow returned nil"
)
// Check the resulting length in two ways.
const
wantLen
=
int
(
payloadSize
+
OutMessageInitialSize
)
if
got
,
want
:=
om
.
Len
(),
wantLen
;
got
!=
want
{
t
.
Errorf
(
"om.Len() = %d, want %d"
,
got
)
}
// Check that everything has been zeroed.
b
:=
om
.
Bytes
()
for
i
,
x
:=
range
b
{
if
got
,
want
:=
len
(
b
),
wantLen
;
got
!=
want
{
t
.
Fatalf
(
"len(om.Len()) = %d, want %d"
,
got
)
}
// Check that the payload was zeroed.
for
i
,
x
:=
range
b
[
OutMessageInitialSize
:
]
{
if
x
!=
0
{
t
.
Fatalf
(
"non-zero byte 0x%02x at offset %d"
,
x
,
i
)
t
.
Fatalf
(
"non-zero byte 0x%02x at
payload
offset %d"
,
x
,
i
)
}
}
}
...
...
Write
Preview
Markdown
is supported
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