/*
 * 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-smtpsid.c,v 1.3 2007/05/05 02:28:47 ca Exp $")

#include "sm/assert.h"
#include "sm/error.h"
#include "sm/sysexits.h"
#include "sm/mta.h"
#include "sm/limits.h"
#include "sm/io.h"
#include "sm/test.h"

void
test(int pid)
{
	sm_ret_T ret;
	id_count_T idc, idr, step;
	sessta_id_T sessid;

	step = UINT64_MAX / (uint64_t) 64;
	for (idc = 65535; idc < UINT64_MAX; idc += step) {
		sm_snprintf(sessid, sizeof(sessid), SMTPS_STID_FORMAT, idc, pid);
		ret = sm_id2idc(sessid, &idr);
		SM_TEST(ret == SM_SUCCESS);
		SM_TEST(idr == idc);
	}
}

int
main(int argc, char *argv[])
{
	int c, pid;

	pid = 1;
	while ((c = getopt(argc, argv, "dp:")) != -1) {
		switch (c) {
		  case 'p':
			pid = (int) strtol(optarg, NULL, 0);
			break;
		  default:
			return EX_USAGE;
		}
	}

	sm_test_begin(argc, argv, "test smtps id");
	test(pid);
	return sm_test_end();
}


syntax highlighted by Code2HTML, v. 0.9.1