diff options
Diffstat (limited to 'junkcode/dongre.avinash@gmail.com-clibutils/test')
10 files changed, 1208 insertions, 0 deletions
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/Makefile b/junkcode/dongre.avinash@gmail.com-clibutils/test/Makefile new file mode 100644 index 00000000..d2e5cd45 --- /dev/null +++ b/junkcode/dongre.avinash@gmail.com-clibutils/test/Makefile @@ -0,0 +1,22 @@ +P_NAME := tstclibutils +P_C_SRCS := $(wildcard *.c) +P_C_OBJS := ${P_C_SRCS:.c=.o} +P_INCLUDE_DIRS := ../inc +P_LIBRARY_DIRS := ../src +P_LIBRARIES := clibutils +CPPFLAGS += $(foreach includedir,$(P_INCLUDE_DIRS),-I$(includedir)) +LDFLAGS += $(foreach librarydir,$(P_LIBRARY_DIRS),-L$(librarydir)) +LDFLAGS += $(foreach library,$(P_LIBRARIES),-l$(library)) +CC := gcc -Wall -g +CCFLAGS := -Wall -g + +.PHONY: all clean +all: $(P_NAME) +$(P_NAME): $(P_C_OBJS) + $(CC) $(CCFLAGS) $(P_C_OBJS) -o $(P_NAME) $(LDFLAGS) +clean: + @- $(RM) $(P_NAME) + @- $(RM) $(P_C_OBJS) + @- $(RM) core* + @- $(RM) tags + diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_array.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_array.c new file mode 100644 index 00000000..c2f1942b --- /dev/null +++ b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_array.c @@ -0,0 +1,305 @@ +/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
+ * This file is part of clib library
+ * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
+
+#include "c_lib.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+
+static int
+compare_e ( void *left, void *right ) {
+ int *l = (int*) left;
+ int *r = (int*) right;
+ return *l == *r ;
+}
+static void
+free_e ( void *ptr ) {
+ if ( ptr )
+ free ( ptr);
+}
+static void
+print_e ( void *ptr ){
+ if ( ptr )
+ printf ( "%d\n", *(int*)ptr);
+}
+static void
+test_with_int() {
+ int size = 10;
+ int i = 0;
+ int rc ;
+ void* p_rv = (void* )0;
+ int rv = 0;
+ struct clib_array* myArray = new_clib_array (8,compare_e,NULL);
+ assert ( clib_true == empty_clib_array( myArray ));
+
+ for ( i = 0; i <= size; i++) {
+ push_back_clib_array ( myArray, &i ,sizeof(int));
+ }
+ assert ( clib_false == empty_clib_array( myArray ));
+ assert ( size + 1 == size_clib_array( myArray ));
+ for ( i = 0; i <= size; i++) {
+ rc = element_at_clib_array ( myArray, i , &p_rv );
+ rv = *(int*)p_rv;
+ assert ( rv == i );
+ free ( p_rv );
+ }
+ rc = front_clib_array ( myArray, &p_rv );
+ rv = *(int*)p_rv;
+ assert ( rv == 0 );
+ free ( p_rv );
+
+ rc = back_clib_array( myArray, &p_rv );
+ rv = *(int*)p_rv;
+ assert ( rv == size );
+ free ( p_rv );
+
+ remove_clib_array( myArray, 0 );
+ assert ( size == size_clib_array( myArray ));
+ rc = element_at_clib_array ( myArray, 0 , &p_rv );
+ rv = *(int*)p_rv;
+ assert ( rv == 1 );
+ free ( p_rv );
+
+ size = size_clib_array( myArray );
+ remove_clib_array( myArray, size/2 );
+ assert ( size - 1 == size_clib_array( myArray ));
+ rc = element_at_clib_array ( myArray, size/2 , &p_rv );
+ rv = *(int*)p_rv;
+ assert ( rv == size/2 + 2 );
+ free ( p_rv );
+
+ size = size_clib_array( myArray );
+ remove_clib_array( myArray, size - 1);
+ assert ( size - 1 == size_clib_array( myArray ));
+ size = size_clib_array( myArray );
+ rc = element_at_clib_array ( myArray, size - 1, &p_rv );
+ rv = *(int*)p_rv;
+ assert ( rv == 9 );
+ free ( p_rv );
+
+ i = 900;
+ insert_at_clib_array ( myArray, 5, &i, sizeof(int));
+ rc = element_at_clib_array ( myArray, 5 , &p_rv );
+ rv = *(int*)p_rv;
+ assert ( rv == i );
+ free ( p_rv );
+
+ rc = element_at_clib_array ( myArray, 6 , &p_rv );
+ rv = *(int*)p_rv;
+ assert ( rv == 7 );
+ free ( p_rv );
+
+ for ( i = 0; i < size_clib_array(myArray ); i++){
+ rc = element_at_clib_array ( myArray, i , &p_rv );
+ print_e ( p_rv);
+ free ( p_rv );
+
+ }
+ delete_clib_array ( myArray );
+}
+
+static void
+test_with_pointers() {
+ int size = 10;
+ int i = 0;
+ int *rv, rc ;
+ void* p_rv = (void* )0;
+ struct clib_array* myArray = new_clib_array (8,compare_e,free_e);
+ assert ( clib_true == empty_clib_array( myArray ));
+
+ for ( i = 0; i < size; i++) {
+ int *v = ( int*) malloc ( sizeof(int));
+ memcpy ( v, &i, sizeof(int));
+ push_back_clib_array ( myArray, v ,sizeof(int*));
+ free ( v );
+ }
+ assert ( clib_false == empty_clib_array( myArray ));
+ assert ( size == size_clib_array( myArray ));
+ for ( i = 0; i < size; i++) {
+ rc = element_at_clib_array ( myArray, i , &p_rv );
+ rv = (int*) p_rv;
+ assert ( *rv == i );
+ free ( p_rv);
+ }
+ rc = front_clib_array ( myArray, &p_rv );
+ rv = (int*) p_rv;
+ assert ( *rv == 0 );
+ free ( p_rv);
+
+ rc = back_clib_array( myArray, &p_rv );
+ rv = (int*) p_rv;
+ assert ( *rv == size - 1);
+ free ( p_rv);
+
+ remove_clib_array( myArray, 0 );
+ assert ( size - 1 == size_clib_array( myArray ));
+
+ rc = element_at_clib_array ( myArray, 0 , &p_rv );
+ rv = (int*) p_rv;
+ assert ( *rv == 1 );
+ free ( p_rv);
+
+ size = size_clib_array( myArray );
+ remove_clib_array( myArray, size/2 );
+ assert ( size - 1 == size_clib_array( myArray ));
+ rc = element_at_clib_array ( myArray, size/2 , &p_rv );
+ rv = (int*) p_rv;
+ assert ( *rv == size/2 + 2 );
+ free ( p_rv);
+
+ size = size_clib_array( myArray );
+ remove_clib_array( myArray, size - 1);
+ assert ( size - 1 == size_clib_array( myArray ));
+
+ size = size_clib_array( myArray );
+
+ rc = element_at_clib_array ( myArray, size - 1, &p_rv );
+ rv = (int*) p_rv;
+ assert ( *rv == 8 );
+ free ( p_rv);
+
+ delete_clib_array ( myArray );
+}
+
+static void
+test_with_strings() {
+ int size = 10;
+ char *input_array[11];
+ int i = 0;
+ char *rv, rc ;
+ void* p_rv = (void* )0;
+ struct clib_array* myArray = new_clib_array (8,compare_e,free_e);
+ assert ( clib_true == empty_clib_array( myArray ));
+
+ input_array[0] = "STRING_0";
+ input_array[1] = "STRING_1";
+ input_array[2] = "STRING_2";
+ input_array[3] = "STRING_3";
+ input_array[4] = "STRING_4";
+ input_array[5] = "STRING_5";
+ input_array[6] = "STRING_6";
+ input_array[7] = "STRING_7";
+ input_array[8] = "STRING_8";
+ input_array[9] = "STRING_9";
+ input_array[10] = "STRING_10";
+
+
+ for ( i = 0; i < size; i++) {
+ char *v = clib_strdup ( input_array[i]);
+ push_back_clib_array ( myArray ,v, strlen(v) + 1 );
+ free ( v );
+ }
+ assert ( clib_false == empty_clib_array( myArray ));
+ assert ( size == size_clib_array( myArray ));
+ for ( i = 0; i < size; i++) {
+ rc = element_at_clib_array ( myArray, i , &p_rv );
+ rv = (char*)p_rv;
+ assert ( strcmp( rv, input_array[i]) == 0);
+ free ( p_rv );
+ }
+ rc = front_clib_array ( myArray, &p_rv );
+ rv = (char*)p_rv;
+ assert ( strcmp( rv, input_array[0]) == 0);
+ free ( p_rv );
+
+ rc = back_clib_array( myArray, &p_rv );
+ rv = (char*)p_rv;
+ assert ( strcmp( rv, input_array[size - 1]) == 0);
+ free ( p_rv );
+
+ remove_clib_array( myArray, 0 );
+ assert ( size - 1 == size_clib_array( myArray ));
+
+ rc = element_at_clib_array ( myArray, 0 , &p_rv );
+ rv = (char*)p_rv;
+ assert ( strcmp( rv, input_array[1]) == 0);
+ free ( p_rv );
+
+ size = size_clib_array( myArray );
+ remove_clib_array( myArray, size/2 );
+
+ rc = element_at_clib_array ( myArray, size/2 , &p_rv );
+ rv = (char*)p_rv;
+ assert ( strcmp( rv, input_array[size/2 + 2]) == 0);
+ free ( p_rv );
+
+ size = size_clib_array( myArray );
+ remove_clib_array( myArray, size - 1);
+ assert ( size - 1 == size_clib_array( myArray ));
+ size = size_clib_array( myArray );
+
+ rc = element_at_clib_array ( myArray, size - 1, &p_rv );
+ rv = (char*)p_rv;
+ assert ( strcmp( rv, input_array[8]) == 0);
+ free ( p_rv );
+
+ delete_clib_array ( myArray );
+}
+static struct clib_array*
+create_array() {
+ int size = 10;
+ int i = 0;
+ int rc ;
+ void* p_rv = (void* )0;
+ int rv = 0;
+
+ struct clib_array* myArray = new_clib_array (8,compare_e,NULL);
+ assert ( clib_true == empty_clib_array( myArray ));
+
+ for ( i = 0; i < size; i++) {
+ push_back_clib_array ( myArray, &i ,sizeof(int));
+ }
+ assert ( clib_false == empty_clib_array( myArray ));
+ assert ( size == size_clib_array( myArray ));
+ for ( i = 0; i < size; i++) {
+ rc = element_at_clib_array ( myArray, i , &p_rv );
+ rv = *(int*)p_rv;
+ assert ( rv == i );
+ free ( p_rv );
+ }
+ return myArray;
+}
+static void
+test_for_each_array(){
+ struct clib_array* pArray = create_array();
+ struct clib_object *temp;
+ for_each_clib_array( pArray, print_e);
+
+ temp = pArray->pElements[5];
+ pArray->pElements[5] = pArray->pElements[8];
+ pArray->pElements[8] = temp;
+
+ for_each_clib_array( pArray, print_e);
+ delete_clib_array ( pArray );
+
+}
+void
+test_clib_array(){
+ test_with_int();
+ test_with_pointers();
+ test_with_strings();
+ printf ( "---------------------------------\n");
+ test_for_each_array();
+}
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_deque.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_deque.c new file mode 100644 index 00000000..4a27d0c9 --- /dev/null +++ b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_deque.c @@ -0,0 +1,90 @@ +/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
+ * This file is part of clib library
+ * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
+
+#include "c_lib.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+static int
+compare_e ( void *left, void *right ) {
+ int *l = (int*) left;
+ int *r = (int*) right;
+ return *l == *r ;
+}
+static void
+free_e ( void *ptr ) {
+ if ( ptr )
+ free ( ptr);
+}
+void
+test_clib_deque() {
+ int flip = 1;
+ int i = 0;
+ int limit = 20;
+ void* element;
+ int j = 0;
+
+ struct clib_deque* myDeq = new_clib_deque ( 10, compare_e, NULL);
+ assert ( (struct clib_deque*)0 != myDeq );
+
+ for ( i = 0; i <= limit; i++ ) {
+ if ( flip ) {
+ push_back_clib_deque ( myDeq, &i , sizeof(int));
+ flip = 0;
+ } else {
+ push_front_clib_deque ( myDeq, &i, sizeof(int) );
+ flip = 1;
+ }
+ }
+ front_clib_deque ( myDeq, &element );
+ assert ( *(int*)element == limit - 1 );
+ free ( element );
+
+ back_clib_deque ( myDeq, &element );
+ assert ( *(int*)element == limit);
+ free ( element );
+
+ while ( empty_clib_deque(myDeq) != clib_true ) {
+ pop_front_clib_deque ( myDeq);
+ }
+ delete_clib_deque(myDeq);
+
+ myDeq = new_clib_deque ( 10, compare_e, free_e);
+ for ( i = 0; i <= limit; i ++ ) {
+ int *v = (int*)malloc(sizeof(int ));
+ memcpy ( v, &i, sizeof ( int ));
+ push_back_clib_deque ( myDeq, v , sizeof(int*));
+ free ( v );
+ }
+ for ( i = myDeq->head + 1; i < myDeq->tail; i++ ){
+ void *elem;
+ if ( element_at_clib_deque( myDeq, i, &elem ) == CLIB_ERROR_SUCCESS ) {
+ assert ( *(int*)elem == j++ );
+ free ( elem );
+ }
+ }
+ delete_clib_deque(myDeq);
+}
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_heap.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_heap.c new file mode 100644 index 00000000..d15a839a --- /dev/null +++ b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_heap.c @@ -0,0 +1,95 @@ +/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
+ * This file is part of clib library
+ * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
+
+#include "c_lib.h"
+#include <stdio.h>
+
+static int
+compare_int ( void *left, void *right ) {
+ int *l = (int*)left;
+ int *r = (int*)right;
+
+ if ( *l < *r )
+ return -1;
+ else if ( *l > *r )
+ return 1;
+ return 0;
+}
+static void
+print_element ( void *ptr ) {
+ printf ( "%d\n", *(int*)ptr);
+}
+void
+test_clib_heap_max() {
+ int test[] = {4,1,3,2,16,9,10,14,8,7};
+ int index = 0;
+ int size = sizeof (test) /sizeof(test[0]);
+ void *maxElem;
+ struct clib_heap* pHeap = new_clib_heap ( 8, compare_int, NULL);
+
+ for ( index = 0; index < size; index++ ) {
+ int v = test[index];
+ insert_clib_heap ( pHeap, &v, sizeof(int));
+ }
+ build_max_clib_heap( pHeap);
+ printf ( "---------------------------------\n");
+ for_each_clib_heap ( pHeap, print_element);
+ printf ( "---------------------------------\n");
+ while ( empty_clib_heap(pHeap) != clib_true ) {
+ maxElem = extract_max_clib_heap ( pHeap );
+ printf ( "MAX ELEMENT = %d\n", *(int*)maxElem);
+ free ( maxElem );
+ }
+ delete_clib_heap ( pHeap );
+}
+
+void
+test_clib_heap_min() {
+ int test[] = {4,1,3,2,16,9,10,14,8,7};
+ int index = 0;
+ int size = sizeof (test) /sizeof(test[0]);
+ void *maxElem;
+ struct clib_heap* pHeap = new_clib_heap ( 8, compare_int, NULL);
+
+ for ( index = 0; index < size; index++ ) {
+ int v = test[index];
+ insert_clib_heap ( pHeap, &v, sizeof(int));
+ }
+ build_min_clib_heap( pHeap);
+ printf ( "---------------------------------\n");
+ for_each_clib_heap ( pHeap, print_element);
+ printf ( "---------------------------------\n");
+ while ( empty_clib_heap(pHeap) != clib_true ) {
+ maxElem = extract_min_clib_heap ( pHeap );
+ printf ( "MIN ELEMENT = %d\n", *(int*)maxElem);
+ free ( maxElem );
+ }
+ delete_clib_heap ( pHeap );
+
+}
+
+void
+test_clib_heap() {
+ test_clib_heap_max();
+ test_clib_heap_min();
+}
\ No newline at end of file diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_map.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_map.c new file mode 100644 index 00000000..5305b45f --- /dev/null +++ b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_map.c @@ -0,0 +1,113 @@ +/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
+ * This file is part of clib library
+ * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
+
+#include "c_lib.h"
+#include <string.h>
+#include <assert.h>
+#include <stdio.h>
+
+static int
+compare_e ( void *left, void *right ) {
+ return strcmp ( (const char *)left, (const char *) right );
+}
+char *char_value[] = { "A","B","C","D","E","F","G","H","I","J","K","L","M",
+ "N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
+int int_value[] = { 1,2,3,4,5,6,7,8,9,10,
+ 11,12,13,14,15,16,17,18,19,20,
+ 21,22,23,24,25,26};
+
+static void
+insert_all ( struct clib_map* myMap) {
+ int size = sizeof(char_value)/sizeof(char_value[0]);
+ int i = 0;
+ for ( i = 0; i < size; i++ ) {
+ char *key = clib_strdup( char_value[i]);
+ int key_length = (int)strlen ( key ) + 1;
+ int value = int_value[i];
+ printf ( "Inserting [%s -> %d]\n", key, value );
+ insert_clib_map ( myMap, key, key_length, &value, sizeof(int));
+ free ( key );
+ }
+}
+static void
+check_exists_all( struct clib_map* myMap) {
+ int size = sizeof(char_value)/sizeof(char_value[0]);
+ int i = 0;
+ for ( i = 0; i < size; i++ ) {
+ void *value ;
+ assert ( clib_true == exists_clib_map ( myMap, char_value[i]));
+ assert ( clib_true == find_clib_map( myMap, char_value[i], &value));
+ printf ( "-----> [%s == %d]\n", char_value[i], *(int*)value);
+ assert ( *(int*)value == int_value[i]);
+ free ( value );
+ }
+}
+
+static void
+remove_some_exist(struct clib_map* myMap) {
+ assert ( CLIB_ERROR_SUCCESS == remove_clib_map ( myMap, "A"));
+ assert ( clib_false == exists_clib_map ( myMap, "A"));
+
+ assert ( CLIB_ERROR_SUCCESS == remove_clib_map ( myMap, "X"));
+ assert ( clib_false == exists_clib_map ( myMap, "X"));
+
+ assert ( CLIB_ERROR_SUCCESS == remove_clib_map ( myMap, "Z"));
+ assert ( clib_false == exists_clib_map ( myMap, "Z"));
+
+ assert ( CLIB_ERROR_SUCCESS == remove_clib_map ( myMap, "H"));
+ assert ( clib_false == exists_clib_map ( myMap, "H"));
+}
+static void
+add_removed_check_all(struct clib_map* myMap) {
+
+ char *key = clib_strdup ("A");
+ int key_length = (int)strlen ( key ) + 1;
+ insert_clib_map ( myMap, key, key_length , &int_value[0], sizeof(int));
+ free ( key );
+
+ key = clib_strdup ("X");
+ key_length = (int)strlen ( key ) + 1;
+ insert_clib_map ( myMap, key, key_length, &int_value[23], sizeof(int));
+ free ( key );
+
+ key = clib_strdup ("Z");
+ key_length = (int)strlen ( key ) + 1;
+ insert_clib_map ( myMap, key, key_length, &int_value[25], sizeof(int));
+ free ( key );
+
+ key = clib_strdup ("H");
+ key_length = (int)strlen ( key ) + 1;
+ insert_clib_map ( myMap, key, key_length, &int_value[7 ], sizeof(int));
+ free ( key );
+
+ check_exists_all(myMap);
+}
+void
+test_clib_map() {
+ struct clib_map* myMap = new_clib_map ( compare_e, NULL, NULL);
+ insert_all(myMap);
+ check_exists_all(myMap);
+ remove_some_exist(myMap);
+ add_removed_check_all(myMap);
+ delete_clib_map(myMap);
+}
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_rb.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_rb.c new file mode 100644 index 00000000..1a318ac5 --- /dev/null +++ b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_rb.c @@ -0,0 +1,255 @@ +/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
+ * This file is part of clib library
+ * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
+
+#include "c_lib.h"
+
+/*#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#define BLACK 0
+#define RED 1
+
+#define rb_sentinel &tree->sentinel
+
+static void*
+ get_key ( struct clib_rb* tree, struct clib_rb_node* node) {
+ if ( node )
+ return node->raw_data.key;
+ return (void*)0;
+ }
+
+static struct clib_rb_node*
+ get_left (struct clib_rb* tree, struct clib_rb_node* node ) {
+ if ( node->left != rb_sentinel && node->left != (struct clib_rb_node*)0 )
+ return node->left;
+ return (struct clib_rb_node*)0 ;
+ }
+static struct clib_rb_node*
+ get_right (struct clib_rb* tree, struct clib_rb_node* node ){
+ if ( node->right != rb_sentinel && node->right != (struct clib_rb_node*)0 )
+ return node->right;
+ return (struct clib_rb_node*)0 ;
+ }
+static struct clib_rb_node*
+ get_parent ( struct clib_rb* tree,struct clib_rb_node* node ) {
+ if ( node->parent != rb_sentinel && node->parent != (struct clib_rb_node*)0 )
+ return node->parent;
+ return (struct clib_rb_node*)0 ;
+ }
+
+int
+compare_rb_e ( void* l, void* r ) {
+
+ int left = 0;
+ int right = 0;
+
+ if ( l ) left = *(int*)l;
+ if ( r ) right = *(int*)r;
+
+ if ( left < right ) return -1;
+ if ( left == right ) return 0;
+
+ return 1;
+}
+
+void
+free_rb_e ( void* p ) {
+ if ( p ) {
+ free ( p );
+ }
+}
+
+typedef struct test_data_tree {
+ int element;
+ int left;
+ int right;
+ int parent;
+ int color;
+} TS;
+
+
+static struct clib_rb_node*
+pvt_find_clib_rb ( struct clib_rb* tree, clib_compare fn_c, void *key ) {
+ struct clib_rb_node* node = tree->root;
+ void* current_key = (void*)0;
+ int compare_result = 0;
+
+ current_key = (void*)malloc ( tree->size_of_key);
+ memcpy ( current_key, key, tree->size_of_key);
+
+ compare_result = (fn_c)(current_key, node->raw_data.key);
+ while ((node != rb_sentinel) && (compare_result = (fn_c)(current_key, node->raw_data.key)) != 0 ){
+ if ( compare_result < 0 ) {
+ node = node->left;
+ } else {
+ node = node->right;
+ }
+ }
+ free ( current_key );
+ return node;
+}
+struct clib_rb_node*
+find(struct clib_rb* tree, void *key ) {
+ return pvt_find_clib_rb ( tree, tree->compare_fn, key );
+}
+
+static void update_values ( void* v, int *l, int *r, int *p , int *e, struct clib_rb* tree ) {
+ struct clib_rb_node *x;
+ if ( get_key(tree,v))
+ *e = *(int*)get_key (tree,v);
+ x = get_left(tree,v);
+ if ( x )
+ *l = *(int*)get_key(tree,x);
+ x = get_right(tree,v);
+ if (x)
+ *r = *(int*)get_key(tree,x);
+ x = get_parent ( tree, v );
+ if (x)
+ *p = *(int*)get_key(tree,x);
+}
+
+static void
+test_each_elements(int l,int r, int p, int e,void* v, TS ts[], int i,
+ struct clib_rb* tree) {
+ assert ( ts[i].element == e);
+ if (ts[i].left != 0 )
+ assert ( ts[i].left == l);
+ else
+ assert ((void* )0 == (void* )get_key(tree,get_left(tree,v)));
+ if ( ts[i].right != 0 )
+ assert (ts[i].right == r);
+ else
+ assert ((void* )0 == (void* )get_key(tree,get_right(tree,v)));
+ if (ts[i].parent != 0 )
+ assert (ts[i].parent == p);
+ else
+ assert ((void* )0 == (void* )get_key(tree,get_parent(tree,v)));
+}
+
+static void
+test_all_elements(struct clib_rb* tree, TS ts[], int size) {
+ int i = 0;
+ for ( i = 0; i < size; i++) {
+ void* v = (void*)0;
+ int l,r,p,e;
+ v = find ( tree, &ts[i].element);
+ update_values( v, &l,&r,&p,&e, tree);
+ test_each_elements(l,r,p,e,v, ts, i, tree);
+ }
+}
+
+static struct clib_rb*
+create_tree(TS ts[], int size) {
+ int i = 0;
+ struct clib_rb* tree = new_clib_rb( compare_rb_e,free_rb_e, (void*)0, sizeof(int),0);
+ for ( i = 0; i < size; i++) {
+ insert_clib_rb( tree, &(ts[i].element) ,(void*)0);
+ }
+ return tree;
+}
+
+
+void
+test_clib_rb() {
+ int size;
+ int size_after_delete;
+ int i = 0;
+ struct clib_rb* tree;
+ struct clib_rb_node* node;
+
+ TS ts[] = {
+ {15,6,18,0,BLACK},{6,3,9,15,RED},{18,17,20,15,BLACK},
+ {3,2,4,6,BLACK},{7,0,0,9,RED},{17,0,0,18,RED},
+ {20,0,0,18,RED},{2,0,0,3,RED},{4,0,0,3,RED},{13,0,0,9,RED},
+ {9,7,13,6,BLACK}
+ };
+ TS ts_delete_leaf_13[] = {
+ {15,6,18,0,BLACK},{6,3,9,15,RED},{18,17,20,15,BLACK},
+ {3,2,4,6,BLACK},{7,0,0,9,RED},{17,0,0,18,RED},
+ {20,0,0,18,RED},{2,0,0,3,RED},{4,0,0,3,RED},
+ {9,7,0,6,BLACK}
+ };
+ TS ts_delete_9[] = {
+ {15,6,18,0,BLACK},{6,3,7,15,RED},{18,17,20,15,BLACK},
+ {3,2,4,6,RED},{7,0,0,6,RED},{17,0,0,18,RED},
+ {20,0,0,18,RED},{2,0,0,3,RED},{4,0,0,3,RED}
+ };
+ TS ts_delete_15[] = {
+ {6,3,7,17,RED},{18,0,20,17,BLACK},
+ {3,2,4,6,RED},{7,0,0,6,RED},{17,6,18,0,RED},
+ {20,0,0,18,RED},{2,0,0,3,RED},{4,0,0,3,RED}
+ };
+ TS ts_insert_1[] = {
+ {6,3,17,0,BLACK},{18,0,20,17,BLACK},
+ {3,2,4,6,RED},{7,0,0,17,RED},{17,7,18,6,RED},
+ {20,0,0,18,RED},{2,1,0,3,BLACK},{4,0,0,3,BLACK},
+ {1,0,0,2,RED}
+ };
+
+
+ size = (sizeof(ts)/sizeof(TS));
+ tree = create_tree(ts,size);
+ test_all_elements(tree, ts, size);
+ {
+ i = 13;
+ size = (sizeof(ts)/sizeof(TS));
+ size_after_delete = (sizeof(ts_delete_leaf_13)/sizeof(TS));
+ node = remove_clib_rb( tree, &i);
+ if ( node != (struct clib_rb_node*)0 ) {
+ free ( node->raw_data.key);
+ free ( node);
+ }
+ test_all_elements(tree, ts_delete_leaf_13, size_after_delete);
+ }
+ {
+ i = 9;
+ size_after_delete = (sizeof(ts_delete_9)/sizeof(TS));
+ node = remove_clib_rb( tree, &i);
+ if ( node != (struct clib_rb_node*)0 ) {
+ free ( node->raw_data.key);
+ free ( node);
+ }
+ test_all_elements(tree, ts_delete_9, size_after_delete);
+ }
+ {
+ i = 15;
+ size_after_delete = (sizeof(ts_delete_15)/sizeof(TS));
+ node = remove_clib_rb( tree, &i);
+ if ( node != (struct clib_rb_node*)0 ) {
+ free ( node->raw_data.key);
+ free ( node);
+ }
+ test_all_elements(tree, ts_delete_15, size_after_delete);
+ }
+ {
+ int i = 1;
+ insert_clib_rb( tree, &i, (void*)0);
+ size_after_delete = (sizeof(ts_insert_1)/sizeof(TS));
+ test_all_elements(tree, ts_insert_1, size_after_delete);
+ }
+ {
+ delete_clib_rb(tree);
+ }
+}*/
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_set.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_set.c new file mode 100644 index 00000000..3efea3ea --- /dev/null +++ b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_set.c @@ -0,0 +1,111 @@ +/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
+ * This file is part of clib library
+ * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
+
+#include "c_lib.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+
+static void
+delete_e ( void *ptr ) {
+ if ( ptr )
+ free ( ptr );
+}
+static int
+compare_e ( void *left, void *right ) {
+ char *l = (char*)left;
+ char *r = (char*)right;
+ return strcmp ( (const char *)l, (const char *) r );
+}
+static int
+compare_int ( void *left, void *right ) {
+ int *l = (int*)left;
+ int *r = (int*)right;
+
+ if ( *l < *r )
+ return -1;
+ else if ( *l > *r )
+ return 1;
+ return 0;
+}
+void
+test_clib_set(){
+ {
+ int test[] = { 0,1,2,3,4,5,6,7,8,9 };
+ int index = 0;
+ int size = sizeof (test) /sizeof(test[0]);
+ void* outKey;
+
+ struct clib_set *pSet = new_clib_set ( compare_int, NULL);
+
+ for ( index = 0; index < size; index++ ) {
+ int v = test[index];
+ insert_clib_set ( pSet, &v, sizeof(int));
+ }
+ for ( index = 0; index < size; index++ ) {
+ int v = test[index];
+ assert ( clib_true == exists_clib_set ( pSet, &v));
+ }
+
+ index = 9;
+ find_clib_set ( pSet, &index, &outKey);
+ assert ( 9 == *(int*)outKey);
+ free ( outKey );
+ delete_clib_set(pSet);
+ }
+ {
+ typedef struct test {
+ char *string;
+ } TEST_INPUT;
+
+ int index = 0;
+ int size = 0;
+ char *v;
+
+ TEST_INPUT ti[] ={
+ {"A for APPLE"},{"B for BALL"},{"C for CAT"}, {"D for DOG"},
+ {"E for ELEPHANT"},{"F for FISH"},{"G for GOAT"},
+ {"H for HORSE"},{"I for ICECREAM"},{"J for JOKER"},
+ {"K for KITE"},{"L for LAMB"},{"M for MONKEY"},
+ {"N for NEST"},{"O for ORANGE"},{"P for POT"},
+ {"Q for QUEEN"},{"R for RAT"},{"S for SHEEP"},
+ {"T for TABLE"},{"U for UMBRELLA"},{"V for VIOLIN"},{"W for WAX"},
+ {"X for XEROX"},{"Y for YUMMY"},{"Z for ZEBRA"}
+ };
+ struct clib_set *pSet = new_clib_set ( compare_e, delete_e);
+ size = sizeof ( ti ) / sizeof ( ti[0]);
+
+ for ( index = 0; index < size; index++ ){
+ char *temp = clib_strdup ( ti[index].string );
+ insert_clib_set ( pSet, temp, strlen(temp) + 1 );
+ free ( temp );
+ }
+ for ( index = 0; index < size; index++ ){
+ v = ti[index].string;
+ assert ( clib_true == exists_clib_set ( pSet, v));
+ }
+ delete_clib_set(pSet);
+ }
+}
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_slist.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_slist.c new file mode 100644 index 00000000..7c8337ca --- /dev/null +++ b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_slist.c @@ -0,0 +1,121 @@ +/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
+ * This file is part of clib library
+ * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
+
+#include "c_lib.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+
+static void
+free_element ( void *ptr ) {
+ if ( ptr )
+ free ( ptr);
+}
+
+void
+add_elements_to_list( struct clib_slist* ll, int x, int y ) {
+ int i = 0;
+ for ( i = x; i <= y; i++ ) {
+ int *v = ( int *) malloc ( sizeof ( int ));
+ memcpy ( v, &i, sizeof ( int ));
+ push_back_clib_slist ( ll, v , sizeof(v));
+ free ( v );
+ }
+}
+void
+print_e ( void *ptr ) {
+ if ( ptr )
+ printf ( "%d\n", *(int*)ptr);
+}
+
+static int
+compare_element ( void *left, void *right ) {
+ int *l = (int*) left;
+ int *r = (int*) right;
+ return *l == *r ;
+}
+
+
+void
+test_clib_slist() {
+ int i = 0;
+ int *v;
+ void* outValue;
+ struct clib_slist* list = new_clib_slist(free_element,compare_element);
+
+ add_elements_to_list(list,1, 10 );
+ for_each_clib_slist(list, print_e);
+
+ i = 55;
+ v = ( int *) malloc ( sizeof ( int ));
+ memcpy ( v, &i, sizeof ( int ));
+ insert_clib_slist(list,5, v,sizeof(v));
+ free ( v );
+ for_each_clib_slist(list, print_e);
+
+ remove_clib_slist(list,5);
+ for_each_clib_slist(list, print_e);
+
+ remove_clib_slist(list,0);
+ for_each_clib_slist(list, print_e);
+
+ remove_clib_slist(list,100);
+ for_each_clib_slist(list, print_e);
+
+ i = 1;
+ v = ( int *) malloc ( sizeof ( int ));
+ memcpy ( v, &i, sizeof ( int ));
+ insert_clib_slist(list,1,v,sizeof(v));
+ free ( v );
+ for_each_clib_slist(list, print_e);
+
+ i = 11;
+ v = ( int *) malloc ( sizeof ( int ));
+ memcpy ( v, &i, sizeof ( int ));
+ insert_clib_slist(list,11,v,sizeof(v));
+ free ( v );
+ for_each_clib_slist(list, print_e);
+
+ i = 12;
+ v = ( int *) malloc ( sizeof ( int ));
+ memcpy ( v, &i, sizeof ( int ));
+ insert_clib_slist(list,200,v,sizeof(v));
+ free ( v );
+ for_each_clib_slist(list, print_e);
+
+ remove_clib_slist(list,list->size);
+ for_each_clib_slist(list, print_e);
+
+ i = 10;
+ if ( clib_true == find_clib_slist ( list, &i, &outValue)) {
+ assert ( i == *(int*)outValue );
+ free ( outValue );
+ }
+ i = 100;
+ assert ( clib_false == find_clib_slist ( list, &i, &outValue));
+
+ delete_clib_slist ( list );
+
+}
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_stack.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_stack.c new file mode 100644 index 00000000..177999d9 --- /dev/null +++ b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_stack.c @@ -0,0 +1,42 @@ +/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
+ * This file is part of clib library
+ * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
+#include "c_lib.h"
+#include <assert.h>
+
+void
+test_clib_stack() {
+ struct clib_stack *pStack = new_clib_stack( 10, NULL );
+ int i = 0;
+ int size = 10;
+ for ( i = 0; i < size; i++) {
+ push_clib_stack ( pStack, &i, sizeof(i));
+ }
+ size = size - 1;
+ while ( ! empty_clib_stack(pStack)) {
+ void *elem;
+ pop_clib_stack( pStack, &elem);
+ assert ( size-- == *(int*)elem);
+ free ( elem );
+ }
+ delete_clib_stack ( pStack );
+}
\ No newline at end of file diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_clibutils.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_clibutils.c new file mode 100644 index 00000000..54161a5e --- /dev/null +++ b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_clibutils.c @@ -0,0 +1,54 @@ +/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
+ * This file is part of clib library
+ * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
+
+#include <stdio.h>
+extern void test_clib_array();
+extern void test_clib_deque();
+extern void test_clib_tree();
+extern void test_clib_rb();
+extern void test_clib_set();
+extern void test_clib_map();
+extern void test_clib_slist();
+extern void test_clib_map();
+extern void test_clib_stack();
+extern void test_clib_heap();
+
+int main( int argc, char**argv ) {
+ printf ( "Performing test for dynamic array\n");
+ test_clib_array();
+ printf ( "Performing test for deque\n");
+ test_clib_deque();
+ printf ( "Performing test for sets\n");
+ test_clib_set();
+ printf ( "Performing test for map\n");
+ test_clib_map();
+ printf ( "Performing test for slist\n");
+ test_clib_slist();
+ printf ( "Performing test for stackn");
+ test_clib_stack();
+ printf ( "Performing test for heap\n");
+ test_clib_heap();
+
+
+ return 0;
+}
|