summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-05-30 12:54:31 -0400
committerNick Mathewson <nickm@torproject.org>2016-06-11 10:11:52 -0400
commit493499a3399f8a8532b4b2a80006c033e8f64c58 (patch)
treefb1965c627838137ecd4634fba00cbcccd253372 /src/test
parent2ff20c93a5ec753a0c46ca5ecd991b8e2020f7d0 (diff)
downloadtor-493499a3399f8a8532b4b2a80006c033e8f64c58.tar.gz
tor-493499a3399f8a8532b4b2a80006c033e8f64c58.zip
Add -Wfloat-conversion for GCC >= 4.9
This caught quite a few minor issues in our unit tests and elsewhere in our code.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_channeltls.c12
-rw-r--r--src/test/test_tortls.c7
-rw-r--r--src/test/test_util.c14
3 files changed, 17 insertions, 16 deletions
diff --git a/src/test/test_channeltls.c b/src/test/test_channeltls.c
index 04ae9a6da7..f5fa50c31e 100644
--- a/src/test/test_channeltls.c
+++ b/src/test/test_channeltls.c
@@ -185,7 +185,7 @@ test_channeltls_overhead_estimate(void *arg)
const char test_digest[DIGEST_LEN] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14 };
- float r;
+ double r;
channel_tls_t *tlschan = NULL;
(void)arg;
@@ -212,25 +212,25 @@ test_channeltls_overhead_estimate(void *arg)
tlschan->conn->bytes_xmitted = 128;
tlschan->conn->bytes_xmitted_by_tls = 64;
r = ch->get_overhead_estimate(ch);
- tt_assert(fabsf(r - 1.0f) < 1E-12);
+ tt_assert(fabs(r - 1.0f) < 1E-12);
tlschan->conn->bytes_xmitted_by_tls = 127;
r = ch->get_overhead_estimate(ch);
- tt_assert(fabsf(r - 1.0f) < 1E-12);
+ tt_assert(fabs(r - 1.0f) < 1E-12);
/* Now middle of the range */
tlschan->conn->bytes_xmitted_by_tls = 192;
r = ch->get_overhead_estimate(ch);
- tt_assert(fabsf(r - 1.5f) < 1E-12);
+ tt_assert(fabs(r - 1.5f) < 1E-12);
/* Now above the 2.0f clamp */
tlschan->conn->bytes_xmitted_by_tls = 257;
r = ch->get_overhead_estimate(ch);
- tt_assert(fabsf(r - 2.0f) < 1E-12);
+ tt_assert(fabs(r - 2.0f) < 1E-12);
tlschan->conn->bytes_xmitted_by_tls = 512;
r = ch->get_overhead_estimate(ch);
- tt_assert(fabsf(r - 2.0f) < 1E-12);
+ tt_assert(fabs(r - 2.0f) < 1E-12);
done:
if (ch) {
diff --git a/src/test/test_tortls.c b/src/test/test_tortls.c
index 973e727b46..caaada8701 100644
--- a/src/test/test_tortls.c
+++ b/src/test/test_tortls.c
@@ -8,6 +8,7 @@
#ifdef _WIN32
#include <winsock2.h>
#endif
+#include <math.h>
#ifdef __GNUC__
#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
@@ -1194,17 +1195,17 @@ test_tortls_get_write_overhead_ratio(void *ignored)
total_bytes_written_over_tls = 0;
ret = tls_get_write_overhead_ratio();
- tt_int_op(ret, OP_EQ, 1.0);
+ tt_double_op(fabs(ret - 1.0), OP_LT, 1E-12);
total_bytes_written_by_tls = 10;
total_bytes_written_over_tls = 1;
ret = tls_get_write_overhead_ratio();
- tt_int_op(ret, OP_EQ, 10.0);
+ tt_double_op(fabs(ret - 10.0), OP_LT, 1E-12);
total_bytes_written_by_tls = 10;
total_bytes_written_over_tls = 2;
ret = tls_get_write_overhead_ratio();
- tt_int_op(ret, OP_EQ, 5.0);
+ tt_double_op(fabs(ret - 5.0), OP_LT, 1E-12);
done:
(void)0;
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 2726c31fe8..05c7d60ea9 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1472,24 +1472,24 @@ test_util_strmisc(void *arg)
{
/* Test parse_double */
- double d = tor_parse_double("10", 0, UINT64_MAX,&i,NULL);
+ double d = tor_parse_double("10", 0, (double)UINT64_MAX,&i,NULL);
tt_int_op(1,OP_EQ, i);
tt_assert(DBL_TO_U64(d) == 10);
- d = tor_parse_double("0", 0, UINT64_MAX,&i,NULL);
+ d = tor_parse_double("0", 0, (double)UINT64_MAX,&i,NULL);
tt_int_op(1,OP_EQ, i);
tt_assert(DBL_TO_U64(d) == 0);
- d = tor_parse_double(" ", 0, UINT64_MAX,&i,NULL);
+ d = tor_parse_double(" ", 0, (double)UINT64_MAX,&i,NULL);
tt_int_op(0,OP_EQ, i);
- d = tor_parse_double(".0a", 0, UINT64_MAX,&i,NULL);
+ d = tor_parse_double(".0a", 0, (double)UINT64_MAX,&i,NULL);
tt_int_op(0,OP_EQ, i);
- d = tor_parse_double(".0a", 0, UINT64_MAX,&i,&cp);
+ d = tor_parse_double(".0a", 0, (double)UINT64_MAX,&i,&cp);
tt_int_op(1,OP_EQ, i);
- d = tor_parse_double("-.0", 0, UINT64_MAX,&i,NULL);
+ d = tor_parse_double("-.0", 0, (double)UINT64_MAX,&i,NULL);
tt_int_op(1,OP_EQ, i);
tt_assert(DBL_TO_U64(d) == 0);
d = tor_parse_double("-10", -100.0, 100.0,&i,NULL);
tt_int_op(1,OP_EQ, i);
- tt_int_op(-10.0,OP_EQ, d);
+ tt_double_op(fabs(d - -10.0),OP_LT, 1E-12);
}
{