Annotation of embedaddon/iperf/src/t_units.c, revision 1.1
1.1 ! misho 1: /*
! 2: * iperf, Copyright (c) 2014, The Regents of the University of
! 3: * California, through Lawrence Berkeley National Laboratory (subject
! 4: * to receipt of any required approvals from the U.S. Dept. of
! 5: * Energy). All rights reserved.
! 6: *
! 7: * If you have questions about your rights to use or distribute this
! 8: * software, please contact Berkeley Lab's Technology Transfer
! 9: * Department at TTD@lbl.gov.
! 10: *
! 11: * NOTICE. This software is owned by the U.S. Department of Energy.
! 12: * As such, the U.S. Government has been granted for itself and others
! 13: * acting on its behalf a paid-up, nonexclusive, irrevocable,
! 14: * worldwide license in the Software to reproduce, prepare derivative
! 15: * works, and perform publicly and display publicly. Beginning five
! 16: * (5) years after the date permission to assert copyright is obtained
! 17: * from the U.S. Department of Energy, and subject to any subsequent
! 18: * five (5) year renewals, the U.S. Government is granted for itself
! 19: * and others acting on its behalf a paid-up, nonexclusive,
! 20: * irrevocable, worldwide license in the Software to reproduce,
! 21: * prepare derivative works, distribute copies to the public, perform
! 22: * publicly and display publicly, and to permit others to do so.
! 23: *
! 24: * This code is distributed under a BSD style license, see the LICENSE
! 25: * file for complete information.
! 26: */
! 27: #include <assert.h>
! 28: #ifdef HAVE_STDINT_H
! 29: #include <stdint.h>
! 30: #endif
! 31: #include <stdio.h>
! 32: #include <string.h>
! 33:
! 34: #include "iperf.h"
! 35: #include "units.h"
! 36:
! 37: int
! 38: main(int argc, char **argv)
! 39: {
! 40: iperf_size_t llu;
! 41: double d;
! 42: char s[11];
! 43:
! 44: assert(1024.0 * 0.5 == unit_atof("0.5K"));
! 45: assert(1024.0 == unit_atof("1K"));
! 46: assert(1024.0 * 1024.0 == unit_atof("1M"));
! 47: assert(4.0 * 1024.0 * 1024.0 * 1024.0 == unit_atof("4G"));
! 48:
! 49: #ifdef notdef
! 50: /* Obsolete - we no longer make a distinction between upper and lower
! 51: ** case.
! 52: */
! 53: assert(1000.0 * 0.5 == unit_atof("0.5k"));
! 54: assert(1000.0 == unit_atof("1k"));
! 55: assert(1000.0 * 1000.0 == unit_atof("1m"));
! 56: assert(4.0 * 1000.0 * 1000.0 * 1000.0 == unit_atof("4g"));
! 57: #endif
! 58: assert(1024.0 * 0.5 == unit_atof("0.5k"));
! 59: assert(1024.0 == unit_atof("1k"));
! 60: assert(1024.0 * 1024.0 == unit_atof("1m"));
! 61: assert(4.0 * 1024.0 * 1024.0 * 1024.0 == unit_atof("4g"));
! 62:
! 63: assert(1024 * 0.5 == unit_atoi("0.5K"));
! 64: assert(1024 == unit_atoi("1K"));
! 65: assert(1024 * 1024 == unit_atoi("1M"));
! 66: d = 4.0 * 1024 * 1024 * 1024;
! 67: llu = (iperf_size_t) d;
! 68: assert(llu == unit_atoi("4G"));
! 69:
! 70: #ifdef notdef
! 71: /* Also obsolete. */
! 72: assert(1000 * 0.5 == unit_atoi("0.5k"));
! 73: assert(1000 == unit_atoi("1k"));
! 74: assert(1000 * 1000 == unit_atoi("1m"));
! 75: d = 4.0 * 1000 * 1000 * 1000;
! 76: llu = (iperf_size_t) d;
! 77: assert(llu == unit_atoi("4g"));
! 78: #endif
! 79: assert(1024 * 0.5 == unit_atoi("0.5k"));
! 80: assert(1024 == unit_atoi("1k"));
! 81: assert(1024 * 1024 == unit_atoi("1m"));
! 82: d = 4.0 * 1024 * 1024 * 1024;
! 83: llu = (iperf_size_t) d;
! 84: assert(llu == unit_atoi("4g"));
! 85:
! 86: unit_snprintf(s, 11, 1024.0, 'A');
! 87: assert(strncmp(s, "1.00 KByte", 11) == 0);
! 88:
! 89: unit_snprintf(s, 11, 1024.0 * 1024.0, 'A');
! 90: assert(strncmp(s, "1.00 MByte", 11) == 0);
! 91:
! 92: unit_snprintf(s, 11, 1000.0, 'k');
! 93: assert(strncmp(s, "8.00 Kbit", 11) == 0);
! 94:
! 95: unit_snprintf(s, 11, 1000.0 * 1000.0, 'a');
! 96: assert(strncmp(s, "8.00 Mbit", 11) == 0);
! 97:
! 98: d = 4.0 * 1024 * 1024 * 1024;
! 99: unit_snprintf(s, 11, d, 'A');
! 100: assert(strncmp(s, "4.00 GByte", 11) == 0);
! 101:
! 102: unit_snprintf(s, 11, d, 'a');
! 103: assert(strncmp(s, "34.4 Gbit", 11) == 0);
! 104:
! 105: return 0;
! 106: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>