2 * Copyright 2008 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include "key_value.h"
24 static KeyValue key_values[] = {
31 static void create_key_values(void **state) {
32 KeyValue * const items = (KeyValue*)test_malloc(sizeof(key_values));
33 memcpy(items, key_values, sizeof(key_values));
34 *state = (void*)items;
35 set_key_values(items, sizeof(key_values) / sizeof(key_values[0]));
38 static void destroy_key_values(void **state) {
40 set_key_values(NULL, 0);
43 static void test_find_item_by_value(void **state) {
46 (void) state; /* unused */
48 for (i = 0; i < sizeof(key_values) / sizeof(key_values[0]); i++) {
49 KeyValue * const found = find_item_by_value(key_values[i].value);
50 assert_true(found != NULL);
51 assert_int_equal(found->key, key_values[i].key);
52 assert_string_equal(found->value, key_values[i].value);
56 static void test_sort_items_by_key(void **state) {
58 KeyValue * const kv = *state;
60 for (i = 1; i < sizeof(key_values) / sizeof(key_values[0]); i++) {
61 assert_true(kv[i - 1].key < kv[i].key);
66 const UnitTest tests[] = {
67 unit_test_setup_teardown(test_find_item_by_value, create_key_values,
69 unit_test_setup_teardown(test_sort_items_by_key, create_key_values,
72 return run_tests(tests);