1 /* $NetBSD: parse_test.c,v 1.1.1.3 2014/12/10 03:34:44 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2012, 2013 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 /* Id */ 20 21 /*! \file */ 22 23 #include <config.h> 24 25 #include <atf-c.h> 26 27 #include <unistd.h> 28 #include <time.h> 29 30 #include <isc/parseint.h> 31 32 #include "isctest.h" 33 34 /* 35 * Individual unit tests 36 */ 37 38 /* Test for 32 bit overflow on 64 bit machines in isc_parse_uint32 */ 39 ATF_TC(parse_overflow); 40 ATF_TC_HEAD(parse_overflow, tc) { 41 atf_tc_set_md_var(tc, "descr", "Check for 32 bit overflow"); 42 } 43 ATF_TC_BODY(parse_overflow, tc) { 44 isc_result_t result; 45 isc_uint32_t output; 46 UNUSED(tc); 47 48 result = isc_test_begin(NULL, ISC_TRUE); 49 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); 50 51 result = isc_parse_uint32(&output, "1234567890", 10); 52 ATF_CHECK_EQ(ISC_R_SUCCESS, result); 53 ATF_CHECK_EQ(1234567890, output); 54 55 result = isc_parse_uint32(&output, "123456789012345", 10); 56 ATF_CHECK_EQ(ISC_R_RANGE, result); 57 58 result = isc_parse_uint32(&output, "12345678901234567890", 10); 59 ATF_CHECK_EQ(ISC_R_RANGE, result); 60 61 isc_test_end(); 62 } 63 64 /* 65 * Main 66 */ 67 ATF_TP_ADD_TCS(tp) { 68 ATF_TP_ADD_TC(tp, parse_overflow); 69 70 return (atf_no_error()); 71 } 72 73