Skip to content
This repository has been archived by the owner on Feb 18, 2023. It is now read-only.

convert: add tests #54

Merged
merged 2 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/convert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @file convert.c Conversion Testcode
*
* Copyright (C) 2022 Sebastian Reimers
*/
#include <re.h>
#include "test.h"

#define DEBUG_MODULE "testconvert"
#define DEBUG_LEVEL 5
#include <re_dbg.h>


int test_try_into(void)
{
int err = 0;
size_t size;
uint16_t u16 = 0;
int i;

/* Testing size_t -> uint16_t */
size = SIZE_MAX;
err = try_into(u16, size);
TEST_EQUALS(ERANGE, err);

size = 5000;
err = try_into(u16, size);
TEST_ERR(err);
TEST_EQUALS(size, u16);

size = SIZE_MAX;
err = try_into(u16, size);
TEST_EQUALS(ERANGE, err);

/* Testing int -> uint16_t */
i = INT_MAX;
err = try_into(u16, i);
TEST_EQUALS(ERANGE, err);

i = -50;
err = try_into(u16, i);
TEST_EQUALS(ERANGE, err);

/* Testing size_t -> int */
size = SIZE_MAX;
err = try_into(i, size);
TEST_EQUALS(ERANGE, err);

size = INT_MAX;
err = try_into(i, size);
TEST_ERR(err);
TEST_EQUALS(INT_MAX, i);

out:
return err;
}
1 change: 1 addition & 0 deletions src/srcs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SRCS += auresamp.c
SRCS += base64.c
SRCS += bfcp.c
SRCS += conf.c
SRCS += convert.c
SRCS += crc32.c
SRCS += dns.c
SRCS += dsp.c
Expand Down
1 change: 1 addition & 0 deletions src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ static const struct test tests[] = {
TEST(test_trice_candpair),
TEST(test_trice_checklist),
TEST(test_trice_loop),
TEST(test_try_into),
TEST(test_turn),
TEST(test_turn_tcp),
TEST(test_udp),
Expand Down
1 change: 1 addition & 0 deletions src/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ int test_tcp(void);
int test_telev(void);
int test_tmr_jiffies(void);
int test_tmr_jiffies_usec(void);
int test_try_into(void);
int test_turn(void);
int test_turn_tcp(void);
int test_udp(void);
Expand Down