avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dcrea...@apache.org
Subject svn commit: r1294928 - in /avro/trunk: CHANGES.txt lang/c/tests/test_avro_968.c lang/c/tests/test_avro_values.c
Date Wed, 29 Feb 2012 01:24:29 GMT
Author: dcreager
Date: Wed Feb 29 01:24:29 2012
New Revision: 1294928

URL: http://svn.apache.org/viewvc?rev=1294928&view=rev
Log:
AVRO-1031. C: avro_value_cmp doesn't necessarily return {-1,0,1}.

The avro_value_cmp function uses memcmp under the covers (at least for
comparing bytes values), and so it doesn't necessarily return only -1,
0, and 1 as results.  Rather, any negative value can be used for the
less-than case, and any positive value for the greater-than case.  This
patch updates our unit tests to not assume too much about the return
value.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/c/tests/test_avro_968.c
    avro/trunk/lang/c/tests/test_avro_values.c

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1294928&r1=1294927&r2=1294928&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Feb 29 01:24:29 2012
@@ -15,6 +15,9 @@ Avro 1.6.3 (unreleased)
     AVRO-1036. Fix a regression in IDL imports created by AVRO-971.
     (George Fletcher & cutting)
 
+    AVRO-1031. C: Test cases made too many assumptions about memcmp
+    result. (dcreager)
+
 Avro 1.6.2 (13 February 2012)
 
   NEW FEATURES

Modified: avro/trunk/lang/c/tests/test_avro_968.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/test_avro_968.c?rev=1294928&r1=1294927&r2=1294928&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/test_avro_968.c (original)
+++ avro/trunk/lang/c/tests/test_avro_968.c Wed Feb 29 01:24:29 2012
@@ -52,12 +52,12 @@ main(int argc, char **argv)
 		return EXIT_FAILURE;
 	}
 
-	if (avro_value_cmp(&v1, &v2) != -1) {
+	if (avro_value_cmp(&v1, &v2) >= 0) {
 		fprintf(stderr, "Unexpected avro_value_cmp\n");
 		return EXIT_FAILURE;
 	}
 
-	if (avro_value_cmp_fast(&v1, &v2) != -1) {
+	if (avro_value_cmp_fast(&v1, &v2) >= 0) {
 		fprintf(stderr, "Unexpected avro_value_cmp_fast\n");
 		return EXIT_FAILURE;
 	}

Modified: avro/trunk/lang/c/tests/test_avro_values.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/test_avro_values.c?rev=1294928&r1=1294927&r2=1294928&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/test_avro_values.c (original)
+++ avro/trunk/lang/c/tests/test_avro_values.c Wed Feb 29 01:24:29 2012
@@ -429,11 +429,11 @@ test_boolean(void)
 	    "Cannot create boolean");
 	try(avro_generic_boolean_new(&val2, 1),
 	    "Cannot create boolean");
-	if (avro_value_cmp_fast(&val1, &val2) != -1) {
+	if (avro_value_cmp_fast(&val1, &val2) >= 0) {
 		fprintf(stderr, "Incorrect sort order\n");
 		return EXIT_FAILURE;
 	}
-	if (avro_value_cmp_fast(&val2, &val1) != 1) {
+	if (avro_value_cmp_fast(&val2, &val1) <= 0) {
 		fprintf(stderr, "Incorrect sort order\n");
 		return EXIT_FAILURE;
 	}
@@ -510,15 +510,15 @@ test_bytes(void)
 	    "Cannot create bytes");
 	try(avro_generic_bytes_new(&val3, "abce", 4),
 	    "Cannot create bytes");
-	if (avro_value_cmp_fast(&val1, &val2) != -1) {
+	if (avro_value_cmp_fast(&val1, &val2) >= 0) {
 		fprintf(stderr, "Incorrect sort order\n");
 		return EXIT_FAILURE;
 	}
-	if (avro_value_cmp_fast(&val2, &val1) != 1) {
+	if (avro_value_cmp_fast(&val2, &val1) <= 0) {
 		fprintf(stderr, "Incorrect sort order\n");
 		return EXIT_FAILURE;
 	}
-	if (avro_value_cmp_fast(&val1, &val3) != -1) {
+	if (avro_value_cmp_fast(&val1, &val3) >= 0) {
 		fprintf(stderr, "Incorrect sort order\n");
 		return EXIT_FAILURE;
 	}
@@ -645,11 +645,11 @@ test_int(void)
 	    "Cannot create int");
 	try(avro_generic_int_new(&val2, 42),
 	    "Cannot create int");
-	if (avro_value_cmp_fast(&val1, &val2) != -1) {
+	if (avro_value_cmp_fast(&val1, &val2) >= 0) {
 		fprintf(stderr, "Incorrect sort order\n");
 		return EXIT_FAILURE;
 	}
-	if (avro_value_cmp_fast(&val2, &val1) != 1) {
+	if (avro_value_cmp_fast(&val2, &val1) <= 0) {
 		fprintf(stderr, "Incorrect sort order\n");
 		return EXIT_FAILURE;
 	}



Mime
View raw message