Skip to contentSkip to conversation

Fix and improve qint_from_int64_test

PATCH In review Pierre Riteau 2 participants 2 messages Sep 8, 2009 – Sep 9, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix and improve qint_from_int64_test

Use a long long integer constant to fix a compilation error (integer constant is too large for 'long' type).

Use a better value for testing, as -1 makes the test pass even if qi->value is of type uint32_t, float or double. This was suggested by Reimar Döffinger <[email protected]>.

Also, make the test fail when qi->value is of type double or float by casting qi->value to int64_t, to avoid value being promoted to the type of qi->value.

---
 check-qint.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
check-qint.c +2 -2
index ae5d22f..49887bb 100644
@@ -43,10 +43,10 @@ END_TEST
 START_TEST(qint_from_int64_test)
 {
     QInt *qi;
-    const int64_t value = 0xffffffffffffffff;
+    const int64_t value = 0x1234567890abcdefLL;
 
     qi = qint_from_int(value);
-    fail_unless(qi->value == value);
+    fail_unless((int64_t) qi->value == value);
 
     QDECREF(qi);
 }
Signature · 1 line
1.6.3.3
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Tue, 8 Sep 2009 11:53:37 +0200 Pierre Riteau <[email protected]> wrote:

Use a long long integer constant to fix a compilation error (integer constant is too large for 'long' type).

Use a better value for testing, as -1 makes the test pass even if qi->value is of type uint32_t, float or double. This was suggested by Reimar Döffinger <[email protected]>.

Quoted 5 lines

Also, make the test fail when qi->value is of type double or float by casting qi->value to int64_t, to avoid value being promoted to the type of qi->value.

Seems good to me.