Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bytes-sgx
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
Service Desk
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
Markus Becker
bytes-sgx
Commits
40f1d1aa
Commit
40f1d1aa
authored
9 years ago
by
Florian Hartwig
Browse files
Options
Downloads
Patches
Plain Diff
Add some basic tests for RingBuf
parent
c4546493
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/test.rs
+1
-0
1 addition, 0 deletions
test/test.rs
test/test_ring.rs
+66
-0
66 additions, 0 deletions
test/test_ring.rs
with
67 additions
and
0 deletions
test/test.rs
+
1
−
0
View file @
40f1d1aa
...
...
@@ -7,6 +7,7 @@ mod test_buf;
mod
test_buf_fill
;
mod
test_byte_buf
;
mod
test_bytes
;
mod
test_ring
;
mod
test_rope
;
mod
test_seq_byte_str
;
mod
test_small_byte_str
;
...
...
This diff is collapsed.
Click to expand it.
test/test_ring.rs
0 → 100644
+
66
−
0
View file @
40f1d1aa
use
bytes
::
RingBuf
;
#[test]
pub
fn
test_initial_buf_empty
()
{
use
bytes
::
traits
::{
Buf
,
BufExt
,
MutBuf
,
MutBufExt
};
let
mut
buf
=
RingBuf
::
new
(
16
);
assert_eq!
(
MutBuf
::
remaining
(
&
buf
),
16
);
assert_eq!
(
Buf
::
remaining
(
&
buf
),
0
);
let
bytes_written
=
buf
.write
(
&
[
1
,
2
,
3
][
..
])
.unwrap
();
assert_eq!
(
bytes_written
,
3
);
let
bytes_written
=
buf
.write
(
&
[][
..
])
.unwrap
();
assert_eq!
(
bytes_written
,
0
);
assert_eq!
(
MutBuf
::
remaining
(
&
buf
),
13
);
assert_eq!
(
Buf
::
remaining
(
&
buf
),
3
);
assert_eq!
(
buf
.bytes
(),
[
1
,
2
,
3
]);
let
mut
out
=
[
0u8
;
3
];
let
bytes_read
=
buf
.read
(
&
mut
out
[
..
])
.unwrap
();;
assert_eq!
(
bytes_read
,
3
);
assert_eq!
(
out
,
[
1
,
2
,
3
]);
assert_eq!
(
MutBuf
::
remaining
(
&
buf
),
16
);
assert_eq!
(
Buf
::
remaining
(
&
buf
),
0
);
}
#[test]
fn
test_wrapping_write
()
{
use
bytes
::
traits
::{
BufExt
,
MutBufExt
};
let
mut
buf
=
RingBuf
::
new
(
16
);
let
mut
out
=
[
0
;
10
];
buf
.write
(
&
[
42
;
12
][
..
])
.unwrap
();
let
bytes_read
=
buf
.read
(
&
mut
out
[
..
])
.unwrap
();
assert_eq!
(
bytes_read
,
10
);
let
bytes_written
=
buf
.write
(
&
[
23
;
8
][
..
])
.unwrap
();
assert_eq!
(
bytes_written
,
8
);
let
bytes_read
=
buf
.read
(
&
mut
out
[
..
])
.unwrap
();
assert_eq!
(
bytes_read
,
10
);
assert_eq!
(
out
,
[
42
,
42
,
23
,
23
,
23
,
23
,
23
,
23
,
23
,
23
]);
}
#[test]
fn
test_io_write_and_read
()
{
use
std
::
io
::{
Read
,
Write
};
let
mut
buf
=
RingBuf
::
new
(
16
);
let
mut
out
=
[
0
;
8
];
let
written
=
buf
.write
(
&
[
1
;
8
][
..
])
.unwrap
();
assert_eq!
(
written
,
8
);
buf
.read
(
&
mut
out
)
.unwrap
();
assert_eq!
(
out
,
[
1
;
8
]);
let
written
=
buf
.write
(
&
[
2
;
8
][
..
])
.unwrap
();
assert_eq!
(
written
,
8
);
let
bytes_read
=
buf
.read
(
&
mut
out
)
.unwrap
();
assert_eq!
(
bytes_read
,
8
);
assert_eq!
(
out
,
[
2
;
8
]);
}
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