/*
* Copyright (c) 2004 Sendmail, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*
*/
#include "sm/generic.h"
SM_RCSID("@(#)$Id: t-edbc-1.c,v 1.5 2006/03/13 18:41:33 ca Exp $")
#include "t-edbc.h"
static void
test(void)
{
int a;
rcpt_id_T rcpt_ids[MAX_KEYS];
sm_ret_T ret;
sm_memzero(&edbc_node_search, sizeof(edbc_node_search));
sm_memzero(&edbc_tnode, sizeof(edbc_tnode));
ECNL_INIT(&(edbc_tnode.ectn_hd));
ECNL_APP(&(edbc_tnode.ectn_hd), &edbc_node_search);
ret = edbc_open(&edbc_ctx, 0, 10);
SM_TEST(ret == SM_SUCCESS);
if (ret != SM_SUCCESS)
return;
for (a = 0; a < MAX_KEYS; a++)
{
next_try[a] = a;
added[a] = false;
sm_snprintf(rcpt_ids[a], sizeof(rcpt_ids[a]),
SMTP_RCPTID_FORMAT, "rcpt-id-filler-text", a);
}
next_try[1] = 9;
next_try[6] = 5;
next_try[7] = 5;
next_try[9] = 5;
next_try[10] = 11;
next_try[12] = 10;
next_try[13] = 10;
intree();
TINS(3);
TINS(5);
TINS(1);
TINS(10);
TINS(4);
TINS(12);
TINS(2);
TINS(9);
TINS(8);
TINS(7);
/*
** next add will fail: cache full, but there is an entry
** next_try[10] = 11
*/
a = 11;
ret = edbc_add(edbc_ctx, rcpt_ids[a], next_try[a], false);
SM_TEST(ret != SM_SUCCESS);
if (ret == SM_SUCCESS)
goto error;
edbc_node_search.ecn_next_try = next_try[a];
edbc_tnode_ret = RB_FIND(edbc_tree_S, &edbc_ctx->edbc_root,
&edbc_tnode);
SM_TEST(edbc_tnode_ret != NULL);
intree();
print_tree(edbc_ctx);
/*
** insert will fail: cache full and it is as old as the last entry
*/
a = 11;
ret = edbc_insert(edbc_ctx, rcpt_ids[a], next_try[a], false);
SM_TEST(ret != SM_SUCCESS);
if (ret == SM_SUCCESS)
goto error;
edbc_node_search.ecn_next_try = next_try[a];
edbc_tnode_ret = RB_FIND(edbc_tree_S, &edbc_ctx->edbc_root,
&edbc_tnode);
SM_TEST(edbc_tnode_ret != NULL);
intree();
print_tree(edbc_ctx);
/*
** insert will succeed: cache full, last entry is 11 which will
** be removed
*/
a = 13;
ret = edbc_insert(edbc_ctx, rcpt_ids[a], next_try[a], false);
SM_TEST(ret == SM_SUCCESS);
if (ret != SM_SUCCESS)
goto error;
edbc_node_search.ecn_next_try = next_try[a];
edbc_tnode_ret = RB_FIND(edbc_tree_S, &edbc_ctx->edbc_root,
&edbc_tnode);
SM_TEST(edbc_tnode_ret != NULL);
added[next_try[a]] = true;
added[11] = false;
intree();
print_tree(edbc_ctx);
/* finds time == 10 */
edbc_tnode_ret = edbct_last(edbc_ctx);
SM_TEST(edbc_tnode_ret != NULL);
SM_TEST(ECNL_FIRST(&edbc_tnode_ret->ectn_hd)->ecn_next_try == 10);
ret = edbct_rm(edbc_ctx, edbc_tnode_ret);
SM_TEST(ret == SM_SUCCESS);
Entries -= 2;
added[10] = false;
INTREE(10);
intree();
print_tree(edbc_ctx);
/* finds time == 9 */
edbc_tnode_ret = edbct_last(edbc_ctx);
SM_TEST(edbc_tnode_ret != NULL);
SM_TEST(ECNL_FIRST(&edbc_tnode_ret->ectn_hd)->ecn_next_try == 9);
ret = edbct_rm(edbc_ctx, edbc_tnode_ret);
SM_TEST(ret == SM_SUCCESS);
Entries--;
added[9] = false;
INTREE(9);
intree();
print_tree(edbc_ctx);
/* finds time == 8 */
edbc_tnode_ret = edbct_last(edbc_ctx);
SM_TEST(edbc_tnode_ret != NULL);
SM_TEST(ECNL_FIRST(&edbc_tnode_ret->ectn_hd)->ecn_next_try == 8);
ret = edbct_rm(edbc_ctx, edbc_tnode_ret);
SM_TEST(ret == SM_SUCCESS);
Entries--;
added[8] = false;
INTREE(8);
intree();
print_tree(edbc_ctx);
/* finds time == 5 */
edbc_tnode_ret = edbct_last(edbc_ctx);
SM_TEST(edbc_tnode_ret != NULL);
SM_TEST(ECNL_FIRST(&edbc_tnode_ret->ectn_hd)->ecn_next_try == 5);
ret = edbct_rm(edbc_ctx, edbc_tnode_ret);
SM_TEST(ret == SM_SUCCESS);
Entries -= 3;
added[5] = false;
INTREE(5);
intree();
print_tree(edbc_ctx);
/* finds time == 4 */
edbc_tnode_ret = edbct_last(edbc_ctx);
SM_TEST(edbc_tnode_ret != NULL);
SM_TEST(ECNL_FIRST(&edbc_tnode_ret->ectn_hd)->ecn_next_try == 4);
ret = edbct_rm(edbc_ctx, edbc_tnode_ret);
SM_TEST(ret == SM_SUCCESS);
Entries--;
added[4] = false;
INTREE(4);
intree();
print_tree(edbc_ctx);
/* finds time == 3 */
edbc_tnode_ret = edbct_last(edbc_ctx);
SM_TEST(edbc_tnode_ret != NULL);
SM_TEST(ECNL_FIRST(&edbc_tnode_ret->ectn_hd)->ecn_next_try == 3);
ret = edbct_rm(edbc_ctx, edbc_tnode_ret);
SM_TEST(ret == SM_SUCCESS);
Entries--;
added[3] = false;
INTREE(3);
intree();
print_tree(edbc_ctx);
/* finds time == 2 */
edbc_tnode_ret = edbct_last(edbc_ctx);
SM_TEST(edbc_tnode_ret != NULL);
SM_TEST(ECNL_FIRST(&edbc_tnode_ret->ectn_hd)->ecn_next_try == 2);
ret = edbct_rm(edbc_ctx, edbc_tnode_ret);
SM_TEST(ret == SM_SUCCESS);
Entries--;
added[2] = false;
INTREE(2);
intree();
print_tree(edbc_ctx);
edbc_tnode_ret = edbct_last(edbc_ctx);
SM_TEST(edbc_tnode_ret == NULL);
print_tree2(edbc_ctx);
error:
edbc_close(edbc_ctx);
return;
}
int
main(int argc, char *argv[])
{
sm_test_begin(argc, argv, "test edbc 0");
test();
return sm_test_end();
}
syntax highlighted by Code2HTML, v. 0.9.1