counter_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 #include <config.h>
00018 #include <stdlib.h>
00019 
00020 #include <atf-c.h>
00021 
00022 #include <isc/counter.h>
00023 #include <isc/result.h>
00024 
00025 #include "isctest.h"
00026 
00027 ATF_TC(isc_counter);
00028 ATF_TC_HEAD(isc_counter, tc) {
00029         atf_tc_set_md_var(tc, "descr", "isc counter object");
00030 }
00031 ATF_TC_BODY(isc_counter, tc) {
00032         isc_result_t result;
00033         isc_counter_t *counter = NULL;
00034         int i;
00035 
00036         result = isc_test_begin(NULL, ISC_TRUE);
00037         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00038 
00039         result = isc_counter_create(mctx, 0, &counter);
00040         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00041 
00042         for (i = 0; i < 10; i++) {
00043                 result = isc_counter_increment(counter);
00044                 ATF_CHECK_EQ(result, ISC_R_SUCCESS);
00045         }
00046 
00047         ATF_CHECK_EQ(isc_counter_used(counter), 10);
00048 
00049         isc_counter_setlimit(counter, 15);
00050         for (i = 0; i < 10; i++) {
00051                 result = isc_counter_increment(counter);
00052                 if (result != ISC_R_SUCCESS)
00053                         break;
00054         }
00055 
00056         ATF_CHECK_EQ(isc_counter_used(counter), 15);
00057 
00058         isc_counter_detach(&counter);
00059         isc_test_end();
00060 }
00061 
00062 /*
00063  * Main
00064  */
00065 ATF_TP_ADD_TCS(tp) {
00066         ATF_TP_ADD_TC(tp, isc_counter);
00067         return (atf_no_error());
00068 }
00069 

Generated on Tue Apr 28 17:41:05 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha