1 /*	$NetBSD: counter_test.c,v 1.1.1.2 2014/12/10 03:34:44 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <config.h>
20 #include <stdlib.h>
21 
22 #include <atf-c.h>
23 
24 #include <isc/counter.h>
25 #include <isc/result.h>
26 
27 #include "isctest.h"
28 
29 ATF_TC(isc_counter);
30 ATF_TC_HEAD(isc_counter, tc) {
31 	atf_tc_set_md_var(tc, "descr", "isc counter object");
32 }
33 ATF_TC_BODY(isc_counter, tc) {
34 	isc_result_t result;
35 	isc_counter_t *counter = NULL;
36 	int i;
37 
38 	result = isc_test_begin(NULL, ISC_TRUE);
39 	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
40 
41 	result = isc_counter_create(mctx, 0, &counter);
42 	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
43 
44 	for (i = 0; i < 10; i++) {
45 		result = isc_counter_increment(counter);
46 		ATF_CHECK_EQ(result, ISC_R_SUCCESS);
47 	}
48 
49 	ATF_CHECK_EQ(isc_counter_used(counter), 10);
50 
51 	isc_counter_setlimit(counter, 15);
52 	for (i = 0; i < 10; i++) {
53 		result = isc_counter_increment(counter);
54 		if (result != ISC_R_SUCCESS)
55 			break;
56 	}
57 
58 	ATF_CHECK_EQ(isc_counter_used(counter), 15);
59 
60 	isc_counter_detach(&counter);
61 	isc_test_end();
62 }
63 
64 /*
65  * Main
66  */
67 ATF_TP_ADD_TCS(tp) {
68 	ATF_TP_ADD_TC(tp, isc_counter);
69 	return (atf_no_error());
70 }
71 
72