Skip to content

Commit

Permalink
test/fmt.c: add test_trim
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianfridrich committed Dec 8, 2024
1 parent f255a79 commit 630a454
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
77 changes: 77 additions & 0 deletions test/fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1185,3 +1185,80 @@ int test_text2pcap(void)
mem_deref(mb);
return err;
}


int test_fmt_trim(void)
{
const struct pl pla = PL(" heisann ");
const struct pl pll = PL("heisann ");
const struct pl plr = PL(" heisann");
const struct pl plb = PL("heisann");

const struct pl pl = PL(" \r \n heisann \n \r ");
const struct pl pl1 = PL("heisann \n \r ");
const struct pl pl2 = PL(" \r \n heisann");
const struct pl pl3 = PL("heisann");

const struct pl pl4 = PL(" \r \n");
const struct pl pl5 = PL("");
struct pl pln;

int err = 0;

pln = pla;
err = pl_ltrim(&pln);
TEST_ERR(err);
err = pl_cmp(&pln, &pll);
TEST_ERR(err);

pln = pla;
err = pl_rtrim(&pln);
TEST_ERR(err);
err = pl_cmp(&pln, &plr);
TEST_ERR(err);

pln = pla;
err = pl_trim(&pln);
TEST_ERR(err);
err = pl_cmp(&pln, &plb);
TEST_ERR(err);

pln = pl1;
err = pl_ltrim(&pln);
TEST_ERR(err);
err = pl_cmp(&pln, &pl1);
TEST_ERR(err);

pln = pl;
err = pl_rtrim(&pln);
TEST_ERR(err);
err = pl_cmp(&pln, &pl2);
TEST_ERR(err);

pln = pl;
err = pl_trim(&pln);
TEST_ERR(err);
err = pl_cmp(&pln, &pl3);
TEST_ERR(err);

pln = pl4;
err = pl_ltrim(&pln);
TEST_ERR(err);
err = pl_cmp(&pln, &pl5);
TEST_ERR(err);

pln = pl4;
err = pl_rtrim(&pln);
TEST_ERR(err);
err = pl_cmp(&pln, &pl5);
TEST_ERR(err);

pln = pl4;
err = pl_trim(&pln);
TEST_ERR(err);
err = pl_cmp(&pln, &pl5);
TEST_ERR(err);

out:
return err;
}
1 change: 1 addition & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ static const struct test tests[] = {
TEST(test_tcp),
TEST(test_telev),
TEST(test_text2pcap),
TEST(test_fmt_trim),
#ifdef USE_TLS
TEST(test_tls),
TEST(test_tls_ec),
Expand Down
1 change: 1 addition & 0 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ int test_fmt_str_error(void);
int test_fmt_str_itoa(void);
int test_fmt_str_wchar(void);
int test_fmt_timestamp(void);
int test_fmt_trim(void);
int test_fmt_unicode(void);
int test_fmt_unicode_decode(void);
int test_g711_alaw(void);
Expand Down

0 comments on commit 630a454

Please sign in to comment.