example: Fix build warnings of key_value.
authorAndreas Schneider <asn@cryptomilk.org>
Tue, 31 May 2011 19:57:55 +0000 (21:57 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 31 May 2011 19:58:27 +0000 (21:58 +0200)
src/example/key_value.c
src/example/key_value.h [new file with mode: 0644]
src/example/key_value_test.c

index a368a16..46f0d25 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-typedef struct KeyValue {
-    unsigned int key;
-    const char* value;
-} KeyValue;
+#include "key_value.h"
 
 static KeyValue *key_values = NULL;
 static unsigned int number_of_key_values = 0;
@@ -32,7 +29,7 @@ void set_key_values(KeyValue * const new_key_values,
 }
 
 // Compare two key members of KeyValue structures.
-int key_value_compare_keys(const void *a, const void *b) {
+static int key_value_compare_keys(const void *a, const void *b) {
     return (int)((KeyValue*)a)->key - (int)((KeyValue*)b)->key;
 }
 
@@ -48,7 +45,7 @@ KeyValue* find_item_by_value(const char * const value) {
 }
 
 // Sort an array of key value pairs by key.
-void sort_items_by_key() {
+void sort_items_by_key(void) {
     qsort(key_values, number_of_key_values, sizeof(*key_values),
           key_value_compare_keys);
 }
diff --git a/src/example/key_value.h b/src/example/key_value.h
new file mode 100644 (file)
index 0000000..736faf2
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2008 Google Inc.
+ *
+ * Licensed 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.
+ */
+
+typedef struct KeyValue {
+    unsigned int key;
+    const char* value;
+} KeyValue;
+
+void set_key_values(KeyValue * const new_key_values,
+                    const unsigned int new_number_of_key_values);
+
+KeyValue* find_item_by_value(const char * const value);
+
+void sort_items_by_key(void);
index edd44f6..0ec632a 100644 (file)
 #include <string.h>
 #include <cmockery.h>
 
-/* This is duplicated here from the module setup_teardown.c to reduce the
- * number of files used in this test. */
-typedef struct KeyValue {
-    unsigned int key;
-    const char* value;
-} KeyValue;
-
-void set_key_values(KeyValue * const new_key_values,
-                    const unsigned int new_number_of_key_values);
-extern KeyValue* find_item_by_value(const char * const value);
-extern void sort_items_by_key();
+#include "key_value.h"
 
 static KeyValue key_values[] = {
     { 10, "this" },
@@ -38,29 +28,29 @@ static KeyValue key_values[] = {
     { 13, "is" },
 };
 
-void create_key_values(void **state) {
+static void create_key_values(void **state) {
     KeyValue * const items = (KeyValue*)test_malloc(sizeof(key_values));
     memcpy(items, key_values, sizeof(key_values));
     *state = (void*)items;
     set_key_values(items, sizeof(key_values) / sizeof(key_values[0]));
 }
 
-void destroy_key_values(void **state) {
+static void destroy_key_values(void **state) {
     test_free(*state);
     set_key_values(NULL, 0);
 }
 
-void test_find_item_by_value(void **state) {
+static void test_find_item_by_value(void **state) {
     unsigned int i;
     for (i = 0; i < sizeof(key_values) / sizeof(key_values[0]); i++) {
         KeyValue * const found  = find_item_by_value(key_values[i].value);
-        assert_true(found);
+        assert_true(found != NULL);
         assert_int_equal(found->key, key_values[i].key);
         assert_string_equal(found->value, key_values[i].value);
     }
 }
 
-void test_sort_items_by_key(void **state) {
+static void test_sort_items_by_key(void **state) {
     unsigned int i;
     KeyValue * const kv = *state;
     sort_items_by_key();
@@ -69,7 +59,7 @@ void test_sort_items_by_key(void **state) {
     }
 }
 
-int main(int argc, char* argv[]) {
+int main(void) {
     const UnitTest tests[] = {
         unit_test_setup_teardown(test_find_item_by_value, create_key_values,
                                  destroy_key_values),