parse_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012, 2013  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 /* $Id$ */
00018 
00019 /*! \file */
00020 
00021 #include <config.h>
00022 
00023 #include <atf-c.h>
00024 
00025 #include <unistd.h>
00026 #include <time.h>
00027 
00028 #include <isc/parseint.h>
00029 
00030 #include "isctest.h"
00031 
00032 /*
00033  * Individual unit tests
00034  */
00035 
00036 /* Test for 32 bit overflow on 64 bit machines in isc_parse_uint32 */
00037 ATF_TC(parse_overflow);
00038 ATF_TC_HEAD(parse_overflow, tc) {
00039         atf_tc_set_md_var(tc, "descr", "Check for 32 bit overflow");
00040 }
00041 ATF_TC_BODY(parse_overflow, tc) {
00042         isc_result_t result;
00043         isc_uint32_t output;
00044         UNUSED(tc);
00045 
00046         result = isc_test_begin(NULL, ISC_TRUE);
00047         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00048 
00049         result = isc_parse_uint32(&output, "1234567890", 10);
00050         ATF_CHECK_EQ(ISC_R_SUCCESS, result);
00051         ATF_CHECK_EQ(1234567890, output);
00052 
00053         result = isc_parse_uint32(&output, "123456789012345", 10);
00054         ATF_CHECK_EQ(ISC_R_RANGE, result);
00055 
00056         result = isc_parse_uint32(&output, "12345678901234567890", 10);
00057         ATF_CHECK_EQ(ISC_R_RANGE, result);
00058 
00059         isc_test_end();
00060 }
00061 
00062 /*
00063  * Main
00064  */
00065 ATF_TP_ADD_TCS(tp) {
00066         ATF_TP_ADD_TC(tp, parse_overflow);
00067 
00068         return (atf_no_error());
00069 }
00070 

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