Index

lognestmonster / a46b7e5

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
16008 Dec 2019 13:02a46b7e5Update Queue utilitiesJosh Stockin1386N

Blob @ lognestmonster / tests / main.c

text/plain3957 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 DEFINE_LOGNESTMONSTER
26#include "lognestmonster.h"
27
28void test(void);
29extern char * queueName;
30static char * queuePath = "~/path";
31
32int main(void) {
33 queueName = "master";
34 long t1 = lnm_getus();
35
36 printf("lognestmonster C test main()\n");
37 printf("============================\n");
38 printf("\n\n");
39
40
41 printf("data testing\n");
42 printf("----------------------------\n");
43
44 printf("word size/ptr length: %li\n", sizeof(lnmItem));
45 printf("\n");
46
47 printf("enum lnmVerbosityLevel {\n");
48 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);
49 printf("\n\n");
50
51 printf("core library\n");
52 printf("----------------------------\n");
53
54 printf("creating \"%s\" queue with path \"%s\"\n", queueName, queuePath);
55 lnmQueue queue = lnmQueueInit(queueName, queuePath);
56 printf("queue \"%s\" created at 0x%llx\n", queueName, (long long)queue);
57 printf("\n");
58
59 printf("checking queue integrity in registry...\n");
60 printf("queue == lnmQueueByName(\"%s\"): ", queueName);
61 if (queue == lnmQueueByName(queueName)) {
62 printf("true\n");
63 } else {
64 printf("false. exiting...\n");
65 return 1;
66 }
67 printf("\n");
68
69 printf("creating an E{2S, E{1S}, 1S} logtree\n");
70 lnmItem event = lnmEventS(lnmError, "INVOKER", "Test ERROR statement pushed to single event with custom tag and message");
71 lnmEventPushS(event, lnmInfo, "INIT", "Sample INFO/INIT log statement");
72
73 lnmItem event2 = lnmEventS(lnmVerbose, "NESTED", "Example of a nested log statement");
74 lnmEventPushS(event2, lnmVeryVerbose, "NESTED", "Nested #2");
75
76 lnmEventPush(event, event2);
77
78 lnmEventPushS(event2, lnmInfo, "TEST", "Item #3");
79 lnmEventPushS(event2, lnmInfo, "TEST", "Item #4");
80
81 lnmItem event3 = lnmEventS(lnmWarning, "NESTED-2", "Third layer log statement");
82 lnmEventPush(event2, event3);
83
84 lnmEventPushS(event2, lnmInfo, "TEST", "Item #6");
85 lnmEventPushS(event2, lnmInfo, "TEST", "Item #7");
86 lnmEventPushS(event2, lnmInfo, "TEST", "Item #8");
87 lnmEventPushS(event2, lnmInfo, "TEST", "Item #9 (frame capacity doubles from 8 to 16)");
88
89 lnmEventPushS(event, lnmDebug, "REQUEST", "DEBUG/REQUEST log statement. might be found useful in a webserver backend");
90 printf("\n");
91
92 printf("debug registry logtree (1 top level items expected)\n");
93 lnm_debug_parse_registry();
94 printf("\n");
95
96 printf("push event to queue\n");
97 lnmQueuePush(queue, event);
98 printf("\n");
99
100 printf("debug queue (master)\n");
101 lnm_debug_parse_queue(queue);
102 printf("\n");
103
104 printf("debug registry logtree (0 top level items expected)\n");
105 lnm_debug_parse_registry();
106 printf("\n");
107
108 printf("calling test function from different source file\n");
109 test();
110 printf("\n");
111
112 printf("freeing queue\n");
113 lnm_free_queue(queue);
114 printf("\n");
115
116 printf("debug queue (master, 0 items expected)\n");
117 lnm_debug_parse_queue(queue);
118 printf("\n\n");
119
120 printf("tests finished\n");
121 printf("----------------------------\n");
122 printf("time elapsed (us): %lu\n", lnm_getus() - t1);
123
124 return 0;
125}
126