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