Add casts for signed/unsigned ints
[yaz-moved-to-github.git] / test / tstodr.c
index 3f6fecd..83d2d2c 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2009 Index Data
+ * Copyright (C) 1995-2010 Index Data
  * See the file LICENSE for details.
  */
 #include <stdlib.h>
@@ -105,13 +105,13 @@ void tst_MySequence3(ODR encode, ODR decode)
     Yc_MySequence *t;
 
     srand(123);
-    for (i = 0; i<1000; i++)
+    for (i = 0; i < 1000; i++)
     {
         int j;
-        for (j = 0; j<sizeof(buf); j++)
+        for (j = 0; j < (int) sizeof(buf); j++)
             buf[j] = rand();
 
-        for (j = 1; j<sizeof(buf); j++)
+        for (j = 1; j < (int) sizeof(buf); j++)
         {
             odr_setbuf(decode, buf, j, 0);
             yc_MySequence(decode, &t, 0, 0);
@@ -120,7 +120,7 @@ void tst_MySequence3(ODR encode, ODR decode)
     }
 }
 
-static void tst_berint(ODR encode, ODR decode)
+static void tst_berint32(ODR encode, ODR decode)
 {
     char *buf = 0;
     int len = 0;
@@ -128,8 +128,8 @@ static void tst_berint(ODR encode, ODR decode)
     Odr_int ret_val;
     int r;
     
-    odr_reset(encode);
     val = 0;
+    odr_reset(encode);
     r = ber_integer(encode, &val);
     YAZ_CHECK_EQ(r, 1);
     buf = odr_getbuf(encode, &len, 0);
@@ -223,7 +223,7 @@ static void tst_berint(ODR encode, ODR decode)
     ber_integer(decode, &ret_val);
     YAZ_CHECK_EQ(ret_val, 2147483647);
 
-    val = (Odr_int) -2147483647L -1; /* -2^31 */
+    val = -2147483647L -1; /* -2^31 */
     odr_reset(encode);
     r = ber_integer(encode, &val);
     YAZ_CHECK_EQ(r, 1);
@@ -240,7 +240,17 @@ static void tst_berint(ODR encode, ODR decode)
     odr_setbuf(decode, buf, len, 0);
     ber_integer(decode, &ret_val);
     YAZ_CHECK_EQ(ret_val, (Odr_int) -2147483647L -1);
+}
 
+static void tst_berint64(ODR encode, ODR decode)
+{
+#if NMEM_64
+    char *buf = 0;
+    int len = 0;
+    Odr_int val;
+    Odr_int ret_val;
+    int r;
+    
     val = (Odr_int) 2 * 2147483648UL; /* 2^32 */
     odr_reset(encode);
     r = ber_integer(encode, &val);
@@ -260,7 +270,6 @@ static void tst_berint(ODR encode, ODR decode)
     ber_integer(decode, &ret_val);
     YAZ_CHECK_EQ(ret_val, val);
 
-
     val = (Odr_int) -2 * 2147483648UL; /* -2^32 */
     odr_reset(encode);
     r = ber_integer(encode, &val);
@@ -299,6 +308,7 @@ static void tst_berint(ODR encode, ODR decode)
     odr_setbuf(decode, buf, len, 0);
     ber_integer(decode, &ret_val);
     YAZ_CHECK_EQ(ret_val, val);
+#endif
 }
 
 static void tst(void)
@@ -313,7 +323,8 @@ static void tst(void)
     tst_MySequence2(odr_encode, odr_decode);
     tst_MySequence3(odr_encode, odr_decode);
 
-    tst_berint(odr_encode, odr_decode);
+    tst_berint32(odr_encode, odr_decode);
+    tst_berint64(odr_encode, odr_decode);
 
     odr_destroy(odr_encode);
     odr_destroy(odr_decode);