mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-12-04 14:46:30 -05:00
Feature: Added first (create/unref) tests for buffers
This commit is contained in:
parent
a92b39becd
commit
bc69719462
@ -35,6 +35,13 @@ ctest_refobject_test_LDADD = libice_ctest.la \
|
||||
icecast-refobject.o
|
||||
check_PROGRAMS += ctest_refobject.test
|
||||
|
||||
ctest_buffer_test_SOURCES = %reldir%/ctest_buffer.c
|
||||
ctest_buffer_test_LDADD = libice_ctest.la \
|
||||
common/thread/libicethread.la \
|
||||
common/avl/libiceavl.la \
|
||||
icecast-refobject.o \
|
||||
icecast-buffer.o
|
||||
check_PROGRAMS += ctest_buffer.test
|
||||
|
||||
# Add all programs to TESTS
|
||||
TESTS = $(check_PROGRAMS)
|
||||
|
111
src/tests/ctest_buffer.c
Normal file
111
src/tests/ctest_buffer.c
Normal file
@ -0,0 +1,111 @@
|
||||
/* Icecast
|
||||
*
|
||||
* This program is distributed under the GNU General Public License, version 2.
|
||||
* A copy of this license is included with this source.
|
||||
*
|
||||
* Copyright 2018, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "ctest_lib.h"
|
||||
|
||||
#include "../src/buffer.h"
|
||||
#include "../src/refobject.h"
|
||||
|
||||
static void test_create_ref_unref(void)
|
||||
{
|
||||
buffer_t *a;
|
||||
|
||||
a = buffer_new(-1, NULL, NULL, REFOBJECT_NULL);
|
||||
ctest_test("buffer created", a != NULL);
|
||||
ctest_test("un-referenced", refobject_unref(a) == 0);
|
||||
|
||||
a = buffer_new_simple();
|
||||
ctest_test("buffer created", a != NULL);
|
||||
ctest_test("un-referenced", refobject_unref(a) == 0);
|
||||
|
||||
}
|
||||
|
||||
static void test_name(void)
|
||||
{
|
||||
buffer_t *a;
|
||||
const char *name = "test object name";
|
||||
const char *ret;
|
||||
|
||||
a = buffer_new(-1, NULL, name, REFOBJECT_NULL);
|
||||
ctest_test("buffer created", a != NULL);
|
||||
|
||||
ret = refobject_get_name(a);
|
||||
ctest_test("get name", ret != NULL);
|
||||
ctest_test("name match", strcmp(name, ret) == 0);
|
||||
|
||||
ctest_test("un-referenced", refobject_unref(a) == 0);
|
||||
}
|
||||
|
||||
static void test_userdata(void)
|
||||
{
|
||||
buffer_t *a;
|
||||
int tmp = 0;
|
||||
void *userdata = &tmp;
|
||||
void *ret;
|
||||
|
||||
a = buffer_new(-1, NULL, NULL, REFOBJECT_NULL);
|
||||
ctest_test("buffer created", a != NULL);
|
||||
ret = refobject_get_userdata(a);
|
||||
ctest_test("get userdata", ret == NULL);
|
||||
ctest_test("set userdata", refobject_set_userdata(a, userdata) == 0);
|
||||
ret = refobject_get_userdata(a);
|
||||
ctest_test("get userdata", ret == userdata);
|
||||
ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0);
|
||||
ret = refobject_get_userdata(a);
|
||||
ctest_test("get userdata", ret == NULL);
|
||||
|
||||
ctest_test("un-referenced", refobject_unref(a) == 0);
|
||||
|
||||
a = buffer_new(-1, userdata, NULL, REFOBJECT_NULL);
|
||||
ctest_test("buffer created", a != NULL);
|
||||
ctest_test("refobject created", !REFOBJECT_IS_NULL(a));
|
||||
ret = refobject_get_userdata(a);
|
||||
ctest_test("get userdata", ret == userdata);
|
||||
ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0);
|
||||
ret = refobject_get_userdata(a);
|
||||
ctest_test("get userdata", ret == NULL);
|
||||
ctest_test("un-referenced", refobject_unref(a) == 0);
|
||||
}
|
||||
|
||||
static void test_associated(void)
|
||||
{
|
||||
refobject_t a;
|
||||
buffer_t *b;
|
||||
|
||||
a = refobject_new(sizeof(refobject_base_t), NULL, NULL, NULL, REFOBJECT_NULL);
|
||||
ctest_test("refobject created", !REFOBJECT_IS_NULL(a));
|
||||
|
||||
|
||||
b = buffer_new(-1, NULL, NULL, a);
|
||||
ctest_test("buffer created with associated", !REFOBJECT_IS_NULL(b));
|
||||
|
||||
ctest_test("un-referenced (1 of 2)", refobject_unref(b) == 0);
|
||||
ctest_test("un-referenced (2 of 2)", refobject_unref(a) == 0);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
ctest_init();
|
||||
|
||||
|
||||
test_create_ref_unref();
|
||||
|
||||
test_name();
|
||||
test_userdata();
|
||||
test_associated();
|
||||
|
||||
ctest_fin();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user