elapi_ut.c revision 1771d32e945b758326951384f0e17121042ad74e
/*
ELAPI
Unit test for the ELAPI event interface.
Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#define TRACE_HOME
#include "trace.h"
#include "elapi.h"
#include "collection_tools.h"
int simple_event_test(void)
{
int error = 0;
struct collection_item *event;
printf("Simple test START:\n");
" %sb( logical1 )", "false",
"%sb( logical2 )", "YES",
" %db(logical3)", 1,
"%d(int_number),", -200,
"%u(unsigned_number)", 300,
"%ld(long_number)", -1234567,
"%lu(long_unsigned_number)", 123456789,
"%s(just_string)", "string",
"%*s(sub_string)", "truncated string", 10, /* Expect word truncated */
"%e(double_number)", 3.141592 * 3,
"simple", "value",
"%(stamp), %s(sub_string), %(int_number), %(unsigned_number), %(long_unsigned_number), %(bin), %e(double_number)",
E_EOARG);
if (error) {
return error;
}
&event,
" %db(foo_logical)", 0,
"%d(foo_int_number),", -2000,
"%u(foo_unsigned_number)", 3000,
"%ld(foo_long_number)", -7654321,
E_EOARG);
if (error) {
return error;
}
if (error) {
return error;
}
if (error) {
return error;
}
printf("Simple test success!\n");
return error;
}
int complex_event_test(void)
{
int error = 0;
printf("Complex test START:\n");
&template,
"%lu(long_unsigned_number)", 123456789,
"%s(just_string)", "string",
"%*s(sub_string)", "truncated string", 10, /* Expect word truncated */
"%e(double_number)", 3.141592 * 3,
"simple", "value",
"%(stamp), %s(sub_string), %(int_number), %(unsigned_number), %(long_unsigned_number), %(bin), %e(double_number)",
E_EOARG);
if (error) {
return error;
}
&event,
NULL,
0,
" %db(evt_logical)", 0,
"%d(evt_int_number),", -2000,
"%u(evt_unsigned_number)", 3000,
"%ld(evt_long_number)", -7654321,
E_EOARG);
if (error) {
return error;
}
if (error) {
return error;
}
&template,
" %sb( logical1 )", "false",
"%sb( logical2 )", "YES",
" %db(logical3)", 1,
"%d(int_number),", -200,
"%u(unsigned_number)", 300,
"%ld(long_number)", -1234567,
"%(stamp), %s(sub_string), %(int_number), %(unsigned_number), %(long_unsigned_number), %(bin), %e(double_number)",
E_EOARG);
if (error) {
return error;
}
/* We are forcing overwrite with different type */
return error;
}
&event,
col,
"%(stamp) a good message",
"-int_number",
E_EOARG);
if (error) {
return error;
}
/* We are forsing overwrite with different type */
return error;
}
col,
"-"E_MESSAGE,
"bin", "bin-string",
E_EOARG);
if (error) {
return error;
}
if (error) {
return error;
}
if (error) {
return error;
}
if (error) {
return error;
}
if (error) {
return error;
}
if (error) {
return error;
}
if (error) {
return error;
}
return error;
}
/* Main function of the unit test */
{
int error = 0;
printf("Start\n");
if ((error = simple_event_test()) ||
(error = complex_event_test())) {
printf("Failed!\n");
}
else printf("Success!\n");
/* Add other tests here ... */
return error;
}