Index

lognestmonster / 33010ba

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
16312 Dec 2019 20:14b2c0e60Update forward declaration handlingJosh Stockin121N

Blob @ lognestmonster / tests / main.c

text/plain3960 bytesdownload raw
1// lognestmonster Copyright (c) 2019 Joshua 'joshuas3' Stockin
2// main.c
3// C file for testing the lognestmonster library header
4
5// <https://github.com/JoshuaS3/lognestmonster/>.
6
7
8// This file is part of lognestmonster.
9
10// lognestmonster is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14
15// lognestmonster is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19
20// You should have received a copy of the GNU General Public License
21// along with lognestmonster. If not, see <https://www.gnu.org/licenses/>.
22
23#include <stdio.h>
24
25#define LNM_INIT
26#define LNM_ALL
27#include "lognestmonster.h"
28
29void test(void);
30extern char * queueName;
31static char * queuePath = "~/path";
32
33int main(void) {
34 queueName = "master";
35 long t1 = lnm_getus();
36
37 printf("lognestmonster C test main()\n");
38 printf("============================\n");
39 printf("\n\n");
40
41
42 printf("data testing\n");
43 printf("----------------------------\n");
44
45 printf("word size/ptr length: %li\n", sizeof(lnmItem));
46 printf("\n");
47
48 printf("enum lnmVerbosityLevel {\n");
49 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);
50 printf("\n\n");
51
52 printf("core library\n");
53 printf("----------------------------\n");
54
55 printf("creating \"%s\" queue with path \"%s\"\n", queueName, queuePath);
56 lnmQueue queue = lnmQueueInit(queueName, queuePath);
57 printf("queue \"%s\" created at 0x%llx\n", queueName, (long long)queue);
58 printf("\n");
59
60 printf("checking queue integrity in registry...\n");
61 printf("queue == lnmQueueByName(\"%s\"): ", queueName);
62 if (queue == lnmQueueByName(queueName)) {
63 printf("true\n");
64 } else {
65 printf("false. exiting...\n");
66 return 1;
67 }
68 printf("\n");
69
70 printf("creating an E{2S, E{1S}, 1S} logtree\n");
71 lnmItem event = lnmEventS(lnmError, "INVOKER", "Test ERROR statement pushed to single event with custom tag and message");
72 lnmEventPushS(event, lnmInfo, "INIT", "Sample INFO/INIT log statement");
73
74 lnmItem event2 = lnmEventS(lnmVerbose, "NESTED", "Example of a nested log statement");
75 lnmEventPushS(event2, lnmVeryVerbose, "NESTED", "Nested #2");
76
77 lnmEventPush(event, event2);
78
79 lnmEventPushS(event2, lnmInfo, "TEST", "Item #3");
80 lnmEventPushS(event2, lnmInfo, "TEST", "Item #4");
81
82 lnmItem event3 = lnmEventS(lnmWarning, "NESTED-2", "Third layer log statement");
83 lnmEventPush(event2, event3);
84
85 lnmEventPushS(event2, lnmInfo, "TEST", "Item #6");
86 lnmEventPushS(event2, lnmInfo, "TEST", "Item #7");
87 lnmEventPushS(event2, lnmInfo, "TEST", "Item #8");
88 lnmEventPushS(event2, lnmInfo, "TEST", "Item #9 (frame capacity doubles from 8 to 16)");
89
90 lnmEventPushS(event, lnmDebug, "REQUEST", "DEBUG/REQUEST log statement. might be found useful in a webserver backend");
91 printf("\n");
92
93 printf("debug registry logtree (1 top level items expected)\n");
94 lnm_debug_parse_registry();
95 printf("\n");
96
97 printf("push event to queue\n");
98 lnmQueuePush(queue, event);
99 printf("\n");
100
101 printf("debug queue (master)\n");
102 lnm_debug_parse_queue(queue);
103 printf("\n");
104
105 printf("debug registry logtree (0 top level items expected)\n");
106 lnm_debug_parse_registry();
107 printf("\n");
108
109 printf("calling test function from different source file\n");
110 test();
111 printf("\n");
112
113 printf("freeing queue\n");
114 lnm_free_queue(queue);
115 printf("\n");
116
117 printf("debug queue (master, 0 items expected)\n");
118 lnm_debug_parse_queue(queue);
119 printf("\n\n");
120
121 printf("tests finished\n");
122 printf("----------------------------\n");
123 printf("time elapsed (us): %lu\n", lnm_getus() - t1);
124
125 return 0;
126}
127