|
Packit Service |
b38f0b |
/*
|
|
Packit Service |
b38f0b |
* etimetest.c
|
|
Packit Service |
b38f0b |
*
|
|
Packit Service |
b38f0b |
* HEADER Testing read_config.c shutdown callback
|
|
Packit Service |
b38f0b |
*
|
|
Packit Service |
b38f0b |
* Expected SUCCESSes for all tests: 8
|
|
Packit Service |
b38f0b |
*
|
|
Packit Service |
b38f0b |
* Test of snmpd_unregister_config_handler SUCCESSes: 4
|
|
Packit Service |
b38f0b |
* Test of unregister_all_config_handlers SUCCESSes: 4
|
|
Packit Service |
b38f0b |
*
|
|
Packit Service |
b38f0b |
*/
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
#include <net-snmp/net-snmp-config.h>
|
|
Packit Service |
b38f0b |
#include <net-snmp/net-snmp-includes.h>
|
|
Packit Service |
b38f0b |
#include <net-snmp/agent/net-snmp-agent-includes.h>
|
|
Packit Service |
b38f0b |
#include <net-snmp/library/testing.h>
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
/* #undef TEST_INTERNAL_API */
|
|
Packit Service |
b38f0b |
#define TEST_INTERNAL_API 1
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
/*
|
|
Packit Service |
b38f0b |
* Global variables.
|
|
Packit Service |
b38f0b |
*/
|
|
Packit Service |
b38f0b |
int callback_called = 0;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
static void test_callback(void);
|
|
Packit Service |
b38f0b |
static void test_callback(void) {
|
|
Packit Service |
b38f0b |
++callback_called;
|
|
Packit Service |
b38f0b |
};
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
static void parse_config(const char *token, char *cptr);
|
|
Packit Service |
b38f0b |
static void parse_config(const char *token, char *cptr) {
|
|
Packit Service |
b38f0b |
/* do nothing */
|
|
Packit Service |
b38f0b |
};
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
/* each test returns 0 on success, and >0 on failure */
|
|
Packit Service |
b38f0b |
int test1(void);
|
|
Packit Service |
b38f0b |
int test2(void);
|
|
Packit Service |
b38f0b |
int test3(void);
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
int (*tests[])(void) = { test1, test2, test3 };
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
int main(int argc, char *argv[])
|
|
Packit Service |
b38f0b |
{
|
|
Packit Service |
b38f0b |
int i,ret=0;
|
|
Packit Service |
b38f0b |
for(i=0;i
|
|
Packit Service |
b38f0b |
ret+=tests[i]();
|
|
Packit Service |
b38f0b |
if (__did_plan == 0) {
|
|
Packit Service |
b38f0b |
PLAN(__test_counter);
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
return ret;
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
int test1() {
|
|
Packit Service |
b38f0b |
int sum = 0;
|
|
Packit Service |
b38f0b |
callback_called = 0;
|
|
Packit Service |
b38f0b |
fprintf(stdout, "# snmpd_unregister_config_handler tests\n");
|
|
Packit Service |
b38f0b |
init_snmp("testing");
|
|
Packit Service |
b38f0b |
OKF(callback_called==0, ("Callback shouldn't be called before registering it - it was called %d times\n",callback_called));
|
|
Packit Service |
b38f0b |
sum += callback_called;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
callback_called = 0;
|
|
Packit Service |
b38f0b |
register_app_config_handler("testing", parse_config, test_callback, "module-name module-path");
|
|
Packit Service |
b38f0b |
OKF(callback_called==0, ("Callback shouldn't be called after registering it - it was called %d times\n",callback_called));
|
|
Packit Service |
b38f0b |
sum += callback_called;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
callback_called = 0;
|
|
Packit Service |
b38f0b |
unregister_app_config_handler("testing");
|
|
Packit Service |
b38f0b |
OKF(callback_called==1, ("Callback should have been called once and only once after unregistering handler - it was called %d times\n",callback_called));
|
|
Packit Service |
b38f0b |
sum += callback_called;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
callback_called = 0;
|
|
Packit Service |
b38f0b |
snmp_shutdown("testing");
|
|
Packit Service |
b38f0b |
OKF(callback_called==0, ("Callback should have been called once and only once after shutdown - it was called %d times\n",callback_called));
|
|
Packit Service |
b38f0b |
sum += callback_called;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
return (sum==1)?0:1;
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
int test2(void) {
|
|
Packit Service |
b38f0b |
int sum = 0;
|
|
Packit Service |
b38f0b |
callback_called = 0;
|
|
Packit Service |
b38f0b |
fprintf(stdout, "# unregister_all_config_handlers tests\n");
|
|
Packit Service |
b38f0b |
init_snmp("testing");
|
|
Packit Service |
b38f0b |
OKF(callback_called==0, ("Callback shouldn't be called before registering it - it was called %d times\n",callback_called));
|
|
Packit Service |
b38f0b |
sum += callback_called;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
callback_called = 0;
|
|
Packit Service |
b38f0b |
register_app_config_handler("testing", parse_config, test_callback, "module-name module-path");
|
|
Packit Service |
b38f0b |
OKF(callback_called==0, ("Callback shouldn't be called after registering it - it was called %d times\n",callback_called));
|
|
Packit Service |
b38f0b |
sum += callback_called;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
callback_called = 0;
|
|
Packit Service |
b38f0b |
snmp_shutdown("testing");
|
|
Packit Service |
b38f0b |
OKF(callback_called==1, ("Callback should have been called once and only once during shutdown - it was called %d times\n",callback_called));
|
|
Packit Service |
b38f0b |
sum += callback_called;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
return (sum==1)?0:1;
|
|
Packit Service |
b38f0b |
}
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
int test3(void) {
|
|
Packit Service |
b38f0b |
#ifdef TEST_INTERNAL_API
|
|
Packit Service |
b38f0b |
int sum = 0;
|
|
Packit Service |
b38f0b |
callback_called = 0;
|
|
Packit Service |
b38f0b |
fprintf(stdout, "# unregister_all_config_handlers internal api tests\n");
|
|
Packit Service |
b38f0b |
init_snmp("testing");
|
|
Packit Service |
b38f0b |
OKF(callback_called==0, ("Callback shouldn't be called before registering it - it was called %d times\n",callback_called));
|
|
Packit Service |
b38f0b |
sum += callback_called;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
callback_called = 0;
|
|
Packit Service |
b38f0b |
register_app_config_handler("testing", parse_config, test_callback, "module-name module-path");
|
|
Packit Service |
b38f0b |
OKF(callback_called==0, ("Callback shouldn't be called after registering it - it was called %d times\n",callback_called));
|
|
Packit Service |
b38f0b |
sum += callback_called;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
callback_called = 0;
|
|
Packit Service |
b38f0b |
unregister_all_config_handlers();
|
|
Packit Service |
b38f0b |
OKF(callback_called==1, ("Callback should have been called once and only once after unregistering handler - it was called %d times\n",callback_called));
|
|
Packit Service |
b38f0b |
sum += callback_called;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
callback_called = 0;
|
|
Packit Service |
b38f0b |
snmp_shutdown("testing");
|
|
Packit Service |
b38f0b |
OKF(callback_called==0, ("Callback should not have been called during shutdown after unregistering handler - it was called %d times\n",callback_called));
|
|
Packit Service |
b38f0b |
sum += callback_called;
|
|
Packit Service |
b38f0b |
|
|
Packit Service |
b38f0b |
return (sum==1)?0:1;
|
|
Packit Service |
b38f0b |
#else
|
|
Packit Service |
b38f0b |
return 0;
|
|
Packit Service |
b38f0b |
#endif
|
|
Packit Service |
b38f0b |
}
|