179d8f4cc893420557c38d940b611404608d0239ckb/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2012, 2013, 2016 Internet Systems Consortium, Inc. ("ISC")
179d8f4cc893420557c38d940b611404608d0239ckb *
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/.
179d8f4cc893420557c38d940b611404608d0239ckb */
179d8f4cc893420557c38d940b611404608d0239ckb
024cf50d122a16a3ce190692d3669ecee47c23aaTinderbox User/* $Id$ */
024cf50d122a16a3ce190692d3669ecee47c23aaTinderbox User
179d8f4cc893420557c38d940b611404608d0239ckb/*! \file */
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb#include <config.h>
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb#include <atf-c.h>
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb#include <unistd.h>
179d8f4cc893420557c38d940b611404608d0239ckb#include <time.h>
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb#include <isc/parseint.h>
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb#include "isctest.h"
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb/*
179d8f4cc893420557c38d940b611404608d0239ckb * Individual unit tests
179d8f4cc893420557c38d940b611404608d0239ckb */
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb/* Test for 32 bit overflow on 64 bit machines in isc_parse_uint32 */
179d8f4cc893420557c38d940b611404608d0239ckbATF_TC(parse_overflow);
179d8f4cc893420557c38d940b611404608d0239ckbATF_TC_HEAD(parse_overflow, tc) {
179d8f4cc893420557c38d940b611404608d0239ckb atf_tc_set_md_var(tc, "descr", "Check for 32 bit overflow");
179d8f4cc893420557c38d940b611404608d0239ckb}
179d8f4cc893420557c38d940b611404608d0239ckbATF_TC_BODY(parse_overflow, tc) {
179d8f4cc893420557c38d940b611404608d0239ckb isc_result_t result;
179d8f4cc893420557c38d940b611404608d0239ckb isc_uint32_t output;
179d8f4cc893420557c38d940b611404608d0239ckb UNUSED(tc);
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb result = isc_test_begin(NULL, ISC_TRUE);
179d8f4cc893420557c38d940b611404608d0239ckb ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb result = isc_parse_uint32(&output, "1234567890", 10);
611dc8876869036ab5e981e53ae7a446145d9354Mark Andrews ATF_CHECK_EQ(ISC_R_SUCCESS, result);
179d8f4cc893420557c38d940b611404608d0239ckb ATF_CHECK_EQ(1234567890, output);
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb result = isc_parse_uint32(&output, "123456789012345", 10);
179d8f4cc893420557c38d940b611404608d0239ckb ATF_CHECK_EQ(ISC_R_RANGE, result);
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb result = isc_parse_uint32(&output, "12345678901234567890", 10);
179d8f4cc893420557c38d940b611404608d0239ckb ATF_CHECK_EQ(ISC_R_RANGE, result);
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb isc_test_end();
179d8f4cc893420557c38d940b611404608d0239ckb}
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb/*
179d8f4cc893420557c38d940b611404608d0239ckb * Main
179d8f4cc893420557c38d940b611404608d0239ckb */
179d8f4cc893420557c38d940b611404608d0239ckbATF_TP_ADD_TCS(tp) {
179d8f4cc893420557c38d940b611404608d0239ckb ATF_TP_ADD_TC(tp, parse_overflow);
179d8f4cc893420557c38d940b611404608d0239ckb
179d8f4cc893420557c38d940b611404608d0239ckb return (atf_no_error());
179d8f4cc893420557c38d940b611404608d0239ckb}
179d8f4cc893420557c38d940b611404608d0239ckb