mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-06 15:51:25 +00:00
More tests
This commit is contained in:
1 parent
082a498afd
commit
7ea3293aba
4 files changed
+31
-6
No files matched your search
@@ -12,7 +12,7 @@ CLANG ?= clang # /usr/local/opt/llvm\@9/bin/clang
|
|||||||
ASAN_OPTIONS ?=
|
ASAN_OPTIONS ?=
|
||||||
EXAMPLES := $(wildcard examples/*)
|
EXAMPLES := $(wildcard examples/*)
|
||||||
EXAMPLE_TARGET ?= example
|
EXAMPLE_TARGET ?= example
|
||||||
.PHONY: ex #$(EXAMPLES)
|
.PHONY: ex test
|
||||||
|
|
||||||
ifeq "$(SSL)" "MBEDTLS"
|
ifeq "$(SSL)" "MBEDTLS"
|
||||||
MBEDTLSDIR ?= $(shell "$(brew --cellar mbedtls)/$(brew info mbedtls --json | jq -j .[0].installed[0].version)")
|
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: EXAMPLE_TARGET = clean
|
||||||
clean: ex
|
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
|
||||||
+3
-2
@@ -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
|
// eCos and Windows are not standard-compliant and return -1 when
|
||||||
// the buffer is too small. Keep allocating larger buffers until we
|
// the buffer is too small. Keep allocating larger buffers until we
|
||||||
// succeed or out of memory.
|
// succeed or out of memory.
|
||||||
*buf = NULL; // LCOV_EXCL_START
|
// LCOV_EXCL_START
|
||||||
|
*buf = NULL;
|
||||||
while (len < 0) {
|
while (len < 0) {
|
||||||
free(*buf);
|
free(*buf);
|
||||||
if (size == 0) size = 5;
|
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
|
// Microsoft version of vsnprintf() is not always null-terminated, so put
|
||||||
// the terminator manually
|
// the terminator manually
|
||||||
(*buf)[len] = 0;
|
(*buf)[len] = 0;
|
||||||
/// LCOV_EXCL_STOP
|
// LCOV_EXCL_STOP
|
||||||
} else if (len >= (int) size) {
|
} else if (len >= (int) size) {
|
||||||
/// Standard-compliant code path. Allocate a buffer that is large enough
|
/// Standard-compliant code path. Allocate a buffer that is large enough
|
||||||
if ((*buf = (char *) malloc(len + 1)) == NULL) {
|
if ((*buf = (char *) malloc(len + 1)) == NULL) {
|
||||||
|
|||||||
+3
-2
@@ -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
|
// eCos and Windows are not standard-compliant and return -1 when
|
||||||
// the buffer is too small. Keep allocating larger buffers until we
|
// the buffer is too small. Keep allocating larger buffers until we
|
||||||
// succeed or out of memory.
|
// succeed or out of memory.
|
||||||
*buf = NULL; // LCOV_EXCL_START
|
// LCOV_EXCL_START
|
||||||
|
*buf = NULL;
|
||||||
while (len < 0) {
|
while (len < 0) {
|
||||||
free(*buf);
|
free(*buf);
|
||||||
if (size == 0) size = 5;
|
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
|
// Microsoft version of vsnprintf() is not always null-terminated, so put
|
||||||
// the terminator manually
|
// the terminator manually
|
||||||
(*buf)[len] = 0;
|
(*buf)[len] = 0;
|
||||||
/// LCOV_EXCL_STOP
|
// LCOV_EXCL_STOP
|
||||||
} else if (len >= (int) size) {
|
} else if (len >= (int) size) {
|
||||||
/// Standard-compliant code path. Allocate a buffer that is large enough
|
/// Standard-compliant code path. Allocate a buffer that is large enough
|
||||||
if ((*buf = (char *) malloc(len + 1)) == NULL) {
|
if ((*buf = (char *) malloc(len + 1)) == NULL) {
|
||||||
|
|||||||
@@ -839,8 +839,31 @@ static void test_timer(void) {
|
|||||||
ASSERT(g_timers == NULL);
|
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) {
|
int main(void) {
|
||||||
mg_log_set("3");
|
mg_log_set("3");
|
||||||
|
test_str();
|
||||||
|
test_util();
|
||||||
test_timer();
|
test_timer();
|
||||||
test_http_range();
|
test_http_range();
|
||||||
test_url();
|
test_url();
|
||||||
|
|||||||
Reference in new issue
Block a user