print_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 
00019 #include <atf-c.h>
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <unistd.h>
00025 
00026 /*
00027  * Workout if we need to force the inclusion of print.c so we can test
00028  * it on all platforms even if we don't include it in libisc.
00029  */
00030 #include <isc/platform.h>
00031 #if !defined(ISC_PLATFORM_NEEDVSNPRINTF) && !defined(ISC_PLATFORM_NEEDSPRINTF)
00032 #define ISC__PRINT_SOURCE
00033 #include "../print.c"
00034 #else
00035 #if !defined(ISC_PLATFORM_NEEDVSNPRINTF) || !defined(ISC_PLATFORM_NEEDSPRINTF)
00036 #define ISC__PRINT_SOURCE
00037 #endif
00038 #include <isc/print.h>
00039 #include <isc/types.h>
00040 #include <isc/util.h>
00041 #endif
00042 
00043 ATF_TC(snprintf);
00044 ATF_TC_HEAD(snprintf, tc) {
00045         atf_tc_set_md_var(tc, "descr", "snprintf implementation");
00046 }
00047 ATF_TC_BODY(snprintf, tc) {
00048         char buf[10000];
00049         isc_uint64_t ll = 8589934592ULL;
00050         int n;
00051 
00052         UNUSED(tc);
00053 
00054         /*
00055          * 4294967296 <= 8589934592 < 1000000000^2 to verify fix for
00056          * RT#36505.
00057          */
00058 
00059         memset(buf, 0xff, sizeof(buf));
00060         n = isc_print_snprintf(buf, sizeof(buf), "%qu", ll);
00061         ATF_CHECK_EQ(n, 10);
00062         ATF_CHECK_STREQ(buf, "8589934592");
00063 
00064         memset(buf, 0xff, sizeof(buf));
00065         n = isc_print_snprintf(buf, sizeof(buf), "%llu", ll);
00066         ATF_CHECK_EQ(n, 10);
00067         ATF_CHECK_STREQ(buf, "8589934592");
00068 }
00069 
00070 /*
00071  * Main
00072  */
00073 ATF_TP_ADD_TCS(tp) {
00074         ATF_TP_ADD_TC(tp, snprintf);
00075         return (atf_no_error());
00076 }

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