/*
Authors:
Pavel Březina <pbrezina@redhat.com>
Copyright (C) 2014 Red Hat
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 <talloc.h>
#include <tevent.h>
#include <errno.h>
#include <popt.h>
#include <time.h>
#include "providers/be_ptask_private.h"
#include "providers/be_ptask.h"
#include "tests/cmocka/common_mock.h"
#include "tests/cmocka/common_mock_be.h"
struct test_ctx {
bool done;
bool add_online_cb_called;
bool add_offline_cb_called;
};
} while (0)
} while (0)
/* Since both test_ctx->done and ptask->req is marked as finished already
* in the sync _send function before a new execution is scheduled we need to
* rely on the fact that ptask->req is set to zero when a new timer is
* created. This way we guarantee that the condition is true only when
* the ptask is executed and a new one is scheduled. */
{
int ret;
assert_int_equal(0, ret);
}
/* Mock few backend functions so we don't have to bring the whole
* data provider into this test. */
{
}
void *pvt,
{
test_ctx->add_online_cb_called = true;
return ERR_OK;
}
void *pvt,
struct be_cb **offline_cb)
{
test_ctx->add_offline_cb_called = true;
return ERR_OK;
}
struct test_be_ptask_state {
};
struct tevent_context *ev,
void *pvt)
{
return req;
}
struct tevent_context *ev,
void *pvt)
{
return NULL;
}
struct tevent_context *ev,
void *pvt)
{
/* we won't finish the request */
return req;
}
{
return ERR_OK;
}
{
return ERR_INTERNAL;
}
struct tevent_context *ev,
void *pvt)
{
return ERR_OK;
}
struct tevent_context *ev,
void *pvt)
{
return ERR_INTERNAL;
}
{
return 0;
}
{
return 0;
}
{
}
{
}
{
}
{
}
{
}
{
now = get_current_time();
}
}
{
now = get_current_time();
}
}
{
}
{
now = get_current_time();
now = get_current_time();
}
}
{
}
now = get_current_time();
}
}
{
now = get_current_time();
}
}
{
}
}
{
}
}
{
now = get_current_time();
}
}
{
&ptask);
now = get_current_time();
}
}
{
&ptask);
now = get_current_time();
}
}
{
&ptask);
/* first iterate until the task is executed */
}
/* then iterate until the request is destroyed */
now = get_current_time();
}
}
{
/* first run */
/* We need to acquire timestamp for the second test here, since this
* is the closest value to the timestamp when the next event is
* scheduled. */
}
/* second run */
}
}
{
}
{
}
{
now = get_current_time();
}
}
{
now = get_current_time();
}
}
{
now = get_current_time();
}
}
{
/* first run */
/* We need to acquire timestamp for the second test here, since this
* is the closest value to the timestamp when the next event is
* scheduled. */
}
/* second run */
}
}
{
int opt;
};
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
default:
return 1;
}
}
}