Skip to content

Commit

Permalink
test: jbuf update first test
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed Oct 2, 2023
1 parent 8489ed1 commit a2effe4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
46 changes: 17 additions & 29 deletions test/jbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,20 @@ int test_jbuf(void)
}

/* Empty list */
if (ENOENT != jbuf_get(jb, &hdr2, &mem)) {
err = EINVAL;
goto out;
}

ASSERT_EQ(ENOENT, jbuf_get(jb, &hdr2, &mem));

/* One frame */
memset(&hdr, 0, sizeof(hdr));
hdr.seq = 160;
hdr.ts = 1;
err = jbuf_put(jb, &hdr, frv[0]);
TEST_ERR(err);
if ((EALREADY != jbuf_put(jb, &hdr, frv[0]))) {err = EINVAL; goto out;}
ASSERT_EQ(EALREADY, jbuf_put(jb, &hdr, frv[0]));

err = jbuf_get(jb, &hdr2, &mem);
TEST_ERR(err);
if (160 != hdr2.seq) {err = EINVAL; goto out;}
if (mem != frv[0]) {err = EINVAL; goto out;}
ASSERT_EQ(160, hdr2.seq);
ASSERT_EQ(frv[0], mem);
mem = mem_deref(mem);

if (ENOENT != jbuf_get(jb, &hdr2, &mem)) {err = EINVAL; goto out;}
Expand All @@ -65,8 +61,7 @@ int test_jbuf(void)
err = jbuf_put(jb, &hdr, frv[1]);
TEST_ERR(err);

err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(EAGAIN, err);
ASSERT_EQ(EAGAIN, jbuf_get(jb, &hdr2, &mem));
if (320 != hdr2.seq) {err = EINVAL; goto out;}
if (mem != frv[0]) {err = EINVAL; goto out;}
mem = mem_deref(mem);
Expand Down Expand Up @@ -99,8 +94,7 @@ int test_jbuf(void)
if (mem != frv[0]) {err = EINVAL; goto out;}
mem = mem_deref(mem);

err = jbuf_get(jb, &hdr2, &mem);
ASSERT_EQ(EAGAIN, err);
ASSERT_EQ(EAGAIN, jbuf_get(jb, &hdr2, &mem));
if (800 != hdr2.seq) {err = EINVAL; goto out;}
if (mem != frv[1]) {err = EINVAL; goto out;}
mem = mem_deref(mem);
Expand All @@ -124,7 +118,7 @@ int test_jbuf(void)
}


int test_jbuf_adaptive(void)
int test_jbuf_frames(void)
{
struct rtp_header hdr, hdr2;
struct jbuf *jb = NULL;
Expand All @@ -140,8 +134,6 @@ int test_jbuf_adaptive(void)

err = jbuf_alloc(&jb, 1, 10);
TEST_ERR(err);
err = jbuf_set_type(jb, JBUF_ADAPTIVE);
TEST_ERR(err);

for (i=0; i<RE_ARRAY_SIZE(frv); i++) {
frv[i] = mem_zalloc(32, NULL);
Expand All @@ -161,15 +153,15 @@ int test_jbuf_adaptive(void)
TEST_ERR(err);
ASSERT_EQ(EALREADY, jbuf_put(jb, &hdr, frv[0]));

/* wish size is not reached yet */
/* not able to decide that frame is complete */
ASSERT_EQ(ENOENT, jbuf_get(jb, &hdr2, &mem));

hdr.seq = 161;
hdr.ts = 161;
err = jbuf_put(jb, &hdr, frv[1]);
TEST_ERR(err);

/* wish size reached */
/* detected complete frame */
err = jbuf_get(jb, &hdr2, &mem);
TEST_ERR(err);
ASSERT_EQ(160, hdr2.seq);
Expand All @@ -180,23 +172,19 @@ int test_jbuf_adaptive(void)

/* Four frames */
jbuf_flush(jb);
hdr.seq = 1;
hdr.ts = 100;
hdr.seq = hdr.ts = 1;
err = jbuf_put(jb, &hdr, frv[0]);
TEST_ERR(err);

hdr.seq = 2;
hdr.ts = 200;
hdr.seq = hdr.ts = 2;
err = jbuf_put(jb, &hdr, frv[1]);
TEST_ERR(err);

hdr.seq = 3;
hdr.ts = 300;
hdr.seq = hdr.ts = 3;
err = jbuf_put(jb, &hdr, frv[2]);
TEST_ERR(err);

hdr.seq = 4;
hdr.ts = 400;
hdr.seq = hdr.ts = 4;
err = jbuf_put(jb, &hdr, frv[3]);
TEST_ERR(err);

Expand Down Expand Up @@ -233,7 +221,7 @@ int test_jbuf_adaptive(void)
}


int test_jbuf_adaptive_video(void)
int test_jbuf_video_frames(void)
{
struct rtp_header hdr, hdr2;
struct jbuf *jb = NULL;
Expand All @@ -247,9 +235,10 @@ int test_jbuf_adaptive_video(void)
memset(&hdr2, 0, sizeof(hdr2));
hdr.ssrc = 1;

err = jbuf_alloc(&jb, 1, 10);
err = jbuf_alloc(&jb, 1, 3);
TEST_ERR(err);
err = jbuf_set_type(jb, JBUF_ADAPTIVE);

err = jbuf_resize(jb, 10);
TEST_ERR(err);

for (i=0; i<RE_ARRAY_SIZE(frv); i++) {
Expand All @@ -260,7 +249,6 @@ int test_jbuf_adaptive_video(void)
}
}


/* --- Test unordered insert --- */
jbuf_flush(jb);

Expand Down
4 changes: 2 additions & 2 deletions test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ static const struct test tests[] = {
TEST(test_contact),
TEST(test_event),
TEST(test_jbuf),
TEST(test_jbuf_adaptive),
TEST(test_jbuf_adaptive_video),
TEST(test_jbuf_frames),
TEST(test_jbuf_video_frames),
TEST(test_message),
TEST(test_network),
TEST(test_play),
Expand Down
4 changes: 2 additions & 2 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ int test_cmd_long(void);
int test_contact(void);
int test_event(void);
int test_jbuf(void);
int test_jbuf_adaptive(void);
int test_jbuf_adaptive_video(void);
int test_jbuf_frames(void);
int test_jbuf_video_frames(void);
int test_message(void);
int test_network(void);
int test_play(void);
Expand Down

0 comments on commit a2effe4

Please sign in to comment.