More tests

This commit is contained in:
cpq 2020-12-07 08:54:58 +00:00
parent 082a498afd
commit 7ea3293aba
4 changed files with 31 additions and 6 deletions

View File

@ -12,7 +12,7 @@ CLANG ?= clang # /usr/local/opt/llvm\@9/bin/clang
ASAN_OPTIONS ?=
EXAMPLES := $(wildcard examples/*)
EXAMPLE_TARGET ?= example
.PHONY: ex #$(EXAMPLES)
.PHONY: ex test
ifeq "$(SSL)" "MBEDTLS"
MBEDTLSDIR ?= $(shell "$(brew --cellar mbedtls)/$(brew info mbedtls --json | jq -j .[0].installed[0].version)")
@ -84,4 +84,4 @@ mongoose.h: $(HDRS) Makefile
clean: EXAMPLE_TARGET = clean
clean: ex
rm -rf $(PROG) *.o *.dSYM unit_test* ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out
rm -rf $(PROG) *.o *.dSYM unit_test* ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out data.txt

View File

@ -3503,7 +3503,8 @@ int mg_vasprintf(char **buf, size_t size, const char *fmt, va_list ap) {
// eCos and Windows are not standard-compliant and return -1 when
// the buffer is too small. Keep allocating larger buffers until we
// succeed or out of memory.
*buf = NULL; // LCOV_EXCL_START
// LCOV_EXCL_START
*buf = NULL;
while (len < 0) {
free(*buf);
if (size == 0) size = 5;
@ -3519,7 +3520,7 @@ int mg_vasprintf(char **buf, size_t size, const char *fmt, va_list ap) {
// Microsoft version of vsnprintf() is not always null-terminated, so put
// the terminator manually
(*buf)[len] = 0;
/// LCOV_EXCL_STOP
// LCOV_EXCL_STOP
} else if (len >= (int) size) {
/// Standard-compliant code path. Allocate a buffer that is large enough
if ((*buf = (char *) malloc(len + 1)) == NULL) {

View File

@ -174,7 +174,8 @@ int mg_vasprintf(char **buf, size_t size, const char *fmt, va_list ap) {
// eCos and Windows are not standard-compliant and return -1 when
// the buffer is too small. Keep allocating larger buffers until we
// succeed or out of memory.
*buf = NULL; // LCOV_EXCL_START
// LCOV_EXCL_START
*buf = NULL;
while (len < 0) {
free(*buf);
if (size == 0) size = 5;
@ -190,7 +191,7 @@ int mg_vasprintf(char **buf, size_t size, const char *fmt, va_list ap) {
// Microsoft version of vsnprintf() is not always null-terminated, so put
// the terminator manually
(*buf)[len] = 0;
/// LCOV_EXCL_STOP
// LCOV_EXCL_STOP
} else if (len >= (int) size) {
/// Standard-compliant code path. Allocate a buffer that is large enough
if ((*buf = (char *) malloc(len + 1)) == NULL) {

View File

@ -839,8 +839,31 @@ static void test_timer(void) {
ASSERT(g_timers == NULL);
}
static void test_str(void) {
struct mg_str s = mg_strdup(mg_str("a"));
ASSERT(mg_strcmp(s, mg_str("a")) == 0);
free((void *) s.ptr);
ASSERT(mg_strcmp(mg_str(""), mg_str(NULL)) == 0);
ASSERT(mg_strcmp(mg_str("a"), mg_str("b")) < 0);
ASSERT(mg_strcmp(mg_str("b"), mg_str("a")) > 0);
ASSERT(mg_strstr(mg_str("abc"), mg_str("d")) == NULL);
ASSERT(mg_strstr(mg_str("abc"), mg_str("b")) != NULL);
ASSERT(mg_strcmp(mg_str("hi"), mg_strstrip(mg_str(" \thi\r\n"))) == 0);
}
static void test_util(void) {
char buf[100], *s = mg_hexdump("abc", 3);
ASSERT(s != NULL);
free(s);
ASSERT(mg_file_write("data.txt", "%s", "hi") == 2);
ASSERT(strcmp(mg_ntoa(0x100007f, buf, sizeof(buf)), "127.0.0.1") == 0);
ASSERT(strcmp(mg_hex("abc", 3, buf), "616263") == 0);
}
int main(void) {
mg_log_set("3");
test_str();
test_util();
test_timer();
test_http_range();
test_url();