avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dcrea...@apache.org
Subject svn commit: r1213898 - in /avro/trunk: CHANGES.txt lang/c/src/value.c lang/c/tests/CMakeLists.txt lang/c/tests/test_avro_968.c
Date Tue, 13 Dec 2011 19:54:32 GMT
Author: dcreager
Date: Tue Dec 13 19:54:32 2011
New Revision: 1213898

URL: http://svn.apache.org/viewvc?rev=1213898&view=rev
Log:
AVRO-968. C: avro_value_cmp now compares string values correctly

Before, we weren't extracting the contents of string values in
avro_value_cmp and avro_value_cmp_fast, so you'd get a garbage result.
Contributed by Vivek Nadkarni.

Added:
    avro/trunk/lang/c/tests/test_avro_968.c
Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/c/src/value.c
    avro/trunk/lang/c/tests/CMakeLists.txt

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1213898&r1=1213897&r2=1213898&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Tue Dec 13 19:54:32 2011
@@ -46,6 +46,9 @@ Avro 1.6.2 (unreleased)
 
     AVRO-978. Java: Fix reflect to better handle Byte type.  (cutting)
 
+    AVRO-968. C: Fixed avro_value_cmp and avro_value_cmp_fast for string
+    values. (Vivek Nadkarni via dcreager)
+
 Avro 1.6.1 (8 November 2011)
 
   INCOMPATIBLE CHANGES

