mirror of
https://github.com/tailix/libkernaux.git
synced 2025-04-14 17:32:55 -04:00
Main: examples/: Enable assertions in all examples
This commit is contained in:
parent
4740e6d00b
commit
08029c2df0
13 changed files with 41 additions and 52 deletions
|
@ -18,7 +18,7 @@ assert_SOURCES = assert.c
|
|||
if WITH_CMDLINE
|
||||
TESTS += cmdline
|
||||
cmdline_LDADD = $(top_builddir)/libkernaux.la
|
||||
cmdline_SOURCES = cmdline.c
|
||||
cmdline_SOURCES = main.c cmdline.c
|
||||
endif
|
||||
|
||||
###########
|
||||
|
@ -29,7 +29,7 @@ if WITH_PRINTF
|
|||
if WITH_IO
|
||||
TESTS += fprintf
|
||||
fprintf_LDADD = $(top_builddir)/libkernaux.la
|
||||
fprintf_SOURCES = fprintf.c
|
||||
fprintf_SOURCES = main.c fprintf.c
|
||||
endif
|
||||
endif
|
||||
|
||||
|
@ -41,7 +41,7 @@ if WITH_PRINTF
|
|||
if WITH_IO
|
||||
TESTS += fprintf_va
|
||||
fprintf_va_LDADD = $(top_builddir)/libkernaux.la
|
||||
fprintf_va_SOURCES = fprintf_va.c
|
||||
fprintf_va_SOURCES = main.c fprintf_va.c
|
||||
endif
|
||||
endif
|
||||
|
||||
|
@ -52,7 +52,7 @@ endif
|
|||
if WITH_IO
|
||||
TESTS += io_memstore
|
||||
io_memstore_LDADD = $(top_builddir)/libkernaux.la
|
||||
io_memstore_SOURCES = io_memstore.c
|
||||
io_memstore_SOURCES = main.c io_memstore.c
|
||||
endif
|
||||
|
||||
##########
|
||||
|
@ -62,7 +62,7 @@ endif
|
|||
if WITH_MEMMAP
|
||||
TESTS += memmap
|
||||
memmap_LDADD = $(top_builddir)/libkernaux.la
|
||||
memmap_SOURCES = memmap.c
|
||||
memmap_SOURCES = main.c memmap.c
|
||||
endif
|
||||
|
||||
########
|
||||
|
@ -72,7 +72,7 @@ endif
|
|||
if WITH_NTOA
|
||||
TESTS += ntoa
|
||||
ntoa_LDADD = $(top_builddir)/libkernaux.la
|
||||
ntoa_SOURCES = ntoa.c
|
||||
ntoa_SOURCES = main.c ntoa.c
|
||||
endif
|
||||
|
||||
#########
|
||||
|
@ -90,7 +90,7 @@ panic_SOURCES = panic.c
|
|||
if WITH_PFA
|
||||
TESTS += pfa
|
||||
pfa_LDADD = $(top_builddir)/libkernaux.la
|
||||
pfa_SOURCES = pfa.c
|
||||
pfa_SOURCES = main.c pfa.c
|
||||
endif
|
||||
|
||||
##############
|
||||
|
@ -100,7 +100,7 @@ endif
|
|||
if WITH_PRINTF_FMT
|
||||
TESTS += printf_fmt
|
||||
printf_fmt_LDADD = $(top_builddir)/libkernaux.la
|
||||
printf_fmt_SOURCES = printf_fmt.c
|
||||
printf_fmt_SOURCES = main.c printf_fmt.c
|
||||
endif
|
||||
|
||||
############
|
||||
|
@ -110,7 +110,7 @@ endif
|
|||
if WITH_PRINTF
|
||||
TESTS += snprintf
|
||||
snprintf_LDADD = $(top_builddir)/libkernaux.la
|
||||
snprintf_SOURCES = snprintf.c
|
||||
snprintf_SOURCES = main.c snprintf.c
|
||||
endif
|
||||
|
||||
###############
|
||||
|
@ -120,7 +120,7 @@ endif
|
|||
if WITH_PRINTF
|
||||
TESTS += snprintf_va
|
||||
snprintf_va_LDADD = $(top_builddir)/libkernaux.la
|
||||
snprintf_va_SOURCES = snprintf_va.c
|
||||
snprintf_va_SOURCES = main.c snprintf_va.c
|
||||
endif
|
||||
|
||||
###############
|
||||
|
@ -130,5 +130,5 @@ endif
|
|||
if WITH_UNITS
|
||||
TESTS += units_human
|
||||
units_human_LDADD = $(top_builddir)/libkernaux.la
|
||||
units_human_SOURCES = units_human.c
|
||||
units_human_SOURCES = main.c units_human.c
|
||||
endif
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
static const char *const cmdline = "foo bar\\ baz \"car cdr\"";
|
||||
|
||||
int main()
|
||||
void example_main()
|
||||
{
|
||||
char error_msg[KERNAUX_CMDLINE_ERROR_MSG_SIZE_MAX];
|
||||
size_t argc;
|
||||
|
@ -30,6 +30,4 @@ int main()
|
|||
assert(strcmp(argv[0], "foo") == 0);
|
||||
assert(strcmp(argv[1], "bar baz") == 0);
|
||||
assert(strcmp(argv[2], "car cdr") == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ static void my_putchar(const char chr, void *arg)
|
|||
buffer[buffer_index++] = chr;
|
||||
}
|
||||
|
||||
int main()
|
||||
void example_main()
|
||||
{
|
||||
struct KernAux_File file = KernAux_File_create(my_putchar);
|
||||
const int result = kernaux_fprintf(
|
||||
|
@ -32,5 +32,4 @@ int main()
|
|||
);
|
||||
assert((size_t)result == strlen(buffer));
|
||||
assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -30,10 +30,9 @@ static int my_printf(const char *const format, ...)
|
|||
return result;
|
||||
}
|
||||
|
||||
int main()
|
||||
void example_main()
|
||||
{
|
||||
const int result = my_printf("Hello, %s! Session ID: %u.", "Alex", 123);
|
||||
assert((size_t)result == strlen(buffer));
|
||||
assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,26 +1,14 @@
|
|||
#include <kernaux/assert.h>
|
||||
#include <kernaux/io.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BUFFER_SIZE 4096
|
||||
|
||||
static char buffer[BUFFER_SIZE];
|
||||
|
||||
static void assert_cb(const char *file, const int line, const char *msg)
|
||||
void example_main()
|
||||
{
|
||||
fprintf(stderr, "%s:%i:%s\n", file, line, msg);
|
||||
abort();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
kernaux_assert_cb = assert_cb;
|
||||
|
||||
struct KernAux_MemStore mem_store =
|
||||
KernAux_MemStore_create(buffer, BUFFER_SIZE);
|
||||
|
||||
|
@ -33,6 +21,4 @@ int main()
|
|||
assert(KernAux_Store_put_char(&mem_store.store, '\0') == '\0');
|
||||
|
||||
assert(strncmp(buffer, "Hello!", BUFFER_SIZE) == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
19
examples/main.c
Normal file
19
examples/main.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <kernaux/assert.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void example_main();
|
||||
|
||||
static void assert_cb(const char *file, const int line, const char *msg)
|
||||
{
|
||||
fprintf(stderr, "%s:%i:%s\n", file, line, msg);
|
||||
abort();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
kernaux_assert_cb = assert_cb;
|
||||
example_main();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
#define SIZE_512MiB ( 512 * 1024 * 1024)
|
||||
#define SIZE_1GiB (1024 * 1024 * 1024)
|
||||
|
||||
int main()
|
||||
void example_main()
|
||||
{
|
||||
KernAux_MemMap memmap = { KernAux_MemMap_create(SIZE_1GiB) };
|
||||
|
||||
|
@ -42,6 +42,4 @@ int main()
|
|||
assert( KernAux_MemMap_entry_by_addr(memmap, SIZE_1GiB - 3 )->size == SIZE_512MiB);
|
||||
assert( KernAux_MemMap_entry_by_addr(memmap, SIZE_1GiB - 2 )->end == SIZE_1GiB - 1);
|
||||
assert( KernAux_MemMap_entry_by_addr(memmap, SIZE_1GiB - 1 )->limit == SIZE_1GiB);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ static const char *str_end(const char *str)
|
|||
for (;; ++str) if (*str == '\0') return str;
|
||||
}
|
||||
|
||||
int main()
|
||||
void example_main()
|
||||
{
|
||||
// kernaux_utoa
|
||||
{
|
||||
|
@ -278,6 +278,4 @@ int main()
|
|||
assert(strcmp(buffer, "-0x123") == 0);
|
||||
assert(end == str_end(buffer));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// management in kernel without PFA.
|
||||
struct KernAux_PFA pfa;
|
||||
|
||||
int main()
|
||||
void example_main()
|
||||
{
|
||||
// In the earliest stage of kernel initialization mark all pages as
|
||||
// unavailable because you don't have memory map yet.
|
||||
|
@ -68,6 +68,4 @@ int main()
|
|||
KernAux_PFA_free_pages(&pfa, page_addr, 123);
|
||||
assert(KernAux_PFA_is_available(&pfa, page_addr));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <assert.h>
|
||||
|
||||
int main()
|
||||
void example_main()
|
||||
{
|
||||
{
|
||||
const char *format = "s";
|
||||
|
@ -89,6 +89,4 @@ int main()
|
|||
assert(spec.type == KERNAUX_PRINTF_FMT_TYPE_INT);
|
||||
assert(spec.base == 10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
static char buffer[BUFFER_SIZE];
|
||||
|
||||
int main()
|
||||
void example_main()
|
||||
{
|
||||
const int result = kernaux_snprintf(
|
||||
buffer,
|
||||
|
@ -18,5 +18,4 @@ int main()
|
|||
);
|
||||
assert((size_t)result == strlen(buffer));
|
||||
assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -16,10 +16,9 @@ static int my_snprintf(const char *const format, ...)
|
|||
return result;
|
||||
}
|
||||
|
||||
int main()
|
||||
void example_main()
|
||||
{
|
||||
const int result = my_snprintf("Hello, %s! Session ID: %u.", "Alex", 123);
|
||||
assert((size_t)result == strlen(buffer));
|
||||
assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int main()
|
||||
void example_main()
|
||||
{
|
||||
char buffer[256];
|
||||
|
||||
|
@ -42,6 +42,4 @@ int main()
|
|||
assert(strcmp(buffer, "123 GB") == 0);
|
||||
kernaux_units_human_bin(123, KERNAUX_UNIT_BYTE, KERNAUX_UNITPFX_GIBI, buffer, sizeof(buffer));
|
||||
assert(strcmp(buffer, "123 GiB") == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue