1 | /* lognestmonster Copyright (c) 2020 Joshua 'joshuas3' Stockin |
2 | * <https://joshstock.in> |
3 | * <https://github.com/JoshuaS3/lognestmonster> |
4 | * |
5 | * This software is licensed and distributed under the terms of the MIT License. |
6 | * See the MIT License in the LICENSE file of this project's root folder. |
7 | * |
8 | * This comment block and its contents, including this disclaimer, MUST be |
9 | * preserved in all copies or distributions of this software's source. |
10 | */ |
11 |
|
12 | // main.c |
13 | // C file for testing the lognestmonster library header |
14 |
|
15 | #include <stdio.h> |
16 |
|
17 | #define LNM_INIT |
18 | #define LNM_DEBUG |
19 | #include "lognestmonster.h" |
20 |
|
21 | void verify_queue_integrity(lnmQueue queue, char * queueName); |
22 |
|
23 | int main(void) { |
24 | long t1 = lnm_getus(); |
25 |
|
26 | printf("data testing\n"); |
27 | printf("============\n"); |
28 |
|
29 | printf("word size/ptr length: %zu\n", sizeof(lnmItem)); |
30 | printf("\n\n"); |
31 |
|
32 | printf("queue persistence testing\n"); |
33 | printf("=========================\n"); |
34 |
|
35 | printf("creating \"master\" queue with path \"/var/log/lognestmonster\"\n"); |
36 | lnmQueue queue = lnmQueueInit("master", "/var/log/lognestmonster"); |
37 | printf("queue \"master\" created at 0x%llx\n", (long long)queue); |
38 | printf("\n"); |
39 |
|
40 | printf("checking queue integrity in registry...\n"); |
41 | printf("tests/header_unit.c: queue == lnmQueueByName(\"master\"): "); |
42 | if (queue == lnmQueueByName("master")) { |
43 | printf("true\n"); |
44 | } else { |
45 | printf("false. exiting...\n"); |
46 | return 1; |
47 | } |
48 | printf("checking queue integrity across translation units...\n"); |
49 | verify_queue_integrity(queue, "master"); |
50 | printf("\n\n"); |
51 |
|
52 | printf("log tree persistence testing\n"); |
53 | printf("============================\n"); |
54 |
|
55 | printf("creating log tree\n"); |
56 | lnmItem event = lnmEvent("EVENT_TAG"); |
57 | lnmEventPushS(event, lnmInfo, "Each log statement has a verbosity level attached and holds general information you want to write in a log file."); |
58 | lnmEventPushS(event, lnmVerbose, "There are 6 verbosity levels: lnmInfo, lnmDebug, lnmVerbose, lnmVeryVerbose, lnmWarning, and lnmError."); |
59 | lnmEventPushS(event, lnmInfo, "An event is a container for log statements or other events. Events can later be deserialized and queried."); |
60 | lnmEventPushS(event, lnmVeryVerbose, "Events can hold other events, like this: "); |
61 | lnmItem nested_event = lnmEvent("NESTED_EVENT"); |
62 | lnmEventPush(event, nested_event); |
63 | lnmEventPushS(nested_event, lnmDebug, "Each event is assigned a tag to make querying easy."); |
64 | lnmEventPushS(nested_event, lnmWarning, "Events can hold up to 2^16 (65536) items. Messages also have a 2^16 maximum message length."); |
65 | printf("created log tree\n"); |
66 | printf("\n\n"); |
67 |
|
68 | printf("debug registry logtree (1 top level items expected)\n"); |
69 | lnm_debug_parse_registry(); |
70 | printf("\n\n"); |
71 |
|
72 | printf("push event to queue\n"); |
73 | lnmQueuePush(queue, event); |
74 | printf("\n"); |
75 |
|
76 | printf("debug registry logtree (0 top level items expected)\n"); |
77 | lnm_debug_parse_registry(); |
78 | printf("\n"); |
79 |
|
80 | printf("debug queue (master)\n"); |
81 | lnm_debug_parse_queue(queue); |
82 | printf("\n\n"); |
83 |
|
84 | printf("freeing queue\n"); |
85 | lnm_free_queue(queue); |
86 | printf("\n"); |
87 |
|
88 | printf("debug queue (master, 0 items expected)\n"); |
89 | lnm_debug_parse_queue(queue); |
90 | printf("\n\n"); |
91 |
|
92 | printf("tests finished\n"); |
93 | printf("----------------------------\n"); |
94 | printf("time elapsed (us): %lu\n", lnm_getus() - t1); |
95 |
|
96 | return 0; |
97 | } |
98 |
|