1 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
\r
2 * This file is part of clib library
\r
3 * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
6 * of this software and associated documentation files (the "Software"), to deal
\r
7 * in the Software without restriction, including without limitation the rights
\r
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
9 * copies of the Software, and to permit persons to whom the Software is
\r
10 * furnished to do so, subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in
\r
13 * all copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
22 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
\r
30 compare_e ( void *left, void *right ) {
\r
31 return strcmp ( (const char *)left, (const char *) right );
\r
33 char *char_value[] = { "A","B","C","D","E","F","G","H","I","J","K","L","M",
\r
34 "N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
\r
35 int int_value[] = { 1,2,3,4,5,6,7,8,9,10,
\r
36 11,12,13,14,15,16,17,18,19,20,
\r
40 insert_all ( struct clib_map* myMap) {
\r
41 int size = sizeof(char_value)/sizeof(char_value[0]);
\r
43 for ( i = 0; i < size; i++ ) {
\r
44 char *key = clib_strdup( char_value[i]);
\r
45 int key_length = (int)strlen ( key ) + 1;
\r
46 int value = int_value[i];
\r
47 printf ( "Inserting [%s -> %d]\n", key, value );
\r
48 insert_clib_map ( myMap, key, key_length, &value, sizeof(int));
\r
53 check_exists_all( struct clib_map* myMap) {
\r
54 int size = sizeof(char_value)/sizeof(char_value[0]);
\r
56 for ( i = 0; i < size; i++ ) {
\r
58 assert ( clib_true == exists_clib_map ( myMap, char_value[i]));
\r
59 assert ( clib_true == find_clib_map( myMap, char_value[i], &value));
\r
60 printf ( "-----> [%s == %d]\n", char_value[i], *(int*)value);
\r
61 assert ( *(int*)value == int_value[i]);
\r
67 remove_some_exist(struct clib_map* myMap) {
\r
68 assert ( CLIB_ERROR_SUCCESS == remove_clib_map ( myMap, "A"));
\r
69 assert ( clib_false == exists_clib_map ( myMap, "A"));
\r
71 assert ( CLIB_ERROR_SUCCESS == remove_clib_map ( myMap, "X"));
\r
72 assert ( clib_false == exists_clib_map ( myMap, "X"));
\r
74 assert ( CLIB_ERROR_SUCCESS == remove_clib_map ( myMap, "Z"));
\r
75 assert ( clib_false == exists_clib_map ( myMap, "Z"));
\r
77 assert ( CLIB_ERROR_SUCCESS == remove_clib_map ( myMap, "H"));
\r
78 assert ( clib_false == exists_clib_map ( myMap, "H"));
\r
81 add_removed_check_all(struct clib_map* myMap) {
\r
83 char *key = clib_strdup ("A");
\r
84 int key_length = (int)strlen ( key ) + 1;
\r
85 insert_clib_map ( myMap, key, key_length , &int_value[0], sizeof(int));
\r
88 key = clib_strdup ("X");
\r
89 key_length = (int)strlen ( key ) + 1;
\r
90 insert_clib_map ( myMap, key, key_length, &int_value[23], sizeof(int));
\r
93 key = clib_strdup ("Z");
\r
94 key_length = (int)strlen ( key ) + 1;
\r
95 insert_clib_map ( myMap, key, key_length, &int_value[25], sizeof(int));
\r
98 key = clib_strdup ("H");
\r
99 key_length = (int)strlen ( key ) + 1;
\r
100 insert_clib_map ( myMap, key, key_length, &int_value[7 ], sizeof(int));
\r
103 check_exists_all(myMap);
\r
107 struct clib_map* myMap = new_clib_map ( compare_e, NULL, NULL);
\r
109 check_exists_all(myMap);
\r
110 remove_some_exist(myMap);
\r
111 add_removed_check_all(myMap);
\r
112 delete_clib_map(myMap);
\r