1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2025-02-17 15:45:32 -05:00

Improve example

This commit is contained in:
Alex Kotov 2022-01-14 12:16:26 +05:00
parent d91e43732f
commit 0718b62b8e
3 changed files with 36 additions and 19 deletions

View file

@ -1,15 +1,21 @@
// TODO: do we really need this?
static const uint8_t multiboot2_header_example1[] = {
214, 80, 82, 232, 0, 0, 0, 0, 16, 1, 0, 0, 26, 174, 173, 23, 1, 0, 0, 0, 96,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0,
0, 0, 6, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 10, 0, 0, 0, 11, 0, 0,
0, 12, 0, 0, 0, 13, 0, 0, 0, 14, 0, 0, 0, 15, 0, 0, 0, 16, 0, 0, 0, 17, 0,
0, 0, 18, 0, 0, 0, 19, 0, 0, 0, 20, 0, 0, 0, 21, 0, 0, 0, 2, 0, 0, 0, 24, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 12, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 12, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0,
5, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6,
0, 0, 0, 8, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 12, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0,
0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
8, 0, 0, 0,
static const struct {
struct KernAux_Multiboot2_Header multiboot2_header;
struct KernAux_Multiboot2_HTag_None tag_none;
} multiboot2_header_example1 = {
.multiboot2_header = {
.magic = KERNAUX_MULTIBOOT2_HEADER_MAGIC,
.arch = KERNAUX_MULTIBOOT2_HEADER_ARCH_MIPS32,
.total_size = sizeof(multiboot2_header_example1),
.checksum = KERNAUX_MULTIBOOT2_HEADER_CHECKSUM(
KERNAUX_MULTIBOOT2_HEADER_ARCH_MIPS32,
sizeof(multiboot2_header_example1)
),
},
.tag_none = {
.base = {
.type = KERNAUX_MULTIBOOT2_HTAG_NONE,
.flags = 0,
.size = sizeof(multiboot2_header_example1.tag_none),
},
},
};

View file

@ -12,11 +12,11 @@
int main()
{
assert(KernAux_Multiboot2_Header_is_valid(
(struct KernAux_Multiboot2_Header*)multiboot2_header_example1
(struct KernAux_Multiboot2_Header*)&multiboot2_header_example1
));
KernAux_Multiboot2_Header_print(
(struct KernAux_Multiboot2_Header*)multiboot2_header_example1,
(struct KernAux_Multiboot2_Header*)&multiboot2_header_example1,
(void (*)(const char *format, ...))printf
);

View file

@ -7,7 +7,18 @@
#define __USE_POSIX2
#include <stdio.h>
static const char output[] =
static const char output1[] =
"Multiboot 2 header\n"
" magic: 3897708758\n"
" arch: 4 (MIPS32)\n"
" size: 24\n"
" checksum: 397258510\n"
"Multiboot 2 header tag\n"
" type: 0 (none)\n"
" flags: 0\n"
" size: 8\n";
static const char output2[] =
"Multiboot 2 header\n"
" magic: 3897708758\n"
" arch: 0 (i386)\n"
@ -64,7 +75,7 @@ int main()
FILE *const fd = popen("tests/multiboot2_header_print1", "r");
assert(fd != NULL);
for (const char *ch = output; *ch; ++ch) {
for (const char *ch = output1; *ch; ++ch) {
assert(fgetc(fd) == *ch);
}
@ -76,7 +87,7 @@ int main()
FILE *const fd = popen("tests/multiboot2_header_print2", "r");
assert(fd != NULL);
for (const char *ch = output; *ch; ++ch) {
for (const char *ch = output2; *ch; ++ch) {
assert(fgetc(fd) == *ch);
}