05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt */
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt#include <config.h>
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt#include <stdlib.h>
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt#include <atf-c.h>
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt#include <isc/counter.h>
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt#include <isc/result.h>
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt#include "isctest.h"
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan HuntATF_TC(isc_counter);
05e448935cb2d6ab08c24257f6536362d3496512Evan HuntATF_TC_HEAD(isc_counter, tc) {
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt atf_tc_set_md_var(tc, "descr", "isc counter object");
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt}
05e448935cb2d6ab08c24257f6536362d3496512Evan HuntATF_TC_BODY(isc_counter, tc) {
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt isc_result_t result;
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt isc_counter_t *counter = NULL;
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt int i;
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt result = isc_test_begin(NULL, ISC_TRUE);
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt result = isc_counter_create(mctx, 0, &counter);
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt for (i = 0; i < 10; i++) {
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt result = isc_counter_increment(counter);
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt ATF_CHECK_EQ(result, ISC_R_SUCCESS);
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt }
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt ATF_CHECK_EQ(isc_counter_used(counter), 10);
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt isc_counter_setlimit(counter, 15);
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt for (i = 0; i < 10; i++) {
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt result = isc_counter_increment(counter);
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt if (result != ISC_R_SUCCESS)
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt break;
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt }
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt ATF_CHECK_EQ(isc_counter_used(counter), 15);
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt isc_counter_detach(&counter);
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt isc_test_end();
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt}
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt/*
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt * Main
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt */
05e448935cb2d6ab08c24257f6536362d3496512Evan HuntATF_TP_ADD_TCS(tp) {
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt ATF_TP_ADD_TC(tp, isc_counter);
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt return (atf_no_error());
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt}
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt