Index

lognestmonster / 955bc8d

A general-purpose single-header C logging library and parser for event-based logs. (Incomplete)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
16729 Dec 2019 19:58955bc8dChange license from GPLv3 to MITJosh Stockin1419N

Blob @ lognestmonster / tests / main.c

text/plain3332 bytesdownload raw
1// lognestmonster Copyright (c) 2020 Joshua 'joshuas3' Stockin (copyrighted under the MIT License)
2// <https://joshstock.in>
3// <https://github.com/JoshuaS3/lognestmonster>
4//
5// main.c
6// C file for testing the lognestmonster library header
7
8#include <stdio.h>
9
10#define LNM_INIT
11#define LNM_ALL
12#include "lognestmonster.h"
13
14void test(void);
15extern char * queueName;
16static char * queuePath = "~/path";
17
18int main(void) {
19 queueName = "master";
20 long t1 = lnm_getus();
21
22 printf("lognestmonster C test main()\n");
23 printf("============================\n");
24 printf("\n\n");
25
26
27 printf("data testing\n");
28 printf("----------------------------\n");
29
30 printf("word size/ptr length: %li\n", sizeof(lnmItem));
31 printf("\n");
32
33 printf("enum lnmVerbosityLevel {\n");
34 printf("\tlnmInfo = %i,\n\tlnmDebug = %i,\n\tlnmVerbose = %i,\n\tlnmVeryVerbose = %i,\n\tlnmWarning = %i,\n\tlnmError = %i\n}\n", lnmInfo, lnmDebug, lnmVerbose, lnmVeryVerbose, lnmWarning, lnmError);
35 printf("\n\n");
36
37 printf("core library\n");
38 printf("----------------------------\n");
39
40 printf("creating \"%s\" queue with path \"%s\"\n", queueName, queuePath);
41 lnmQueue queue = lnmQueueInit(queueName, queuePath);
42 printf("queue \"%s\" created at 0x%llx\n", queueName, (long long)queue);
43 printf("\n");
44
45 printf("checking queue integrity in registry...\n");
46 printf("queue == lnmQueueByName(\"%s\"): ", queueName);
47 if (queue == lnmQueueByName(queueName)) {
48 printf("true\n");
49 } else {
50 printf("false. exiting...\n");
51 return 1;
52 }
53 printf("\n");
54
55 printf("creating an E{2S, E{1S}, 1S} logtree\n");
56 lnmItem event = lnmEventS(lnmError, "INVOKER", "Test ERROR statement pushed to single event with custom tag and message");
57 lnmEventPushS(event, lnmInfo, "INIT", "Sample INFO/INIT log statement");
58
59 lnmItem event2 = lnmEventS(lnmVerbose, "NESTED", "Example of a nested log statement");
60 lnmEventPushS(event2, lnmVeryVerbose, "NESTED", "Nested #2");
61
62 lnmEventPush(event, event2);
63
64 lnmEventPushS(event2, lnmInfo, "TEST", "Item #3");
65 lnmEventPushS(event2, lnmInfo, "TEST", "Item #4");
66
67 lnmItem event3 = lnmEventS(lnmWarning, "NESTED-2", "Third layer log statement");
68 lnmEventPush(event2, event3);
69
70 lnmEventPushS(event2, lnmInfo, "TEST", "Item #6");
71 lnmEventPushS(event2, lnmInfo, "TEST", "Item #7");
72 lnmEventPushS(event2, lnmInfo, "TEST", "Item #8");
73 lnmEventPushS(event2, lnmInfo, "TEST", "Item #9 (frame capacity doubles from 8 to 16)");
74
75 lnmEventPushS(event, lnmDebug, "REQUEST", "DEBUG/REQUEST log statement. might be found useful in a webserver backend");
76 printf("\n");
77
78 printf("debug registry logtree (1 top level items expected)\n");
79 lnm_debug_parse_registry();
80 printf("\n");
81
82 printf("push event to queue\n");
83 lnmQueuePush(queue, event);
84 printf("\n");
85
86 printf("debug queue (master)\n");
87 lnm_debug_parse_queue(queue);
88 printf("\n");
89
90 printf("debug registry logtree (0 top level items expected)\n");
91 lnm_debug_parse_registry();
92 printf("\n");
93
94 printf("calling test function from different source file\n");
95 test();
96 printf("\n");
97
98 printf("freeing queue\n");
99 lnm_free_queue(queue);
100 printf("\n");
101
102 printf("debug queue (master, 0 items expected)\n");
103 lnm_debug_parse_queue(queue);
104 printf("\n\n");
105
106 printf("tests finished\n");
107 printf("----------------------------\n");
108 printf("time elapsed (us): %lu\n", lnm_getus() - t1);
109
110 return 0;
111}
112