Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Knot projects
Knot Resolver
Commits
c9476458
Commit
c9476458
authored
Apr 15, 2015
by
Marek Vavruša
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: added tests for _mm functions
parent
47bcd143
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
2 deletions
+44
-2
tests/test_array.c
tests/test_array.c
+42
-0
tests/test_set.c
tests/test_set.c
+2
-2
No files found.
tests/test_array.c
View file @
c9476458
...
...
@@ -49,12 +49,54 @@ static void test_array(void **state)
array_clear
(
arr
);
}
/** Reservation through tracked memory allocator. */
static
int
test_reserve
(
void
*
baton
,
char
**
mem
,
size_t
elm_size
,
size_t
want
,
size_t
*
have
)
{
if
(
want
>
*
have
)
{
void
*
new_mem
=
mm_alloc
(
baton
,
elm_size
*
want
);
if
(
*
mem
!=
NULL
)
{
memcpy
(
new_mem
,
*
mem
,
(
*
have
)
*
elm_size
);
mm_free
(
baton
,
*
mem
);
}
*
mem
=
new_mem
;
*
have
=
want
;
}
return
0
;
}
/** Reservation through fake memory allocator. */
static
int
fake_reserve
(
void
*
baton
,
char
**
mem
,
size_t
elm_size
,
size_t
want
,
size_t
*
have
)
{
return
-
1
;
}
static
void
test_array_mm
(
void
**
state
)
{
array_t
(
int
)
arr
;
array_init
(
arr
);
/* Reserve using fake memory allocator. */
assert_false
(
array_reserve_mm
(
arr
,
5
,
fake_reserve
,
NULL
)
>=
0
);
/* Reserve capacity and fill. */
assert_true
(
array_reserve_mm
(
arr
,
100
,
test_reserve
,
&
global_mm
)
>=
0
);
for
(
unsigned
i
=
0
;
i
<
100
;
++
i
)
{
int
ret
=
array_push
(
arr
,
i
);
assert_true
(
ret
>=
0
);
}
array_clear_mm
(
arr
,
mm_free
,
&
global_mm
);
}
int
main
(
void
)
{
test_mm_ctx_init
(
&
global_mm
);
const
UnitTest
tests
[]
=
{
unit_test
(
test_array
),
unit_test
(
test_array_mm
)
};
return
run_tests
(
tests
);
...
...
tests/test_set.c
View file @
c9476458
...
...
@@ -131,7 +131,7 @@ static void test_delete_all(void **state)
}
/* Fake allocator */
static
void
*
fake_malloc
(
size_t
s
,
void
*
b
)
{
return
NULL
;
}
static
void
*
fake_malloc
(
void
*
b
,
size_t
s
)
{
return
NULL
;
}
static
void
test_allocator
(
void
**
state
)
{
set_t
set
=
set_make
();
...
...
@@ -216,4 +216,4 @@ int main(int argc, char **argv)
};
return
run_group_tests
(
tests
);
}
\ No newline at end of file
}
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