Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
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
Container registry
Model registry
Operate
Environments
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
tci-gateway-module
Grpc
Commits
6adc1730
Commit
6adc1730
authored
9 years ago
by
Craig Tiller
Browse files
Options
Downloads
Plain Diff
Merge pull request #4316 from sreecha/support_coverage
Improve test coverage for slice_buffer
parents
9c053048
ea4b3c60
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/core/support/slice_buffer_test.c
+56
-2
56 additions, 2 deletions
test/core/support/slice_buffer_test.c
with
56 additions
and
2 deletions
test/core/support/slice_buffer_test.c
+
56
−
2
View file @
6adc1730
...
@@ -35,13 +35,12 @@
...
@@ -35,13 +35,12 @@
#include
<grpc/support/slice_buffer.h>
#include
<grpc/support/slice_buffer.h>
#include
"test/core/util/test_config.h"
#include
"test/core/util/test_config.h"
int
main
(
int
argc
,
char
**
argv
)
{
void
test_slice_buffer_add
(
)
{
gpr_slice_buffer
buf
;
gpr_slice_buffer
buf
;
gpr_slice
aaa
=
gpr_slice_from_copied_string
(
"aaa"
);
gpr_slice
aaa
=
gpr_slice_from_copied_string
(
"aaa"
);
gpr_slice
bb
=
gpr_slice_from_copied_string
(
"bb"
);
gpr_slice
bb
=
gpr_slice_from_copied_string
(
"bb"
);
size_t
i
;
size_t
i
;
grpc_test_init
(
argc
,
argv
);
gpr_slice_buffer_init
(
&
buf
);
gpr_slice_buffer_init
(
&
buf
);
for
(
i
=
0
;
i
<
10
;
i
++
)
{
for
(
i
=
0
;
i
<
10
;
i
++
)
{
gpr_slice_ref
(
aaa
);
gpr_slice_ref
(
aaa
);
...
@@ -70,6 +69,61 @@ int main(int argc, char **argv) {
...
@@ -70,6 +69,61 @@ int main(int argc, char **argv) {
GPR_ASSERT
(
buf
.
count
==
0
);
GPR_ASSERT
(
buf
.
count
==
0
);
GPR_ASSERT
(
buf
.
length
==
0
);
GPR_ASSERT
(
buf
.
length
==
0
);
gpr_slice_buffer_destroy
(
&
buf
);
gpr_slice_buffer_destroy
(
&
buf
);
}
void
test_slice_buffer_move_first
()
{
gpr_slice
slices
[
3
];
gpr_slice_buffer
src
;
gpr_slice_buffer
dst
;
int
idx
=
0
;
size_t
src_len
=
0
;
size_t
dst_len
=
0
;
slices
[
0
]
=
gpr_slice_from_copied_string
(
"aaa"
);
slices
[
1
]
=
gpr_slice_from_copied_string
(
"bbbb"
);
slices
[
2
]
=
gpr_slice_from_copied_string
(
"ccc"
);
gpr_slice_buffer_init
(
&
src
);
gpr_slice_buffer_init
(
&
dst
);
for
(
idx
=
0
;
idx
<
3
;
idx
++
)
{
gpr_slice_ref
(
slices
[
idx
]);
/* For this test, it is important that we add each slice at a new
slice index */
gpr_slice_buffer_add_indexed
(
&
src
,
slices
[
idx
]);
gpr_slice_buffer_add_indexed
(
&
dst
,
slices
[
idx
]);
}
/* Case 1: Move more than the first slice's length from src to dst */
src_len
=
src
.
length
;
dst_len
=
dst
.
length
;
gpr_slice_buffer_move_first
(
&
src
,
4
,
&
dst
);
src_len
-=
4
;
dst_len
+=
4
;
GPR_ASSERT
(
src
.
length
==
src_len
);
GPR_ASSERT
(
dst
.
length
==
dst_len
);
/* src now has two slices ["bbb"] and ["ccc"] */
/* Case 2: Move the first slice from src to dst */
gpr_slice_buffer_move_first
(
&
src
,
3
,
&
dst
);
src_len
-=
3
;
dst_len
+=
3
;
GPR_ASSERT
(
src
.
length
==
src_len
);
GPR_ASSERT
(
dst
.
length
==
dst_len
);
/* src now has one slice ["ccc"] */
/* Case 3: Move less than the first slice's length from src to dst*/
gpr_slice_buffer_move_first
(
&
src
,
2
,
&
dst
);
src_len
-=
2
;
dst_len
+=
2
;
GPR_ASSERT
(
src
.
length
==
src
.
length
);
GPR_ASSERT
(
dst
.
length
==
dst
.
length
);
}
int
main
(
int
argc
,
char
**
argv
)
{
grpc_test_init
(
argc
,
argv
);
test_slice_buffer_add
();
test_slice_buffer_move_first
();
return
0
;
return
0
;
}
}
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