Modified: avro/trunk/lang/c/src/value.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/value.c?rev=1213898&r1=1213897&r2=1213898&view=diff
==============================================================================
--- avro/trunk/lang/c/src/value.c (original)
+++ avro/trunk/lang/c/src/value.c Tue Dec 13 19:54:32 2011
@@ -383,6 +383,8 @@ avro_value_cmp_fast(avro_value_t *val1, 
 			size_t  size2;
 			size_t  min_size;
 			int  result;
+			check_return(0, avro_value_get_string(val1, &buf1, &size1));
+			check_return(0, avro_value_get_string(val2, &buf2, &size2));
 
 			min_size = (size1 < size2)? size1: size2;
 			result = memcmp(buf1, buf2, min_size);

Modified: avro/trunk/lang/c/tests/CMakeLists.txt
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/CMakeLists.txt?rev=1213898&r1=1213897&r2=1213898&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/CMakeLists.txt (original)
+++ avro/trunk/lang/c/tests/CMakeLists.txt Tue Dec 13 19:54:32 2011
@@ -17,35 +17,31 @@
 # under the License.
 #
 
-add_executable(generate_interop_data generate_interop_data.c)
-target_link_libraries(generate_interop_data avro-static)
-
-add_executable(performance performance.c)
-target_link_libraries(performance avro-static)
-
-add_executable(test_interop_data test_interop_data.c)
-target_link_libraries(test_interop_data avro-static)
-
-add_executable(test_data_structures test_data_structures.c)
-target_link_libraries(test_data_structures avro-static)
-add_test(test_data_structures ${CMAKE_COMMAND} -E chdir ${AvroC_SOURCE_DIR}/tests ${CMAKE_CURRENT_BINARY_DIR}/test_data_structures)
-
-add_executable(test_avro_schema test_avro_schema.c)
-target_link_libraries(test_avro_schema avro-static)
-add_test(test_avro_schema ${CMAKE_COMMAND} -E chdir ${AvroC_SOURCE_DIR}/tests ${CMAKE_CURRENT_BINARY_DIR}/test_avro_schema)
-
-add_executable(test_avro_schema_names test_avro_schema_names.c)
-target_link_libraries(test_avro_schema_names avro-static)
-add_test(test_avro_schema_names ${CMAKE_COMMAND} -E chdir ${AvroC_SOURCE_DIR}/tests ${CMAKE_CURRENT_BINARY_DIR}/test_avro_schema_names)
-
-add_executable(test_avro_values test_avro_values.c)
-target_link_libraries(test_avro_values avro-static)
-add_test(test_avro_values ${CMAKE_COMMAND} -E chdir ${AvroC_SOURCE_DIR}/tests ${CMAKE_CURRENT_BINARY_DIR}/test_avro_values)
-
-add_executable(test_avro_data test_avro_data.c)
-target_link_libraries(test_avro_data avro-static)
-add_test(test_avro_data ${CMAKE_COMMAND} -E chdir ${AvroC_SOURCE_DIR}/tests ${CMAKE_CURRENT_BINARY_DIR}/test_avro_data)
-
-add_executable(test_cpp test_cpp.cpp)
-target_link_libraries(test_cpp avro-static)
-add_test(test_cpp ${CMAKE_COMMAND} -E chdir ${AvroC_SOURCE_DIR}/tests ${CMAKE_CURRENT_BINARY_DIR}/test_cpp)
+macro(add_avro_executable name)
+    set(source "${ARGV1}")
+    if (NOT source)
+        set(source "${name}.c")
+    endif (NOT source)
+    add_executable(${name} ${source})
+    target_link_libraries(${name} avro-static)
+endmacro(add_avro_executable)
+
+macro(add_avro_test name)
+    add_avro_executable(${name} ${ARGN})
+    add_test(${name}
+        ${CMAKE_COMMAND} -E chdir ${AvroC_SOURCE_DIR}/tests
+        ${CMAKE_CURRENT_BINARY_DIR}/${name}
+    )
+endmacro(add_avro_test)
+
+add_avro_executable(generate_interop_data)
+add_avro_executable(performance)
+add_avro_executable(test_interop_data)
+
+add_avro_test(test_data_structures)
+add_avro_test(test_avro_schema)
+add_avro_test(test_avro_schema_names)
+add_avro_test(test_avro_values)
+add_avro_test(test_avro_968)
+add_avro_test(test_avro_data)
+add_avro_test(test_cpp test_cpp.cpp)

Added: 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=1213898&view=auto
==============================================================================
--- avro/trunk/lang/c/tests/test_avro_968.c (added)
+++ avro/trunk/lang/c/tests/test_avro_968.c Tue Dec 13 19:54:32 2011
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License. 
+ */
+
+#include <stdio.h>
+
+#include "avro.h"
+#include "avro_private.h"
+
+#define try(call, msg) \
+	do { \
+		if (call) { \
+			fprintf(stderr, msg ":\n  %s\n", avro_strerror()); \
+			return EXIT_FAILURE; \
+		} \
+	} while (0)
+
+int
+main(int argc, char **argv)
+{
+	AVRO_UNUSED(argc);
+	AVRO_UNUSED(argv);
+
+	avro_value_t  v1;
+	avro_value_t  v2;
+
+	try(avro_generic_string_new(&v1, "test string a"),
+	    "Cannot create string value");
+	try(avro_generic_string_new(&v2, "test string b"),
+	    "Cannot create string value");
+
+	if (avro_value_equal(&v1, &v2)) {
+		fprintf(stderr, "Unexpected avro_value_equal\n");
+		return EXIT_FAILURE;
+	}
+
+	if (avro_value_equal_fast(&v1, &v2)) {
+		fprintf(stderr, "Unexpected avro_value_equal_fast\n");
+		return EXIT_FAILURE;
+	}
+
+	if (avro_value_cmp(&v1, &v2) != -1) {
+		fprintf(stderr, "Unexpected avro_value_cmp\n");
+		return EXIT_FAILURE;
+	}
+
+	if (avro_value_cmp_fast(&v1, &v2) != -1) {
+		fprintf(stderr, "Unexpected avro_value_cmp_fast\n");
+		return EXIT_FAILURE;
+	}
+
+	avro_value_decref(&v1);
+	avro_value_decref(&v2);
+	return 0;
+}



Mime
View raw message