diff options
Diffstat (limited to 'dispatcher/elapi_dispatcher_ut.c')
-rw-r--r-- | dispatcher/elapi_dispatcher_ut.c | 110 |
1 files changed, 105 insertions, 5 deletions
diff --git a/dispatcher/elapi_dispatcher_ut.c b/dispatcher/elapi_dispatcher_ut.c index 994df17..3d2d6ac 100644 --- a/dispatcher/elapi_dispatcher_ut.c +++ b/dispatcher/elapi_dispatcher_ut.c @@ -33,14 +33,14 @@ struct collection_item *socket; struct collection_item *host; -int construct_event() +int build_event() { char binary_dump[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; int found = 0; int error = EOK; - DEBUG_STRING("construct_event","Entry."); + DEBUG_STRING("build_event","Entry."); if((error=create_collection(&peer,"peer")) || (error=add_str_property(peer,NULL,"hostname","peerhost.mytest.com",0)) || @@ -83,7 +83,7 @@ int construct_event() return error; } - /* Construct event */ + /* build event */ if((error=create_collection(&event,"event")) || (error=add_str_property(event,NULL,"escape1","ds\\sd=ewrw===sada",0)) || (error=add_str_property(event,NULL,"escape2","dss,d,=,ewrw===sada",0)) || @@ -125,6 +125,103 @@ int construct_event() return EOK; } +int other_high_level_test() +{ + int error = EOK; + char *sinks[]= { "syslog", "stderr", "file", NULL }; + char bin[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + + printf("Second high level test start\n"); + + printf("%s","=================\nOpening audit\n"); + error = open_audit("my_app",sinks); + if(error) { + printf("open_audit returned %d\n", error); + return error; + } + else printf("Success : %d\n",error); + + printf("%s","=================\nCreating collection\n"); + if((error=create_event(&event,"test_event")) || + (error=add_str_property(event,NULL,"name","some name",0)) || + (error=add_int_property(event,NULL,"number",-100)) || + (error=add_binary_property(event,NULL,"bin",bin,8)) || + (error=add_double_property(event,NULL,"double",3.141592))) { + printf("Failed to create collection. Error %d\n",error); + return error; + } + else printf("Success : %d\n",error); + + error = construct_event(&event,"test_event"," %b(bin)," + " %d(int_number)," + " %u(unsigned_number)," + " %ld(long_number)," + " %lu(long_unsigned_number)," + " %s(just_string)," + " %*s(sub_string)," + " %e(double_number)", + bin,8, + -200, + 300, + -1234567, + 1234567879, + "string", + "truncated string", 10, /* Expect word truncated */ + 3.141592 * 3); + if(error) { + printf("Failed to construct event %d\n", error); + return error; + } + else printf("Success : %d\n",error); + + + printf("%s","=================\nLog event using NULL format\n"); + log_event(NULL, event); + + printf("%s","=================\nLog event using format\n"); + log_event("%(stamp), %s(sub_string), %(int_number), %(unsigned_number), %(long_unsigned_number), %(bin), %e(double_number)", event); + + error = modify_event(event,1," %d(int_number)," + " %u(unsigned_number),", + -220, + 330); + + if(error) { + printf("Failed to modify event %d\n", error); + return error; + } + else printf("Success : %d\n",error); + + printf("%s","=================\nLog modified event using NULL format\n"); + log_event(NULL, event); + + printf("%s","=================\nLog modified event using format\n"); + log_event("%(stamp), %s(sub_string), %(int_number), %(unsigned_number), %(long_unsigned_number), %(bin), %e(double_number)", event); + + error = modify_event(event,0," %d(int_number)," + " %u(unsigned_number),", + -250, + 350); + if(error) { + printf("Failed to modify event %d\n", error); + return error; + } + else printf("Success : %d\n",error); + + printf("%s","=================\nLog modified event using NULL format\n"); + log_event(NULL, event); + + printf("%s","=================\nLog modified event using format\n"); + log_event("%(stamp), %s(sub_string), %(int_number), %(unsigned_number), %(long_unsigned_number), %(bin), %e(double_number)", event); + + destroy_collection(event); + close_audit(); + + printf("Low level test end\n"); + return error; +} + + int high_level_test(char *app) { int error = EOK; @@ -199,7 +296,7 @@ int high_level_test(char *app) printf("%s","=================\nNegative tests\n"); printf("%s","=================\nLog event using Third format\n"); - log_event("%-50s(timestamp), %50s(name, %lo(number), %a(bin), %%, %.8f(double)", event); + log_event("%-50s(stamp), %50s(name, %lo(number), %a(bin), %%, %.8f(double)", event); log_event("%(times), %z(name), %lo(number), %a(bin), %%, %.8f(double)", event); log_event("%(times), %(name ), %lo(number), %a(bin), %%, %.8f(double)", event); log_event("%(times), (name ), %lo(number), %a(bin), %%, %.8f(double)", event); @@ -231,7 +328,7 @@ int low_level_test() } printf("%s","=================\nCreating collection\n"); - error = construct_event(); + error = build_event(); if(error) { printf("Error creating event %d\n",error); return error; @@ -356,7 +453,10 @@ int main() error = high_level_test("my_app2"); printf("High level test second run returned: %d\n",error); + if(error) return error; + error = other_high_level_test(); + printf("Other high level test returned: %d\n",error); return error; } |