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 5, 2024
1 parent f255a79 commit db21fea
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1185,3 +1185,68 @@ int test_text2pcap(void)
mem_deref(mb);
return err;
}


int test_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_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_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 @@ -334,6 +334,7 @@ int test_sys_getenv(void);
int test_tcp(void);
int test_telev(void);
int test_text2pcap(void);
int test_trim(void);
int test_thread(void);
int test_thread_cnd_timedwait(void);
int test_tmr_jiffies(void);
Expand Down

0 comments on commit db21fea

Please sign in to comment.