2011-04-21 00:33:09 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009-2011, The Regents of the University of California,
|
|
|
|
* through Lawrence Berkeley National Laboratory (subject to receipt of any
|
|
|
|
* required approvals from the U.S. Dept. of Energy). All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is distributed under a BSD style license, see the LICENSE file
|
|
|
|
* for complete information.
|
|
|
|
*/
|
|
|
|
|
2009-02-24 11:05:14 +03:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "iperf.h"
|
|
|
|
#include "units.h"
|
|
|
|
|
2009-10-20 02:35:18 +04:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
2009-02-24 11:05:14 +03:00
|
|
|
{
|
|
|
|
iperf_size_t llu;
|
2009-10-20 02:35:18 +04:00
|
|
|
double d;
|
|
|
|
char s[11];
|
2009-02-24 11:05:14 +03:00
|
|
|
|
|
|
|
assert(1024.0 * 0.5 == unit_atof("0.5K"));
|
|
|
|
assert(1024.0 == unit_atof("1K"));
|
2009-10-20 02:35:18 +04:00
|
|
|
assert(1024.0 * 1024.0 == unit_atof("1M"));
|
|
|
|
assert(4.0 * 1024.0 * 1024.0 * 1024.0 == unit_atof("4G"));
|
2009-02-24 11:05:14 +03:00
|
|
|
|
2013-12-10 05:52:59 +04:00
|
|
|
#ifdef notdef
|
|
|
|
/* Obsolete - we no longer make a distinction between upper and lower
|
|
|
|
** case.
|
|
|
|
*/
|
2009-02-24 11:05:14 +03:00
|
|
|
assert(1000.0 * 0.5 == unit_atof("0.5k"));
|
|
|
|
assert(1000.0 == unit_atof("1k"));
|
2009-10-20 02:35:18 +04:00
|
|
|
assert(1000.0 * 1000.0 == unit_atof("1m"));
|
|
|
|
assert(4.0 * 1000.0 * 1000.0 * 1000.0 == unit_atof("4g"));
|
2013-12-10 05:52:59 +04:00
|
|
|
#endif
|
|
|
|
assert(1024.0 * 0.5 == unit_atof("0.5k"));
|
|
|
|
assert(1024.0 == unit_atof("1k"));
|
|
|
|
assert(1024.0 * 1024.0 == unit_atof("1m"));
|
|
|
|
assert(4.0 * 1024.0 * 1024.0 * 1024.0 == unit_atof("4g"));
|
2009-02-24 11:05:14 +03:00
|
|
|
|
|
|
|
assert(1024 * 0.5 == unit_atoi("0.5K"));
|
|
|
|
assert(1024 == unit_atoi("1K"));
|
2009-10-20 02:35:18 +04:00
|
|
|
assert(1024 * 1024 == unit_atoi("1M"));
|
|
|
|
d = 4.0 * 1024 * 1024 * 1024;
|
2009-02-24 11:05:14 +03:00
|
|
|
llu = (iperf_size_t) d;
|
|
|
|
assert(llu == unit_atoi("4G"));
|
|
|
|
|
2013-12-10 05:52:59 +04:00
|
|
|
#ifdef notdef
|
|
|
|
/* Also obsolete. */
|
2009-02-24 11:05:14 +03:00
|
|
|
assert(1000 * 0.5 == unit_atoi("0.5k"));
|
|
|
|
assert(1000 == unit_atoi("1k"));
|
2009-10-20 02:35:18 +04:00
|
|
|
assert(1000 * 1000 == unit_atoi("1m"));
|
|
|
|
d = 4.0 * 1000 * 1000 * 1000;
|
2009-02-24 11:05:14 +03:00
|
|
|
llu = (iperf_size_t) d;
|
|
|
|
assert(llu == unit_atoi("4g"));
|
2013-12-10 05:52:59 +04:00
|
|
|
#endif
|
|
|
|
assert(1024 * 0.5 == unit_atoi("0.5k"));
|
|
|
|
assert(1024 == unit_atoi("1k"));
|
|
|
|
assert(1024 * 1024 == unit_atoi("1m"));
|
|
|
|
d = 4.0 * 1024 * 1024 * 1024;
|
|
|
|
llu = (iperf_size_t) d;
|
|
|
|
assert(llu == unit_atoi("4g"));
|
2009-02-24 11:05:14 +03:00
|
|
|
|
|
|
|
unit_snprintf(s, 11, 1024.0, 'A');
|
2009-10-20 02:35:18 +04:00
|
|
|
assert(strncmp(s, "1.00 KByte", 11) == 0);
|
2009-02-24 11:05:14 +03:00
|
|
|
|
|
|
|
unit_snprintf(s, 11, 1024.0 * 1024.0, 'A');
|
2009-10-20 02:35:18 +04:00
|
|
|
assert(strncmp(s, "1.00 MByte", 11) == 0);
|
2009-02-24 11:05:14 +03:00
|
|
|
|
|
|
|
unit_snprintf(s, 11, 1000.0, 'k');
|
2009-10-20 02:35:18 +04:00
|
|
|
assert(strncmp(s, "8.00 Kbit", 11) == 0);
|
2009-02-24 11:05:14 +03:00
|
|
|
|
|
|
|
unit_snprintf(s, 11, 1000.0 * 1000.0, 'a');
|
2009-10-20 02:35:18 +04:00
|
|
|
assert(strncmp(s, "8.00 Mbit", 11) == 0);
|
2009-02-24 11:05:14 +03:00
|
|
|
|
2009-10-20 02:35:18 +04:00
|
|
|
d = 4.0 * 1024 * 1024 * 1024;
|
2009-02-24 11:05:14 +03:00
|
|
|
unit_snprintf(s, 11, d, 'A');
|
2009-10-20 02:35:18 +04:00
|
|
|
assert(strncmp(s, "4.00 GByte", 11) == 0);
|
2009-02-24 11:05:14 +03:00
|
|
|
|
|
|
|
unit_snprintf(s, 11, d, 'a');
|
2009-10-20 02:35:18 +04:00
|
|
|
assert(strncmp(s, "34.4 Gbit", 11) == 0);
|
2009-02-24 11:05:14 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|