diff options
Diffstat (limited to 'tinySAK/test')
-rwxr-xr-x | tinySAK/test/stdafx.c | 6 | ||||
-rwxr-xr-x | tinySAK/test/stdafx.h | 6 | ||||
-rwxr-xr-x | tinySAK/test/targetver.h | 4 | ||||
-rwxr-xr-x | tinySAK/test/test.c | 159 | ||||
-rwxr-xr-x | tinySAK/test/test_base64.h | 162 | ||||
-rwxr-xr-x | tinySAK/test/test_buffer.h | 28 | ||||
-rwxr-xr-x | tinySAK/test/test_condwait.h | 64 | ||||
-rwxr-xr-x | tinySAK/test/test_fsm.h | 331 | ||||
-rwxr-xr-x | tinySAK/test/test_heap.h | 80 | ||||
-rwxr-xr-x | tinySAK/test/test_lists.h | 372 | ||||
-rwxr-xr-x | tinySAK/test/test_md5.h | 112 | ||||
-rwxr-xr-x | tinySAK/test/test_mutex.h | 58 | ||||
-rwxr-xr-x | tinySAK/test/test_object.h | 123 | ||||
-rwxr-xr-x | tinySAK/test/test_options.h | 59 | ||||
-rwxr-xr-x | tinySAK/test/test_params.h | 68 | ||||
-rwxr-xr-x | tinySAK/test/test_runnable.h | 153 | ||||
-rwxr-xr-x | tinySAK/test/test_safeobject.h | 77 | ||||
-rwxr-xr-x | tinySAK/test/test_semaphore.h | 56 | ||||
-rwxr-xr-x | tinySAK/test/test_sha1.h | 106 | ||||
-rwxr-xr-x | tinySAK/test/test_strings.h | 76 | ||||
-rwxr-xr-x | tinySAK/test/test_threads.h | 26 | ||||
-rwxr-xr-x | tinySAK/test/test_timer.h | 110 | ||||
-rwxr-xr-x | tinySAK/test/test_url.h | 26 | ||||
-rwxr-xr-x | tinySAK/test/test_uuid.h | 12 |
24 files changed, 1117 insertions, 1157 deletions
diff --git a/tinySAK/test/stdafx.c b/tinySAK/test/stdafx.c index a98e092..938920a 100755 --- a/tinySAK/test/stdafx.c +++ b/tinySAK/test/stdafx.c @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * diff --git a/tinySAK/test/stdafx.h b/tinySAK/test/stdafx.h index 9b3fd7e..3112592 100755 --- a/tinySAK/test/stdafx.h +++ b/tinySAK/test/stdafx.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * diff --git a/tinySAK/test/targetver.h b/tinySAK/test/targetver.h index c205b20..c868b68 100755 --- a/tinySAK/test/targetver.h +++ b/tinySAK/test/targetver.h @@ -3,8 +3,8 @@ #if (defined(_WIN32) || defined(WIN32) || defined(_WIN32_WCE)) && !defined(__SYMBIAN32__) // The following macros define the minimum required platform. The minimum required platform -// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run -// your application. The macros work by enabling all features available on platform versions up to and +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and // including the version specified. // Modify the following defines if you have to target a platform prior to the ones specified below. diff --git a/tinySAK/test/test.c b/tinySAK/test/test.c index 0e77cc7..5f40941 100755 --- a/tinySAK/test/test.c +++ b/tinySAK/test/test.c @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -142,148 +142,147 @@ int _tmain(int argc, _TCHAR* argv[]) int main() #endif { - do - { - int y, x; + do { + int y, x; - for(y = 0; y < 16; ++y){ - printf("{"); - for(x = 0; x < 16; ++x){ - printf("%d, ", (2 * ( y / 8 ) + ( x / 8 ))); - } - printf("}\n"); - } + for(y = 0; y < 16; ++y) { + printf("{"); + for(x = 0; x < 16; ++x) { + printf("%d, ", (2 * ( y / 8 ) + ( x / 8 ))); + } + printf("}\n"); + } - /* Print copyright information */ - printf("Doubango Project\nCopyright (C) 2009 Mamadou Diop \n\n"); + /* Print copyright information */ + printf("Doubango Project\nCopyright (C) 2009 Mamadou Diop \n\n"); #if RUN_TEST_LISTS || RUN_TEST_ALL - /* linked lists */ - test_basic_list(); - printf("\n\n"); - test_complex_list(); - printf("\n\n"); - test_filtered_list(); - printf("\n\n"); + /* linked lists */ + test_basic_list(); + printf("\n\n"); + test_complex_list(); + printf("\n\n"); + test_filtered_list(); + printf("\n\n"); #endif #if RUN_TEST_HEAP || RUN_TEST_ALL - /* heap */ - test_heap(); - printf("\n\n"); + /* heap */ + test_heap(); + printf("\n\n"); #endif #if RUN_TEST_STRINGS || RUN_TEST_ALL - /* strings */ - test_strings(); - printf("\n\n"); + /* strings */ + test_strings(); + printf("\n\n"); #endif #if RUN_TEST_URL || RUN_TEST_ALL - /* url */ - test_url(); - printf("\n\n"); + /* url */ + test_url(); + printf("\n\n"); #endif #if RUN_TEST_THREADS || RUN_TEST_ALL - /* threads */ - test_threads(); - printf("\n\n"); + /* threads */ + test_threads(); + printf("\n\n"); #endif #if RUN_TEST_MUTEX || RUN_TEST_ALL - /* mutex */ - test_mutex(); - printf("\n\n"); + /* mutex */ + test_mutex(); + printf("\n\n"); #endif #if RUN_TEST_CONDWAIT || RUN_TEST_ALL - /* condwait */ - test_condwait(); - printf("\n\n"); + /* condwait */ + test_condwait(); + printf("\n\n"); #endif #if RUN_TEST_SEMAPHORE || RUN_TEST_ALL - /* semaphore */ - test_semaphore(); - printf("\n\n"); + /* semaphore */ + test_semaphore(); + printf("\n\n"); #endif #if RUN_TEST_SAFEOBJECT || RUN_TEST_ALL - /* safe object */ - //test_safeobject(); - printf("\n\n"); + /* safe object */ + //test_safeobject(); + printf("\n\n"); #endif #if RUN_TEST_OBJECT || RUN_TEST_ALL - /* object */ - //test_object(); - printf("\n\n"); + /* object */ + //test_object(); + printf("\n\n"); #endif #if RUN_TEST_PARAMS || RUN_TEST_ALL - /* parameters */ - test_params(); - printf("\n\n"); + /* parameters */ + test_params(); + printf("\n\n"); #endif #if RUN_TEST_OPTIONS || RUN_TEST_ALL - /* options */ - test_options(); - printf("\n\n"); + /* options */ + test_options(); + printf("\n\n"); #endif #if RUN_TEST_TIMER || RUN_TEST_ALL - /* timer */ - test_timer(); - printf("\n\n"); + /* timer */ + test_timer(); + printf("\n\n"); #endif - + #if RUN_TEST_RUNNABLE || RUN_TEST_ALL - /* test runnable. */ - test_runnable(); - printf("\n\n"); + /* test runnable. */ + test_runnable(); + printf("\n\n"); #endif #if RUN_TEST_BUFFER || RUN_TEST_ALL - /* test buffer */ - test_buffer(); + /* test buffer */ + test_buffer(); #endif #if RUN_TEST_MD5 || RUN_TEST_ALL - /* test md5 and hmac_md5 */ - test_md5(); - test_hmac_md5(); + /* test md5 and hmac_md5 */ + test_md5(); + test_hmac_md5(); #endif #if RUN_TEST_SHA1 || RUN_TEST_ALL - /* test sha1 and hmac_sha-1 */ - test_sha1(); - test_hmac_sha1(); + /* test sha1 and hmac_sha-1 */ + test_sha1(); + test_hmac_sha1(); #endif #if RUN_TEST_BASE64 || RUN_TEST_ALL - /* test base64 encoding/decoding */ - test_base64(); + /* test base64 encoding/decoding */ + test_base64(); #endif #if RUN_TEST_UUID || RUN_TEST_ALL - /* test fake UUID (version5) */ - test_uuid(); + /* test fake UUID (version5) */ + test_uuid(); #endif #if RUN_TEST_FSM || RUN_TEST_ALL - /* test FSM */ - test_fsm(); + /* test FSM */ + test_fsm(); #endif - } - while(LOOP); + } + while(LOOP); - getchar(); + getchar(); - return 0; + return 0; } diff --git a/tinySAK/test/test_base64.h b/tinySAK/test/test_base64.h index 0a8ac0b..124f59f 100755 --- a/tinySAK/test/test_base64.h +++ b/tinySAK/test/test_base64.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -22,92 +22,90 @@ #ifndef _TEST_BASE64_H_ #define _TEST_BASE64_H_ -struct b64_msg -{ - const char* ascii; - const char* base64; +struct b64_msg { + const char* ascii; + const char* base64; }; -struct b64_msg b64_msgs[] = -{ - { "", "" }, - { "f", "Zg==" }, - { "fo", "Zm8=" }, - { "foo", "Zm9v" }, - { "foob", "Zm9vYg==" }, - { "fooba", "Zm9vYmE=" }, - { "foobar", "Zm9vYmFy" }, - { "Aladdin:open sesame", "QWxhZGRpbjpvcGVuIHNlc2FtZQ=="}, - { "Doubango Project", "RG91YmFuZ28gUHJvamVjdA=="}, - { "Open Source Doubango Framework", "T3BlbiBTb3VyY2UgRG91YmFuZ28gRnJhbWV3b3Jr"}, - { - "* Copyright (C) 2009 Mamadou Diop." - "*" - "* Contact: Mamadou Diop <diopmamadou(at)doubango.org>" - "*" - "* This file is part of Open Source Doubango Framework." - "*" - "* DOUBANGO is free software: you can redistribute it and/or modify" - "* it under the terms of the GNU General Public License as published by" - "* the Free Software Foundation, either version 3 of the License, or" - "* (at your option) any later version." - "*" - "* DOUBANGO is distributed in the hope that it will be useful," - "* but WITHOUT ANY WARRANTY; without even the implied warranty of" - "* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" - "* GNU General Public License for more details." - "*" - "* You should have received a copy of the GNU General Public License" - "* along with DOUBANGO." - , - "KiBDb3B5cmlnaHQgKEMpIDIwMDkgTWFtYWRvdSBEaW9wLioqIENvbnRhY3Q6IE1hbW" - "Fkb3UgRGlvcCA8ZGlvcG1hbWFkb3UoYXQpZG91YmFuZ28ub3JnPioqIFRoaXMgZmls" - "ZSBpcyBwYXJ0IG9mIE9wZW4gU291cmNlIERvdWJhbmdvIEZyYW1ld29yay4qKiBET1" - "VCQU5HTyBpcyBmcmVlIHNvZnR3YXJlOiB5b3UgY2FuIHJlZGlzdHJpYnV0ZSBpdCBh" - "bmQvb3IgbW9kaWZ5KiBpdCB1bmRlciB0aGUgdGVybXMgb2YgdGhlIEdOVSBHZW5lcm" - "FsIFB1YmxpYyBMaWNlbnNlIGFzIHB1Ymxpc2hlZCBieSogdGhlIEZyZWUgU29mdHdh" - "cmUgRm91bmRhdGlvbiwgZWl0aGVyIHZlcnNpb24gMyBvZiB0aGUgTGljZW5zZSwgb3" - "IqIChhdCB5b3VyIG9wdGlvbikgYW55IGxhdGVyIHZlcnNpb24uKiogRE9VQkFOR08g" - "aXMgZGlzdHJpYnV0ZWQgaW4gdGhlIGhvcGUgdGhhdCBpdCB3aWxsIGJlIHVzZWZ1bC" - "wqIGJ1dCBXSVRIT1VUIEFOWSBXQVJSQU5UWTsgd2l0aG91dCBldmVuIHRoZSBpbXBs" - "aWVkIHdhcnJhbnR5IG9mKiBNRVJDSEFOVEFCSUxJVFkgb3IgRklUTkVTUyBGT1IgQS" - "BQQVJUSUNVTEFSIFBVUlBPU0UuICBTZWUgdGhlKiBHTlUgR2VuZXJhbCBQdWJsaWMg" - "TGljZW5zZSBmb3IgbW9yZSBkZXRhaWxzLioqIFlvdSBzaG91bGQgaGF2ZSByZWNlaX" - "ZlZCBhIGNvcHkgb2YgdGhlIEdOVSBHZW5lcmFsIFB1YmxpYyBMaWNlbnNlKiBhbG9u" - "ZyB3aXRoIERPVUJBTkdPLg==" - } +struct b64_msg b64_msgs[] = { + { "", "" }, + { "f", "Zg==" }, + { "fo", "Zm8=" }, + { "foo", "Zm9v" }, + { "foob", "Zm9vYg==" }, + { "fooba", "Zm9vYmE=" }, + { "foobar", "Zm9vYmFy" }, + { "Aladdin:open sesame", "QWxhZGRpbjpvcGVuIHNlc2FtZQ=="}, + { "Doubango Project", "RG91YmFuZ28gUHJvamVjdA=="}, + { "Open Source Doubango Framework", "T3BlbiBTb3VyY2UgRG91YmFuZ28gRnJhbWV3b3Jr"}, + { + "* Copyright (C) 2009 Mamadou Diop." + "*" + "* Contact: Mamadou Diop <diopmamadou(at)doubango.org>" + "*" + "* This file is part of Open Source Doubango Framework." + "*" + "* DOUBANGO is free software: you can redistribute it and/or modify" + "* it under the terms of the GNU General Public License as published by" + "* the Free Software Foundation, either version 3 of the License, or" + "* (at your option) any later version." + "*" + "* DOUBANGO is distributed in the hope that it will be useful," + "* but WITHOUT ANY WARRANTY; without even the implied warranty of" + "* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" + "* GNU General Public License for more details." + "*" + "* You should have received a copy of the GNU General Public License" + "* along with DOUBANGO." + , + "KiBDb3B5cmlnaHQgKEMpIDIwMDkgTWFtYWRvdSBEaW9wLioqIENvbnRhY3Q6IE1hbW" + "Fkb3UgRGlvcCA8ZGlvcG1hbWFkb3UoYXQpZG91YmFuZ28ub3JnPioqIFRoaXMgZmls" + "ZSBpcyBwYXJ0IG9mIE9wZW4gU291cmNlIERvdWJhbmdvIEZyYW1ld29yay4qKiBET1" + "VCQU5HTyBpcyBmcmVlIHNvZnR3YXJlOiB5b3UgY2FuIHJlZGlzdHJpYnV0ZSBpdCBh" + "bmQvb3IgbW9kaWZ5KiBpdCB1bmRlciB0aGUgdGVybXMgb2YgdGhlIEdOVSBHZW5lcm" + "FsIFB1YmxpYyBMaWNlbnNlIGFzIHB1Ymxpc2hlZCBieSogdGhlIEZyZWUgU29mdHdh" + "cmUgRm91bmRhdGlvbiwgZWl0aGVyIHZlcnNpb24gMyBvZiB0aGUgTGljZW5zZSwgb3" + "IqIChhdCB5b3VyIG9wdGlvbikgYW55IGxhdGVyIHZlcnNpb24uKiogRE9VQkFOR08g" + "aXMgZGlzdHJpYnV0ZWQgaW4gdGhlIGhvcGUgdGhhdCBpdCB3aWxsIGJlIHVzZWZ1bC" + "wqIGJ1dCBXSVRIT1VUIEFOWSBXQVJSQU5UWTsgd2l0aG91dCBldmVuIHRoZSBpbXBs" + "aWVkIHdhcnJhbnR5IG9mKiBNRVJDSEFOVEFCSUxJVFkgb3IgRklUTkVTUyBGT1IgQS" + "BQQVJUSUNVTEFSIFBVUlBPU0UuICBTZWUgdGhlKiBHTlUgR2VuZXJhbCBQdWJsaWMg" + "TGljZW5zZSBmb3IgbW9yZSBkZXRhaWxzLioqIFlvdSBzaG91bGQgaGF2ZSByZWNlaX" + "ZlZCBhIGNvcHkgb2YgdGhlIEdOVSBHZW5lcmFsIFB1YmxpYyBMaWNlbnNlKiBhbG9u" + "ZyB3aXRoIERPVUJBTkdPLg==" + } }; void test_base64() { - size_t i, size; - char *output_e = 0, *output_d = 0; - - for(i=0; i<sizeof(b64_msgs)/sizeof(struct b64_msg); i++){ - /*=========== - * Encoding - */ - size = tsk_base64_encode((const uint8_t*)b64_msgs[i].ascii, strlen(b64_msgs[i].ascii), &output_e); - if(tsk_striequals(b64_msgs[i].base64, output_e)){ - TSK_DEBUG_INFO("[BASE64-%d encoding] ==> OK", i); - } - else{ - TSK_DEBUG_INFO("[BASE64-%d encoding] ==> NOK", i); - } - TSK_FREE(output_e); + size_t i, size; + char *output_e = 0, *output_d = 0; + + for(i=0; i<sizeof(b64_msgs)/sizeof(struct b64_msg); i++) { + /*=========== + * Encoding + */ + size = tsk_base64_encode((const uint8_t*)b64_msgs[i].ascii, strlen(b64_msgs[i].ascii), &output_e); + if(tsk_striequals(b64_msgs[i].base64, output_e)) { + TSK_DEBUG_INFO("[BASE64-%d encoding] ==> OK", i); + } + else { + TSK_DEBUG_INFO("[BASE64-%d encoding] ==> NOK", i); + } + TSK_FREE(output_e); - /*=========== - * Decoding - */ - size = tsk_base64_decode((const uint8_t*)b64_msgs[i].base64, strlen(b64_msgs[i].base64), &output_d); - if(tsk_striequals(b64_msgs[i].ascii, output_d)){ - TSK_DEBUG_INFO("[BASE64-%d decoding] ==> OK", i); - } - else{ - TSK_DEBUG_INFO("[BASE64-%d decoding] ==> NOK", i); - } - TSK_FREE(output_d); - } + /*=========== + * Decoding + */ + size = tsk_base64_decode((const uint8_t*)b64_msgs[i].base64, strlen(b64_msgs[i].base64), &output_d); + if(tsk_striequals(b64_msgs[i].ascii, output_d)) { + TSK_DEBUG_INFO("[BASE64-%d decoding] ==> OK", i); + } + else { + TSK_DEBUG_INFO("[BASE64-%d decoding] ==> NOK", i); + } + TSK_FREE(output_d); + } } #endif /* _TEST_BASE64_H_ */ diff --git a/tinySAK/test/test_buffer.h b/tinySAK/test/test_buffer.h index 8940608..6207d1f 100755 --- a/tinySAK/test/test_buffer.h +++ b/tinySAK/test/test_buffer.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -24,21 +24,21 @@ void test_buffer() { - tsk_buffer_t *buffer = tsk_buffer_create_null(); - - tsk_buffer_append(buffer, "Diop", strlen("Diop")); - tsk_buffer_append(buffer, " ", strlen(" ")); - tsk_buffer_append(buffer, "Mamadou", strlen("Mamadou")); - tsk_buffer_append(buffer, "\r\n", strlen("\r\n")); + tsk_buffer_t *buffer = tsk_buffer_create_null(); + + tsk_buffer_append(buffer, "Diop", strlen("Diop")); + tsk_buffer_append(buffer, " ", strlen(" ")); + tsk_buffer_append(buffer, "Mamadou", strlen("Mamadou")); + tsk_buffer_append(buffer, "\r\n", strlen("\r\n")); - printf("1. Buffer=%s", TSK_BUFFER_TO_STRING(buffer)); + printf("1. Buffer=%s", TSK_BUFFER_TO_STRING(buffer)); - tsk_buffer_append_2(buffer, "val1=[%s] and val2=[%d]r\n", "value1", 12); - tsk_buffer_append_2(buffer, "val3=[%s] and val4=[%s]r\n", "458888554778555LL", "1254852"); + tsk_buffer_append_2(buffer, "val1=[%s] and val2=[%d]r\n", "value1", 12); + tsk_buffer_append_2(buffer, "val3=[%s] and val4=[%s]r\n", "458888554778555LL", "1254852"); - printf("2. Buffer=%s", TSK_BUFFER_TO_STRING(buffer)); + printf("2. Buffer=%s", TSK_BUFFER_TO_STRING(buffer)); - TSK_OBJECT_SAFE_FREE(buffer); + TSK_OBJECT_SAFE_FREE(buffer); } #endif /* _TEST_BUFFER_H_ */ diff --git a/tinySAK/test/test_condwait.h b/tinySAK/test/test_condwait.h index a28bf11..1f6f346 100755 --- a/tinySAK/test/test_condwait.h +++ b/tinySAK/test/test_condwait.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -24,35 +24,35 @@ void *threadfunc_timed(void *parm) { - tsk_condwait_handle_t *condwait = (tsk_condwait_handle_t *)parm; - int ret = 0; + tsk_condwait_handle_t *condwait = (tsk_condwait_handle_t *)parm; + int ret = 0; - ret = tsk_condwait_timedwait(condwait, 10); - printf("threadfunc_timed/// %d\n", ret); + ret = tsk_condwait_timedwait(condwait, 10); + printf("threadfunc_timed/// %d\n", ret); - return 0; + return 0; } void *threadfunc_infinite(void *parm) { - tsk_condwait_handle_t *condwait = (tsk_condwait_handle_t *)parm; - int ret = 0; + tsk_condwait_handle_t *condwait = (tsk_condwait_handle_t *)parm; + int ret = 0; - ret = tsk_condwait_wait(condwait); - printf("threadfunc_infinite/// %d\n", ret); + ret = tsk_condwait_wait(condwait); + printf("threadfunc_infinite/// %d\n", ret); - return 0; + return 0; } void *threadfunc_onemore(void *parm) { - tsk_condwait_handle_t *condwait = (tsk_condwait_handle_t *)parm; - int ret = 0; + tsk_condwait_handle_t *condwait = (tsk_condwait_handle_t *)parm; + int ret = 0; - ret = tsk_condwait_wait(condwait); - printf("threadfunc_onemore/// %d\n", ret); + ret = tsk_condwait_wait(condwait); + printf("threadfunc_onemore/// %d\n", ret); - return 0; + return 0; } @@ -60,27 +60,27 @@ void *threadfunc_onemore(void *parm) /* Pthread condwait */ void test_condwait() { - tsk_condwait_handle_t *condwait = tsk_condwait_create(); - int ret; - void* tid[3] = {0,0,0}; + tsk_condwait_handle_t *condwait = tsk_condwait_create(); + int ret; + void* tid[3] = {0,0,0}; - printf("test_condwait//\n"); + printf("test_condwait//\n"); - tsk_thread_create(&tid[0], threadfunc_timed, condwait); - tsk_thread_create(&tid[1], threadfunc_infinite, condwait); - tsk_thread_create(&tid[2], threadfunc_onemore, condwait); + tsk_thread_create(&tid[0], threadfunc_timed, condwait); + tsk_thread_create(&tid[1], threadfunc_infinite, condwait); + tsk_thread_create(&tid[2], threadfunc_onemore, condwait); - tsk_condwait_timedwait(condwait, 100); /* give the threads the time to start and 'threadfunc_timed' function to timeout */ + tsk_condwait_timedwait(condwait, 100); /* give the threads the time to start and 'threadfunc_timed' function to timeout */ - ret = tsk_condwait_signal(condwait); /* Release one */ - ret = tsk_condwait_broadcast(condwait); /* Release all */ + ret = tsk_condwait_signal(condwait); /* Release one */ + ret = tsk_condwait_broadcast(condwait); /* Release all */ - tsk_thread_join(&tid[0]); - tsk_thread_join(&tid[1]); - tsk_thread_join(&tid[2]); + tsk_thread_join(&tid[0]); + tsk_thread_join(&tid[1]); + tsk_thread_join(&tid[2]); - tsk_condwait_destroy(&condwait); + tsk_condwait_destroy(&condwait); } #endif /* _TEST_CONDWAIT_H_ */ diff --git a/tinySAK/test/test_fsm.h b/tinySAK/test/test_fsm.h index 98cabc3..83d2dd2 100755 --- a/tinySAK/test/test_fsm.h +++ b/tinySAK/test/test_fsm.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -22,289 +22,284 @@ #ifndef _TEST_FSM_H_ #define _TEST_FSM_H_ -typedef struct test_fsm_ctx_s -{ - unsigned unsubscribing:1; +typedef struct test_fsm_ctx_s { + unsigned unsubscribing:1; } test_fsm_ctx_t; /* ======================== actions ======================== */ -typedef enum test_fsm_action_e -{ - test_fsm_action_send, - test_fsm_action_1xx, - test_fsm_action_2xx, - test_fsm_action_401_407_421_494, - test_fsm_action_423, - test_fsm_action_300_to_699, - test_fsm_action_cancel, - test_fsm_action_notify, - test_fsm_action_unsubscribe, - test_fsm_action_refresh, - test_fsm_action_transporterror, - test_fsm_action_error, +typedef enum test_fsm_action_e { + test_fsm_action_send, + test_fsm_action_1xx, + test_fsm_action_2xx, + test_fsm_action_401_407_421_494, + test_fsm_action_423, + test_fsm_action_300_to_699, + test_fsm_action_cancel, + test_fsm_action_notify, + test_fsm_action_unsubscribe, + test_fsm_action_refresh, + test_fsm_action_transporterror, + test_fsm_action_error, } test_fsm_action_t; /* ======================== execs ======================== */ int test_fsm_exec_Started_2_Trying_X_send(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Trying_2_Trying_X_1xx(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Trying_2_Terminated_X_2xx(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Trying_2_Connected_X_2xx(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Trying_2_Trying_X_401_407_421_494(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Trying_2_Trying_X_423(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Trying_2_Terminated_X_300_to_699(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Trying_2_Terminated_X_cancel(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Trying_2_Trying_X_NOTIFY(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Connected_2_Trying_X_unsubscribe(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Connected_2_Trying_X_refresh(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Connected_2_Connected_X_NOTIFY(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Connected_2_Terminated_X_NOTIFY(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Any_2_Trying_X_hangup(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Any_2_Terminated_X_transportError(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } int test_fsm_exec_Any_2_Terminated_X_Error(va_list *app) { - const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); - const void* message = va_arg(*app, const void *); + const test_fsm_ctx_t* ctx = va_arg(*app, const test_fsm_ctx_t *); + const void* message = va_arg(*app, const void *); - return 0; + return 0; } /* ======================== conds ======================== */ int test_fsm_cond_unsubscribing(test_fsm_ctx_t* ctx, void* data) { - return ctx->unsubscribing ? 1 : 0; + return ctx->unsubscribing ? 1 : 0; } int test_fsm_cond_subscribing(test_fsm_ctx_t* ctx, void* data) { - return !test_fsm_cond_unsubscribing(ctx, data); + return !test_fsm_cond_unsubscribing(ctx, data); } int test_fsm_cond_notify_terminated(test_fsm_ctx_t* ctx, void* sipmessage) { - return 0; + return 0; } int test_fsm_cond_notify_not_terminated(test_fsm_ctx_t* ctx, void* sipmessage) { - return !test_fsm_cond_notify_terminated(ctx, sipmessage); + return !test_fsm_cond_notify_terminated(ctx, sipmessage); } -typedef enum test_fsm_state_e -{ - __nil = 0, - Started, - Trying, - Connected, - Terminated +typedef enum test_fsm_state_e { + __nil = 0, + Started, + Trying, + Connected, + Terminated } test_fsm_state_t; int test_fsm_onterminated(const test_fsm_ctx_t* ctx) { - TSK_DEBUG_INFO("FSM in terminal state."); - return 0; + TSK_DEBUG_INFO("FSM in terminal state."); + return 0; } #define TEST_FSM_ACTIONS_COUNT 5 -test_fsm_action_t test_fsm_tests[TEST_FSM_ACTIONS_COUNT][TEST_FSM_ACTIONS_COUNT] = -{ - { test_fsm_action_send, test_fsm_action_300_to_699 }, - { test_fsm_action_send, test_fsm_action_401_407_421_494, test_fsm_action_2xx, test_fsm_action_refresh, test_fsm_action_300_to_699}, - { test_fsm_action_send, test_fsm_action_401_407_421_494, test_fsm_action_2xx, test_fsm_action_refresh, test_fsm_action_2xx}, - { test_fsm_action_send, test_fsm_action_2xx, test_fsm_action_2xx, test_fsm_action_refresh, test_fsm_action_2xx}, - { test_fsm_action_send, test_fsm_action_423, test_fsm_action_2xx, test_fsm_action_refresh, test_fsm_action_401_407_421_494}, +test_fsm_action_t test_fsm_tests[TEST_FSM_ACTIONS_COUNT][TEST_FSM_ACTIONS_COUNT] = { + { test_fsm_action_send, test_fsm_action_300_to_699 }, + { test_fsm_action_send, test_fsm_action_401_407_421_494, test_fsm_action_2xx, test_fsm_action_refresh, test_fsm_action_300_to_699}, + { test_fsm_action_send, test_fsm_action_401_407_421_494, test_fsm_action_2xx, test_fsm_action_refresh, test_fsm_action_2xx}, + { test_fsm_action_send, test_fsm_action_2xx, test_fsm_action_2xx, test_fsm_action_refresh, test_fsm_action_2xx}, + { test_fsm_action_send, test_fsm_action_423, test_fsm_action_2xx, test_fsm_action_refresh, test_fsm_action_401_407_421_494}, }; void test_fsm() { - size_t i; - - for(i=0; i<TEST_FSM_ACTIONS_COUNT; i++) - { - size_t j; - tsk_fsm_t* fsm = tsk_fsm_create(Started, Terminated); - test_fsm_ctx_t ctx; - ctx.unsubscribing = 0; - - tsk_fsm_set_callback_terminated(fsm, test_fsm_onterminated, &ctx); - - tsk_fsm_set(fsm, - - /*======================= - * === Any === - */ - // Any -> (transport error) -> Terminated - TSK_FSM_ADD_ALWAYS(tsk_fsm_state_any, test_fsm_action_transporterror, Terminated, test_fsm_exec_Any_2_Terminated_X_transportError, "test_fsm_exec_Any_2_Terminated_X_transportError"), - // Any -> (transport error) -> Terminated - TSK_FSM_ADD_ALWAYS(tsk_fsm_state_any, test_fsm_action_error, Terminated, test_fsm_exec_Any_2_Terminated_X_Error, "test_fsm_exec_Any_2_Terminated_X_Error"), - // Any -> (hangup) -> Terminated - // Any -> (hangup) -> Trying - - /*======================= - * === Started === - */ - // Started -> (Send) -> Trying - TSK_FSM_ADD_ALWAYS(Started, test_fsm_action_send, Trying, test_fsm_exec_Started_2_Trying_X_send, "test_fsm_exec_Started_2_Trying_X_send"), - // Started -> (Any) -> Started - TSK_FSM_ADD_ALWAYS_NOTHING(Started, "test_fsm_exec_Started_2_Started_X_any"), - - - /*======================= - * === Trying === - */ - // Trying -> (1xx) -> Trying - TSK_FSM_ADD_ALWAYS(Trying, test_fsm_action_1xx, Trying, test_fsm_exec_Trying_2_Trying_X_1xx, "test_fsm_exec_Trying_2_Trying_X_1xx"), - // Trying -> (2xx) -> Terminated - TSK_FSM_ADD(Trying, test_fsm_action_2xx, test_fsm_cond_unsubscribing, Terminated, test_fsm_exec_Trying_2_Terminated_X_2xx, "test_fsm_exec_Trying_2_Terminated_X_2xx"), - // Trying -> (2xx) -> Connected - TSK_FSM_ADD(Trying, test_fsm_action_2xx, test_fsm_cond_subscribing, Connected, test_fsm_exec_Trying_2_Connected_X_2xx, "test_fsm_exec_Trying_2_Connected_X_2xx"), - // Trying -> (401/407/421/494) -> Trying - TSK_FSM_ADD_ALWAYS(Trying, test_fsm_action_401_407_421_494, Trying, test_fsm_exec_Trying_2_Trying_X_401_407_421_494, "test_fsm_exec_Trying_2_Trying_X_401_407_421_494"), - // Trying -> (423) -> Trying - TSK_FSM_ADD_ALWAYS(Trying, test_fsm_action_423, Trying, test_fsm_exec_Trying_2_Trying_X_423, "test_fsm_exec_Trying_2_Trying_X_423"), - // Trying -> (300_to_699) -> Terminated - TSK_FSM_ADD_ALWAYS(Trying, test_fsm_action_300_to_699, Terminated, test_fsm_exec_Trying_2_Terminated_X_300_to_699, "test_fsm_exec_Trying_2_Terminated_X_300_to_699"), - // Trying -> (cancel) -> Terminated - TSK_FSM_ADD_ALWAYS(Trying, test_fsm_action_cancel, Terminated, test_fsm_exec_Trying_2_Terminated_X_cancel, "test_fsm_exec_Trying_2_Terminated_X_cancel"), - // Trying -> (Notify) -> Trying - TSK_FSM_ADD_ALWAYS(Trying, test_fsm_action_notify, Trying, test_fsm_exec_Trying_2_Trying_X_NOTIFY, "test_fsm_exec_Trying_2_Trying_X_NOTIFY"), - // Trying -> (Any) -> Trying - TSK_FSM_ADD_ALWAYS_NOTHING(Trying, "test_fsm_exec_Trying_2_Trying_X_any"), - - - /*======================= - * === Connected === - */ - // Connected -> (unsubscribe) -> Trying - TSK_FSM_ADD_ALWAYS(Connected, test_fsm_action_unsubscribe, Trying, test_fsm_exec_Connected_2_Trying_X_unsubscribe, "test_fsm_exec_Connected_2_Trying_X_unsubscribe"), - // Connected -> (refresh) -> Trying - TSK_FSM_ADD_ALWAYS(Connected, test_fsm_action_refresh, Trying, test_fsm_exec_Connected_2_Trying_X_refresh, "test_fsm_exec_Connected_2_Trying_X_refresh"), - // Connected -> (NOTIFY) -> Connected - TSK_FSM_ADD(Connected, test_fsm_action_notify, test_fsm_cond_notify_not_terminated, Connected, test_fsm_exec_Connected_2_Connected_X_NOTIFY, "test_fsm_exec_Connected_2_Connected_X_NOTIFY"), - // Connected -> (NOTIFY) -> Terminated - TSK_FSM_ADD(Connected, test_fsm_action_notify, test_fsm_cond_notify_terminated, Terminated, test_fsm_exec_Connected_2_Terminated_X_NOTIFY, "test_fsm_exec_Connected_2_Terminated_X_NOTIFY"), - // Connected -> (Any) -> Connected - TSK_FSM_ADD_ALWAYS_NOTHING(Connected, "test_fsm_exec_Connected_2_Connected_X_any"), - - TSK_FSM_ADD_NULL()); - - - for(j=0; j<TEST_FSM_ACTIONS_COUNT; j++){ - tsk_fsm_act(fsm, test_fsm_tests[i][j], &ctx, tsk_null, &ctx, tsk_null /*message*/); - } - - TSK_OBJECT_SAFE_FREE(fsm); - - printf("\n\n"); - } + size_t i; + + for(i=0; i<TEST_FSM_ACTIONS_COUNT; i++) { + size_t j; + tsk_fsm_t* fsm = tsk_fsm_create(Started, Terminated); + test_fsm_ctx_t ctx; + ctx.unsubscribing = 0; + + tsk_fsm_set_callback_terminated(fsm, test_fsm_onterminated, &ctx); + + tsk_fsm_set(fsm, + + /*======================= + * === Any === + */ + // Any -> (transport error) -> Terminated + TSK_FSM_ADD_ALWAYS(tsk_fsm_state_any, test_fsm_action_transporterror, Terminated, test_fsm_exec_Any_2_Terminated_X_transportError, "test_fsm_exec_Any_2_Terminated_X_transportError"), + // Any -> (transport error) -> Terminated + TSK_FSM_ADD_ALWAYS(tsk_fsm_state_any, test_fsm_action_error, Terminated, test_fsm_exec_Any_2_Terminated_X_Error, "test_fsm_exec_Any_2_Terminated_X_Error"), + // Any -> (hangup) -> Terminated + // Any -> (hangup) -> Trying + + /*======================= + * === Started === + */ + // Started -> (Send) -> Trying + TSK_FSM_ADD_ALWAYS(Started, test_fsm_action_send, Trying, test_fsm_exec_Started_2_Trying_X_send, "test_fsm_exec_Started_2_Trying_X_send"), + // Started -> (Any) -> Started + TSK_FSM_ADD_ALWAYS_NOTHING(Started, "test_fsm_exec_Started_2_Started_X_any"), + + + /*======================= + * === Trying === + */ + // Trying -> (1xx) -> Trying + TSK_FSM_ADD_ALWAYS(Trying, test_fsm_action_1xx, Trying, test_fsm_exec_Trying_2_Trying_X_1xx, "test_fsm_exec_Trying_2_Trying_X_1xx"), + // Trying -> (2xx) -> Terminated + TSK_FSM_ADD(Trying, test_fsm_action_2xx, test_fsm_cond_unsubscribing, Terminated, test_fsm_exec_Trying_2_Terminated_X_2xx, "test_fsm_exec_Trying_2_Terminated_X_2xx"), + // Trying -> (2xx) -> Connected + TSK_FSM_ADD(Trying, test_fsm_action_2xx, test_fsm_cond_subscribing, Connected, test_fsm_exec_Trying_2_Connected_X_2xx, "test_fsm_exec_Trying_2_Connected_X_2xx"), + // Trying -> (401/407/421/494) -> Trying + TSK_FSM_ADD_ALWAYS(Trying, test_fsm_action_401_407_421_494, Trying, test_fsm_exec_Trying_2_Trying_X_401_407_421_494, "test_fsm_exec_Trying_2_Trying_X_401_407_421_494"), + // Trying -> (423) -> Trying + TSK_FSM_ADD_ALWAYS(Trying, test_fsm_action_423, Trying, test_fsm_exec_Trying_2_Trying_X_423, "test_fsm_exec_Trying_2_Trying_X_423"), + // Trying -> (300_to_699) -> Terminated + TSK_FSM_ADD_ALWAYS(Trying, test_fsm_action_300_to_699, Terminated, test_fsm_exec_Trying_2_Terminated_X_300_to_699, "test_fsm_exec_Trying_2_Terminated_X_300_to_699"), + // Trying -> (cancel) -> Terminated + TSK_FSM_ADD_ALWAYS(Trying, test_fsm_action_cancel, Terminated, test_fsm_exec_Trying_2_Terminated_X_cancel, "test_fsm_exec_Trying_2_Terminated_X_cancel"), + // Trying -> (Notify) -> Trying + TSK_FSM_ADD_ALWAYS(Trying, test_fsm_action_notify, Trying, test_fsm_exec_Trying_2_Trying_X_NOTIFY, "test_fsm_exec_Trying_2_Trying_X_NOTIFY"), + // Trying -> (Any) -> Trying + TSK_FSM_ADD_ALWAYS_NOTHING(Trying, "test_fsm_exec_Trying_2_Trying_X_any"), + + + /*======================= + * === Connected === + */ + // Connected -> (unsubscribe) -> Trying + TSK_FSM_ADD_ALWAYS(Connected, test_fsm_action_unsubscribe, Trying, test_fsm_exec_Connected_2_Trying_X_unsubscribe, "test_fsm_exec_Connected_2_Trying_X_unsubscribe"), + // Connected -> (refresh) -> Trying + TSK_FSM_ADD_ALWAYS(Connected, test_fsm_action_refresh, Trying, test_fsm_exec_Connected_2_Trying_X_refresh, "test_fsm_exec_Connected_2_Trying_X_refresh"), + // Connected -> (NOTIFY) -> Connected + TSK_FSM_ADD(Connected, test_fsm_action_notify, test_fsm_cond_notify_not_terminated, Connected, test_fsm_exec_Connected_2_Connected_X_NOTIFY, "test_fsm_exec_Connected_2_Connected_X_NOTIFY"), + // Connected -> (NOTIFY) -> Terminated + TSK_FSM_ADD(Connected, test_fsm_action_notify, test_fsm_cond_notify_terminated, Terminated, test_fsm_exec_Connected_2_Terminated_X_NOTIFY, "test_fsm_exec_Connected_2_Terminated_X_NOTIFY"), + // Connected -> (Any) -> Connected + TSK_FSM_ADD_ALWAYS_NOTHING(Connected, "test_fsm_exec_Connected_2_Connected_X_any"), + + TSK_FSM_ADD_NULL()); + + + for(j=0; j<TEST_FSM_ACTIONS_COUNT; j++) { + tsk_fsm_act(fsm, test_fsm_tests[i][j], &ctx, tsk_null, &ctx, tsk_null /*message*/); + } + + TSK_OBJECT_SAFE_FREE(fsm); + + printf("\n\n"); + } } #endif /* _TEST_FSM_H_ */ diff --git a/tinySAK/test/test_heap.h b/tinySAK/test/test_heap.h index edae766..b648457 100755 --- a/tinySAK/test/test_heap.h +++ b/tinySAK/test/test_heap.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -26,52 +26,52 @@ /* test heap*/ void test_heap() { - //int i = 0; - //tsk_heap_t heap; + //int i = 0; + //tsk_heap_t heap; - ///* initialize our memory heap */ - //tsk_heap_init(&heap); + ///* initialize our memory heap */ + //tsk_heap_init(&heap); - ///* heap(1): Ten strings are allocated an all freed when we cleanup the heap */ - //for(i=0; i<10;i++) - //{ - // char* test = tsk_strdup(&heap, "testing the heap (1)"); - //} - //tsk_heap_cleanup(&heap); + ///* heap(1): Ten strings are allocated an all freed when we cleanup the heap */ + //for(i=0; i<10;i++) + //{ + // char* test = tsk_strdup(&heap, "testing the heap (1)"); + //} + //tsk_heap_cleanup(&heap); - ///* heap(2): pop memory from the heap*/ - //{ - // char* test = tsk_strdup(&heap, "testing the heap (2)"); - // tsk_free(&heap, (void**)&test); + ///* heap(2): pop memory from the heap*/ + //{ +// char* test = tsk_strdup(&heap, "testing the heap (2)"); + // tsk_free(&heap, (void**)&test); - // test = tsk_calloc(&heap, 10, 1); - // tsk_free(&heap, (void**)&test); + // test = tsk_calloc(&heap, 10, 1); + // tsk_free(&heap, (void**)&test); - // test = tsk_malloc(&heap, 10); - // tsk_free(&heap, (void**)&test); + // test = tsk_malloc(&heap, 10); + // tsk_free(&heap, (void**)&test); - // test = tsk_malloc(&heap, 10); - // test = tsk_realloc(&heap, test, 100); - // tsk_free(&heap, (void**)&test); - //} - // - ///* heap(3): pop a NULL pointer */ - //{ - // tsk_free(&heap, 0); - //} + // test = tsk_malloc(&heap, 10); + // test = tsk_realloc(&heap, test, 100); + // tsk_free(&heap, (void**)&test); + //} + // + ///* heap(3): pop a NULL pointer */ + //{ + // tsk_free(&heap, 0); + //} - ///* heap(4): allocate and pop from NULL heap */ - //{ - // char* test = tsk_calloc(0, 10, 1); - // tsk_free(0, (void**)&test); + ///* heap(4): allocate and pop from NULL heap */ + //{ + // char* test = tsk_calloc(0, 10, 1); + // tsk_free(0, (void**)&test); - // test = tsk_malloc(0, 10); - // tsk_free(0, (void**)&test); + // test = tsk_malloc(0, 10); + // tsk_free(0, (void**)&test); - // test = tsk_malloc(0, 10); - // test = tsk_realloc(0, test, 100); - // tsk_free(0, (void**)&test); - //} + // test = tsk_malloc(0, 10); + // test = tsk_realloc(0, test, 100); + // tsk_free(0, (void**)&test); + //} } #endif /* _TEST_HEAP_H_ */ diff --git a/tinySAK/test/test_lists.h b/tinySAK/test/test_lists.h index c02b2a7..3b6a0f0 100755 --- a/tinySAK/test/test_lists.h +++ b/tinySAK/test/test_lists.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -24,248 +24,244 @@ // (well-defined object declaration) -typedef struct student_s -{ - TSK_DECLARE_OBJECT; +typedef struct student_s { + TSK_DECLARE_OBJECT; - char *id; - char *name; -} + char *id; + char *name; +} student_t; // (constructor) static tsk_object_t* student_ctor(tsk_object_t* self, va_list * app) { - student_t* student = (tsk_object_t*)self; - if(student){ - } - return self; + student_t* student = (tsk_object_t*)self; + if(student) { + } + return self; } // (destructor) static tsk_object_t* student_dtor(tsk_object_t* self) { - student_t* student = (tsk_object_t*)self; - TSK_FREE(student->id); - TSK_FREE(student->name); - return self; + student_t* student = (tsk_object_t*)self; + TSK_FREE(student->id); + TSK_FREE(student->name); + return self; } // (case insensitive comparator) static int student_icmp(const tsk_object_t *self, const tsk_object_t *object) -{ - const student_t* student1 = (const tsk_object_t*)self; - const student_t* student2 = (const tsk_object_t*)object; +{ + const student_t* student1 = (const tsk_object_t*)self; + const student_t* student2 = (const tsk_object_t*)object; - if(!student1 || !student2){ - return 0;// must never happen - } + if(!student1 || !student2) { + return 0;// must never happen + } - return tsk_stricmp(student1->id, student2->id); + return tsk_stricmp(student1->id, student2->id); } // (well-defined object declaration) -static const tsk_object_def_t student_def_s = -{ - sizeof(student_t), - student_ctor, - student_dtor, - student_icmp +static const tsk_object_def_t student_def_s = { + sizeof(student_t), + student_ctor, + student_dtor, + student_icmp }; // create a stun object static student_t* student_create(const char* id, const char* name) { - student_t* student; - if((student = (student_t*)tsk_object_new(&student_def_s))){ - student->id = tsk_strdup(id); - student->name = tsk_strdup(name); - } - return student; + student_t* student; + if((student = (student_t*)tsk_object_new(&student_def_s))) { + student->id = tsk_strdup(id); + student->name = tsk_strdup(name); + } + return student; } // predicate function to find a student by name static int pred_find_student_by_name(const tsk_list_item_t *item, const void *name) { - if(item && item->data){ - student_t *student = item->data; - return tsk_striequals(student->name, name); - } - return -1; + if(item && item->data) { + student_t *student = item->data; + return tsk_striequals(student->name, name); + } + return -1; } // predicate function to find a student by id static int pred_find_student_by_id(const tsk_list_item_t *item, const void *id) { - if(item && item->data){ - student_t *student = item->data; - return tsk_striequals(student->id, id); - } - return -1; + if(item && item->data) { + student_t *student = item->data; + return tsk_striequals(student->id, id); + } + return -1; } /* testing basic linked list */ void test_basic_list() { - tsk_list_t *list = tsk_list_create(); - tsk_list_item_t *item = tsk_list_item_create(); - - /* add items to the list */ - item->data = tsk_string_create("First item"); - tsk_list_push_front_item(list, &item); + tsk_list_t *list = tsk_list_create(); + tsk_list_item_t *item = tsk_list_item_create(); + + /* add items to the list */ + item->data = tsk_string_create("First item"); + tsk_list_push_front_item(list, &item); - item = tsk_list_item_create(); - item->data = tsk_string_create("Second item"); - tsk_list_push_back_item(list, &item); + item = tsk_list_item_create(); + item->data = tsk_string_create("Second item"); + tsk_list_push_back_item(list, &item); - item = tsk_list_item_create(); - item->data = tsk_string_create("Third item"); - tsk_list_push_front_item(list, &item); + item = tsk_list_item_create(); + item->data = tsk_string_create("Third item"); + tsk_list_push_front_item(list, &item); - item = tsk_list_item_create(); - item->data = tsk_string_create("Fourth item"); - tsk_list_push_back_item(list, &item); + item = tsk_list_item_create(); + item->data = tsk_string_create("Fourth item"); + tsk_list_push_back_item(list, &item); - /* dump all items */ - tsk_list_foreach(item, list){ - tsk_string_t* item_data = ((tsk_string_t*)item->data); - printf("test_basic_list/// --> [%s]\n", item_data->value); - } + /* dump all items */ + tsk_list_foreach(item, list) { + tsk_string_t* item_data = ((tsk_string_t*)item->data); + printf("test_basic_list/// --> [%s]\n", item_data->value); + } - tsk_list_remove_item(list, list->tail); - tsk_list_remove_item(list, list->tail); - tsk_list_remove_item(list, list->tail); - tsk_list_remove_item(list, list->tail); + tsk_list_remove_item(list, list->tail); + tsk_list_remove_item(list, list->tail); + tsk_list_remove_item(list, list->tail); + tsk_list_remove_item(list, list->tail); - /* delete all items in the list */ - TSK_OBJECT_SAFE_FREE(list); + /* delete all items in the list */ + TSK_OBJECT_SAFE_FREE(list); } void test_filtered_list() { - tsk_list_t *list = tsk_list_create(); - tsk_list_item_t *item = 0; + tsk_list_t *list = tsk_list_create(); + tsk_list_item_t *item = 0; - /* add items to the list */ - { - student_t *student2 = student_create("2", "student2"); - tsk_list_push_ascending_data(list, ((void**) &student2)); - } - { - student_t *student6 = student_create("6", "student6"); - tsk_list_push_ascending_data(list, ((void**) &student6)); - } - { - student_t *student1 = student_create("1", "student1"); - tsk_list_push_ascending_data(list, ((void**) &student1)); - } - { - student_t *student6 = student_create("6", "student6"); - tsk_list_push_ascending_data(list, ((void**) &student6)); - } - { - student_t *student6 = student_create("6", "student6"); - tsk_list_push_ascending_data(list, ((void**) &student6)); - } - { - student_t *student2 = student_create("2", "student2"); - tsk_list_push_ascending_data(list, ((void**) &student2)); - } - { - student_t *student2 = student_create("2", "student2"); - tsk_list_push_ascending_data(list, ((void**) &student2)); - } - { - student_t *student5 = student_create("5", "student5"); - tsk_list_push_ascending_data(list, ((void**) &student5)); - } - { - student_t *student4 = student_create("4", "student4"); - tsk_list_push_ascending_data(list, ((void**) &student4)); - } - { - student_t *student1 = student_create("1", "student1"); - tsk_list_push_ascending_data(list, ((void**) &student1)); - } - { - student_t *student1 = student_create("1", "student1"); - tsk_list_push_ascending_data(list, ((void**) &student1)); - } - { - student_t *student3 = student_create("3", "student3"); - tsk_list_push_ascending_data(list, ((void**) &student3)); - } - { - student_t *student6 = student_create("6", "student6"); - tsk_list_push_ascending_data(list, ((void**) &student6)); - } - { - student_t *student1 = student_create("1", "student1"); - tsk_list_push_ascending_data(list, ((void**) &student1)); - } - { - student_t *student3 = student_create("3", "student3"); - tsk_list_push_ascending_data(list, ((void**) &student3)); - } - { - student_t *student6 = student_create("6", "student6"); - tsk_list_push_ascending_data(list, ((void**) &student6)); - } + /* add items to the list */ + { + student_t *student2 = student_create("2", "student2"); + tsk_list_push_ascending_data(list, ((void**) &student2)); + } + { + student_t *student6 = student_create("6", "student6"); + tsk_list_push_ascending_data(list, ((void**) &student6)); + } + { + student_t *student1 = student_create("1", "student1"); + tsk_list_push_ascending_data(list, ((void**) &student1)); + } + { + student_t *student6 = student_create("6", "student6"); + tsk_list_push_ascending_data(list, ((void**) &student6)); + } + { + student_t *student6 = student_create("6", "student6"); + tsk_list_push_ascending_data(list, ((void**) &student6)); + } + { + student_t *student2 = student_create("2", "student2"); + tsk_list_push_ascending_data(list, ((void**) &student2)); + } + { + student_t *student2 = student_create("2", "student2"); + tsk_list_push_ascending_data(list, ((void**) &student2)); + } + { + student_t *student5 = student_create("5", "student5"); + tsk_list_push_ascending_data(list, ((void**) &student5)); + } + { + student_t *student4 = student_create("4", "student4"); + tsk_list_push_ascending_data(list, ((void**) &student4)); + } + { + student_t *student1 = student_create("1", "student1"); + tsk_list_push_ascending_data(list, ((void**) &student1)); + } + { + student_t *student1 = student_create("1", "student1"); + tsk_list_push_ascending_data(list, ((void**) &student1)); + } + { + student_t *student3 = student_create("3", "student3"); + tsk_list_push_ascending_data(list, ((void**) &student3)); + } + { + student_t *student6 = student_create("6", "student6"); + tsk_list_push_ascending_data(list, ((void**) &student6)); + } + { + student_t *student1 = student_create("1", "student1"); + tsk_list_push_ascending_data(list, ((void**) &student1)); + } + { + student_t *student3 = student_create("3", "student3"); + tsk_list_push_ascending_data(list, ((void**) &student3)); + } + { + student_t *student6 = student_create("6", "student6"); + tsk_list_push_ascending_data(list, ((void**) &student6)); + } - /* dump all items */ - tsk_list_foreach(item, list) - { - student_t* item_data = item->data; - TSK_DEBUG_INFO("test_filtered_list/// --> [id=%s and name=%s]", item_data->id, item_data->name); - } + /* dump all items */ + tsk_list_foreach(item, list) { + student_t* item_data = item->data; + TSK_DEBUG_INFO("test_filtered_list/// --> [id=%s and name=%s]", item_data->id, item_data->name); + } - /* delete all items in the list */ - TSK_OBJECT_SAFE_FREE(list); + /* delete all items in the list */ + TSK_OBJECT_SAFE_FREE(list); } void test_complex_list() { - tsk_list_t *list = tsk_list_create(); - tsk_list_item_t *item = 0; + tsk_list_t *list = tsk_list_create(); + tsk_list_item_t *item = 0; - /* add items to the list */ - { - student_t *student1 = student_create("1", "student1"); - tsk_list_push_back_data(list, ((void**) &student1)); - } - { - student_t *student2 = student_create("2", "student2"); - tsk_list_push_front_data(list, ((void**) &student2)); - } - { - student_t *student3 = student_create("3", "student3"); - tsk_list_push_front_data(list, ((void**) &student3)); - } + /* add items to the list */ + { + student_t *student1 = student_create("1", "student1"); + tsk_list_push_back_data(list, ((void**) &student1)); + } + { + student_t *student2 = student_create("2", "student2"); + tsk_list_push_front_data(list, ((void**) &student2)); + } + { + student_t *student3 = student_create("3", "student3"); + tsk_list_push_front_data(list, ((void**) &student3)); + } - /* dump all items */ - tsk_list_foreach(item, list) - { - student_t* item_data = item->data; - TSK_DEBUG_INFO("test_complex_list/// --> [id=%s and name=%s]", item_data->id, item_data->name); - } + /* dump all items */ + tsk_list_foreach(item, list) { + student_t* item_data = item->data; + TSK_DEBUG_INFO("test_complex_list/// --> [id=%s and name=%s]", item_data->id, item_data->name); + } - /* Find student using tsk_object* */ - { - student_t *student_to_find = student_create("1", "student1"); - const tsk_list_item_t *item_const = tsk_list_find_item_by_data(list, student_to_find); - { - const student_t* item_data_const = item_const->data; - TSK_DEBUG_INFO("test_complex_list/// using tsk_object --> student with name==\"student1\" and id=\"%s\"", item_data_const->id); - } - TSK_OBJECT_SAFE_FREE(student_to_find); - } + /* Find student using tsk_object* */ + { + student_t *student_to_find = student_create("1", "student1"); + const tsk_list_item_t *item_const = tsk_list_find_item_by_data(list, student_to_find); + { + const student_t* item_data_const = item_const->data; + TSK_DEBUG_INFO("test_complex_list/// using tsk_object --> student with name==\"student1\" and id=\"%s\"", item_data_const->id); + } + TSK_OBJECT_SAFE_FREE(student_to_find); + } - /* Find student named "student2" using predicate */ - { - const tsk_list_item_t *item_const = tsk_list_find_item_by_pred(list, pred_find_student_by_name, "student2"); - { - const student_t* item_data_const = item_const->data; - TSK_DEBUG_INFO("test_complex_list/// using predicate --> student with name==\"student2\" and id=\"%s\"", item_data_const->id); - } - } + /* Find student named "student2" using predicate */ + { + const tsk_list_item_t *item_const = tsk_list_find_item_by_pred(list, pred_find_student_by_name, "student2"); + { + const student_t* item_data_const = item_const->data; + TSK_DEBUG_INFO("test_complex_list/// using predicate --> student with name==\"student2\" and id=\"%s\"", item_data_const->id); + } + } - /* delete all items in the list */ - TSK_OBJECT_SAFE_FREE(list); + /* delete all items in the list */ + TSK_OBJECT_SAFE_FREE(list); } #endif /* _TEST_LISTS_H_ */ diff --git a/tinySAK/test/test_md5.h b/tinySAK/test/test_md5.h index b96621a..d841516 100755 --- a/tinySAK/test/test_md5.h +++ b/tinySAK/test/test_md5.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -22,79 +22,69 @@ #ifndef _TEST_MD5_H_ #define _TEST_MD5_H_ -struct md5_result -{ - const char* msg; - const char* xres; +struct md5_result { + const char* msg; + const char* xres; }; -struct md5_result msgs_md5[] = -{ - { "x3JJHMbDL1EzLkh9GBhXDw==258EAFA5-E914-47DA-95CA-C5AB0DC85B11", "f3d129cf0d52088287dee3e6057fa18d" }, - { "", "d41d8cd98f00b204e9800998ecf8427e" }, - { "a", "0cc175b9c0f1b6a831c399e269772661" }, - { "abc", "900150983cd24fb0d6963f7d28e17f72" }, - { "message digest", "f96b697d7cb7938d525a2f31aaf161d0" }, - { "abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b" }, - { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "d174ab98d277d9f5a5611c2c9f419d9f" }, - { "12345678901234567890123456789012345678901234567890123456789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a" }, - { "The quick brown fox jumps over the lazy dog", "9e107d9d372bb6826bd81d3542a419d6" }, - { "The quick brown fox jumps over the lazy dog.", "e4d909c290d0fb1ca068ffaddf22cbd0" }, +struct md5_result msgs_md5[] = { + { "x3JJHMbDL1EzLkh9GBhXDw==258EAFA5-E914-47DA-95CA-C5AB0DC85B11", "f3d129cf0d52088287dee3e6057fa18d" }, + { "", "d41d8cd98f00b204e9800998ecf8427e" }, + { "a", "0cc175b9c0f1b6a831c399e269772661" }, + { "abc", "900150983cd24fb0d6963f7d28e17f72" }, + { "message digest", "f96b697d7cb7938d525a2f31aaf161d0" }, + { "abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b" }, + { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "d174ab98d277d9f5a5611c2c9f419d9f" }, + { "12345678901234567890123456789012345678901234567890123456789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a" }, + { "The quick brown fox jumps over the lazy dog", "9e107d9d372bb6826bd81d3542a419d6" }, + { "The quick brown fox jumps over the lazy dog.", "e4d909c290d0fb1ca068ffaddf22cbd0" }, }; void test_md5() { - size_t i; - tsk_md5string_t md5result; + size_t i; + tsk_md5string_t md5result; - for(i=0; i< sizeof(msgs_md5)/sizeof(struct md5_result); i++) - { - tsk_md5compute(msgs_md5[i].msg, strlen(msgs_md5[i].msg), &md5result); - if(tsk_striequals(msgs_md5[i].xres, md5result)) - { - TSK_DEBUG_INFO("[MD5-%d] ==> OK", i); - } - else - { - TSK_DEBUG_INFO("[MD5-%d] ==> NOK", i); - } - } + for(i=0; i< sizeof(msgs_md5)/sizeof(struct md5_result); i++) { + tsk_md5compute(msgs_md5[i].msg, strlen(msgs_md5[i].msg), &md5result); + if(tsk_striequals(msgs_md5[i].xres, md5result)) { + TSK_DEBUG_INFO("[MD5-%d] ==> OK", i); + } + else { + TSK_DEBUG_INFO("[MD5-%d] ==> NOK", i); + } + } } -struct hmac_md5_result -{ - const char* msg; - const char* key; - const char* xres; +struct hmac_md5_result { + const char* msg; + const char* key; + const char* xres; }; -struct hmac_md5_result msgs_hmac_md5[] = -{ - { "Hi There", "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", "9294727a3638bb1c13f48ef8158bfc9d" }, - { "what do ya want for nothing?", "Jefe", "750c783e6ab0b503eaa86e310a5db738" }, - { "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "56be34521d144c88dbb8c733f0e8b3f6" }, - { "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd", "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19", "697eaf0aca3a3aea3a75164746ffaa79" }, - { "Test With Truncation", "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", "56461ef2342edc00f9bab995690efd4c" }, - { "Test Using Larger Than Block-Size Key - Hash Key First", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd" }, - { "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "6f630fad67cda0ee1fb1f562db3aa53e" }, +struct hmac_md5_result msgs_hmac_md5[] = { + { "Hi There", "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", "9294727a3638bb1c13f48ef8158bfc9d" }, + { "what do ya want for nothing?", "Jefe", "750c783e6ab0b503eaa86e310a5db738" }, + { "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "56be34521d144c88dbb8c733f0e8b3f6" }, + { "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd", "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19", "697eaf0aca3a3aea3a75164746ffaa79" }, + { "Test With Truncation", "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", "56461ef2342edc00f9bab995690efd4c" }, + { "Test Using Larger Than Block-Size Key - Hash Key First", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd" }, + { "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "6f630fad67cda0ee1fb1f562db3aa53e" }, }; void test_hmac_md5() { - size_t i; - tsk_md5string_t md5result; + size_t i; + tsk_md5string_t md5result; - for(i=0; i< sizeof(msgs_hmac_md5)/sizeof(struct hmac_md5_result); i++) - { - hmac_md5_compute((const uint8_t*)msgs_hmac_md5[i].msg, strlen(msgs_hmac_md5[i].msg), msgs_hmac_md5[i].key, strlen(msgs_hmac_md5[i].key), &md5result); - if(tsk_striequals(msgs_hmac_md5[i].xres, md5result)) - { - TSK_DEBUG_INFO("[HMAC-MD5-%d] ==> OK", i); - } - else - { - TSK_DEBUG_INFO("[HMAC-MD5-%d] ==> NOK", i); - } - } + for(i=0; i< sizeof(msgs_hmac_md5)/sizeof(struct hmac_md5_result); i++) { + hmac_md5_compute((const uint8_t*)msgs_hmac_md5[i].msg, strlen(msgs_hmac_md5[i].msg), msgs_hmac_md5[i].key, strlen(msgs_hmac_md5[i].key), &md5result); + if(tsk_striequals(msgs_hmac_md5[i].xres, md5result)) { + TSK_DEBUG_INFO("[HMAC-MD5-%d] ==> OK", i); + } + else { + TSK_DEBUG_INFO("[HMAC-MD5-%d] ==> NOK", i); + } + } } diff --git a/tinySAK/test/test_mutex.h b/tinySAK/test/test_mutex.h index bc5e701..2200ba2 100755 --- a/tinySAK/test/test_mutex.h +++ b/tinySAK/test/test_mutex.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -28,53 +28,53 @@ int mutex_thread_started = 0; int safe_func(tsk_mutex_handle_t *mutex, const char* caller) { - int ret = 0; + int ret = 0; - ret = tsk_mutex_lock(mutex); - TSK_DEBUG_INFO("threadfunc_mutex/// Start doing job [%s]... %d\n", caller, ret); - tsk_thread_sleep(5000); - TSK_DEBUG_INFO("threadfunc_mutex/// Stop doing job [%s]... %d\n", caller, ret); - ret = tsk_mutex_unlock(mutex); + ret = tsk_mutex_lock(mutex); + TSK_DEBUG_INFO("threadfunc_mutex/// Start doing job [%s]... %d\n", caller, ret); + tsk_thread_sleep(5000); + TSK_DEBUG_INFO("threadfunc_mutex/// Stop doing job [%s]... %d\n", caller, ret); + ret = tsk_mutex_unlock(mutex); - return ret; + return ret; } void *threadfunc_mutex(void *parm) { - tsk_mutex_handle_t *mutex = (tsk_mutex_handle_t *)parm; - safe_func(mutex, "caller1"); + tsk_mutex_handle_t *mutex = (tsk_mutex_handle_t *)parm; + safe_func(mutex, "caller1"); - return 0; + return 0; } /* Pthread mutex */ void test_mutex() { - tsk_mutex_handle_t *mutex = tsk_mutex_create(); - void* tid[1] = {0}; + tsk_mutex_handle_t *mutex = tsk_mutex_create(); + void* tid[1] = {0}; + + TSK_DEBUG_INFO("test_mutex//\n"); + + //tsk_mutex_lock(mutex); - TSK_DEBUG_INFO("test_mutex//\n"); - - //tsk_mutex_lock(mutex); - - tsk_thread_create(&tid[0], threadfunc_mutex, mutex); - tsk_thread_sleep(1000); + tsk_thread_create(&tid[0], threadfunc_mutex, mutex); + tsk_thread_sleep(1000); - safe_func(mutex, "caller0"); + safe_func(mutex, "caller0"); - /*while(!mutex_thread_started) tsk_thread_sleep(1000); + /*while(!mutex_thread_started) tsk_thread_sleep(1000); - printf("test_mutex// threadfunc_mutex is locked for 1 second\n"); - tsk_thread_sleep(1000); + printf("test_mutex// threadfunc_mutex is locked for 1 second\n"); + tsk_thread_sleep(1000); - printf("test_mutex// Now unlock threadfunc_mutex\n"); - tsk_mutex_unlock(mutex);*/ + printf("test_mutex// Now unlock threadfunc_mutex\n"); + tsk_mutex_unlock(mutex);*/ - tsk_thread_join(&(tid[0])); + tsk_thread_join(&(tid[0])); - tsk_mutex_destroy(&mutex); + tsk_mutex_destroy(&mutex); } #endif /* _TEST_MUTEX_H_ */ diff --git a/tinySAK/test/test_object.h b/tinySAK/test/test_object.h index 8c59b46..dfca90e 100755 --- a/tinySAK/test/test_object.h +++ b/tinySAK/test/test_object.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -22,20 +22,18 @@ #if !defined(_TEST_OBJECT_H_) && 0 #define _TEST_OBJECT_H_ -typedef struct person_s -{ - TSK_DECLARE_OBJECT; // Mandatory +typedef struct person_s { + TSK_DECLARE_OBJECT; // Mandatory - char* name; - struct person_s* girlfriend; + char* name; + struct person_s* girlfriend; } person_t; // (a student is a person) -typedef struct student_s -{ - struct person_s* person; // Must be the first element - char* school; +typedef struct student_s { + struct person_s* person; // Must be the first element + char* school; } student_t; @@ -47,65 +45,64 @@ student_t; // constructor static tsk_object_t* person_create(tsk_object_t * self, va_list * app) { - person_t *person = self; - if(person){ - person->name = tsk_strdup(va_arg(*app, const char *)); - } - return self; - } + person_t *person = self; + if(person) { + person->name = tsk_strdup(va_arg(*app, const char *)); + } + return self; +} - // destructor - static tsk_object_t* person_destroy(tsk_object_t * self) - { - person_t *person = self; - if(person){ - TSK_FREE(person->name); - tsk_object_unref(person->girlfriend); - } - return self; // return - } - - // comparator - static int person_cmp(const tsk_object_t *_p1, const tsk_object_t *_p2) - { - const person_t *p1 = _p1; - const person_t *p1 = _p2; - int ret; - - // do they have the same name? - if((ret = tsk_stricmp(p1->name, p2->name))){ - return ret; - } - // do they have the same girlfriend? - if((ret = tsk_object_cmp(p1->girlfriend, p2->girlfriend))){ - return ret; - } - - // they are the same - return 0; - } +// destructor +static tsk_object_t* person_destroy(tsk_object_t * self) +{ + person_t *person = self; + if(person) { + TSK_FREE(person->name); + tsk_object_unref(person->girlfriend); + } + return self; // return +} + +// comparator +static int person_cmp(const tsk_object_t *_p1, const tsk_object_t *_p2) +{ + const person_t *p1 = _p1; + const person_t *p1 = _p2; + int ret; + + // do they have the same name? + if((ret = tsk_stricmp(p1->name, p2->name))) { + return ret; + } + // do they have the same girlfriend? + if((ret = tsk_object_cmp(p1->girlfriend, p2->girlfriend))) { + return ret; + } + + // they are the same + return 0; +} - //(Object defnition) - static const tsk_object_def_t person_def_t = - { - sizeof(person_t), - person_create, - person_destroy, - person_cmp - }; +//(Object defnition) +static const tsk_object_def_t person_def_t = { + sizeof(person_t), + person_create, + person_destroy, + person_cmp +}; - // create a person +// create a person #define PERSON_CREATE(name) tsk_object_new(&person_def_t, (const char*)name) /* test object */ void test_object() { - // creates a person: will call the constructor - person_t* bob = PERSON_CREATE("bob"); - // creates bob's girlfriend - bob->girlfriend = PERSON_CREATE("alice"); - // deletes bob: will delete both bob and bob's girlfriend field by calling their destructors - TSK_OBJECT_SAFE_FREE(bob); + // creates a person: will call the constructor + person_t* bob = PERSON_CREATE("bob"); + // creates bob's girlfriend + bob->girlfriend = PERSON_CREATE("alice"); + // deletes bob: will delete both bob and bob's girlfriend field by calling their destructors + TSK_OBJECT_SAFE_FREE(bob); } #endif /* _TEST_OBJECT_H_ */ diff --git a/tinySAK/test/test_options.h b/tinySAK/test/test_options.h index 47c8224..b707c3d 100755 --- a/tinySAK/test/test_options.h +++ b/tinySAK/test/test_options.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -22,39 +22,38 @@ #ifndef _TEST_OPTIONS_H_ #define _TEST_OPTIONS_H_ -typedef enum options_e -{ - o_project, - o_license, - o_contact, - o_version, - o_date +typedef enum options_e { + o_project, + o_license, + o_contact, + o_version, + o_date } options_t; void test_options() { - tsk_options_L_t *options = tsk_list_create(); - tsk_bool_t b; - int i; - const char* string; - const tsk_option_t* o; - - tsk_options_add_option(&options, o_project, "doubango"); - tsk_options_add_option(&options, o_project, "doubangooo"); - tsk_options_add_option(&options, o_license, "GPLv3"); - tsk_options_add_option(&options, o_contact, "Mamadou Diop <diopmamadou(at)doubango.org>"); - tsk_options_add_option(&options, o_version, "10"); + tsk_options_L_t *options = tsk_list_create(); + tsk_bool_t b; + int i; + const char* string; + const tsk_option_t* o; + + tsk_options_add_option(&options, o_project, "doubango"); + tsk_options_add_option(&options, o_project, "doubangooo"); + tsk_options_add_option(&options, o_license, "GPLv3"); + tsk_options_add_option(&options, o_contact, "Mamadou Diop <diopmamadou(at)doubango.org>"); + tsk_options_add_option(&options, o_version, "10"); + + b = tsk_options_have_option(options, o_project); + b = tsk_options_have_option(options, o_date); + tsk_options_remove_option(options, o_project); + b = tsk_options_have_option(options, o_project); + i = tsk_options_get_option_value_as_int(options, o_version); + string = tsk_options_get_option_value(options, o_version); + o = tsk_options_get_option_by_id(options, o_contact); - b = tsk_options_have_option(options, o_project); - b = tsk_options_have_option(options, o_date); - tsk_options_remove_option(options, o_project); - b = tsk_options_have_option(options, o_project); - i = tsk_options_get_option_value_as_int(options, o_version); - string = tsk_options_get_option_value(options, o_version); - o = tsk_options_get_option_by_id(options, o_contact); - - TSK_OBJECT_SAFE_FREE(options); + TSK_OBJECT_SAFE_FREE(options); } diff --git a/tinySAK/test/test_params.h b/tinySAK/test/test_params.h index 0bfd958..847bece 100755 --- a/tinySAK/test/test_params.h +++ b/tinySAK/test/test_params.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -25,43 +25,43 @@ void test_params() { - tsk_buffer_t *buffer = tsk_buffer_create_null(); - tsk_params_L_t *params = tsk_list_create(); + tsk_buffer_t *buffer = tsk_buffer_create_null(); + tsk_params_L_t *params = tsk_list_create(); + + // + // + // + tsk_param_t *param1 = tsk_params_parse_param("mamadou=diop", strlen("mamadou=diop")); + tsk_param_t *param2 = tsk_params_parse_param("project=doubango", strlen("project=doubango")); + tsk_param_t *param3 = tsk_params_parse_param("license=gpl", strlen("license=gpl")); + + tsk_list_push_back_data(params, (void**)¶m1); + tsk_list_push_back_data(params, (void**)¶m2); + tsk_list_push_back_data(params, (void**)¶m3); - // - // - // - tsk_param_t *param1 = tsk_params_parse_param("mamadou=diop", strlen("mamadou=diop")); - tsk_param_t *param2 = tsk_params_parse_param("project=doubango", strlen("project=doubango")); - tsk_param_t *param3 = tsk_params_parse_param("license=gpl", strlen("license=gpl")); - - tsk_list_push_back_data(params, (void**)¶m1); - tsk_list_push_back_data(params, (void**)¶m2); - tsk_list_push_back_data(params, (void**)¶m3); + tsk_params_tostring(params, ',', buffer); + TSK_DEBUG_INFO("Buffer=[%s]", TSK_BUFFER_TO_STRING(buffer)); - tsk_params_tostring(params, ',', buffer); - TSK_DEBUG_INFO("Buffer=[%s]", TSK_BUFFER_TO_STRING(buffer)); + tsk_buffer_cleanup(buffer); + TSK_OBJECT_SAFE_FREE(params); - tsk_buffer_cleanup(buffer); - TSK_OBJECT_SAFE_FREE(params); + // + // + // + params = tsk_params_fromstring("octet-align=1; mode-set=0,1,2,3,4,5,6,7; mode-change-period=1; mode-change-capability=2; mode-change-neighbor=0", ';', tsk_true); + tsk_params_tostring(params, ';', buffer); + TSK_DEBUG_INFO("Buffer=[%s]", TSK_BUFFER_TO_STRING(buffer)); + tsk_buffer_cleanup(buffer); + TSK_OBJECT_SAFE_FREE(params); - // - // - // - params = tsk_params_fromstring("octet-align=1; mode-set=0,1,2,3,4,5,6,7; mode-change-period=1; mode-change-capability=2; mode-change-neighbor=0", ';', tsk_true); - tsk_params_tostring(params, ';', buffer); - TSK_DEBUG_INFO("Buffer=[%s]", TSK_BUFFER_TO_STRING(buffer)); - tsk_buffer_cleanup(buffer); - TSK_OBJECT_SAFE_FREE(params); - - params = tsk_params_fromstring("QCIF=1;CIF=2;MaxBR=4200", ';', tsk_true); - tsk_params_tostring(params, ';', buffer); - TSK_DEBUG_INFO("Buffer=[%s]", TSK_BUFFER_TO_STRING(buffer)); - tsk_buffer_cleanup(buffer); - TSK_OBJECT_SAFE_FREE(params); + params = tsk_params_fromstring("QCIF=1;CIF=2;MaxBR=4200", ';', tsk_true); + tsk_params_tostring(params, ';', buffer); + TSK_DEBUG_INFO("Buffer=[%s]", TSK_BUFFER_TO_STRING(buffer)); + tsk_buffer_cleanup(buffer); + TSK_OBJECT_SAFE_FREE(params); - TSK_OBJECT_SAFE_FREE(buffer); + TSK_OBJECT_SAFE_FREE(buffer); } diff --git a/tinySAK/test/test_runnable.h b/tinySAK/test/test_runnable.h index bb99c28..3395e09 100755 --- a/tinySAK/test/test_runnable.h +++ b/tinySAK/test/test_runnable.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -22,105 +22,104 @@ #ifndef _TEST_RUNNABLE_H_ #define _TEST_RUNNABLE_H_ -typedef struct test_runnable_timer_s -{ - tsk_timer_id_t id; - uint64_t timeout; - const char *arg; +typedef struct test_runnable_timer_s { + tsk_timer_id_t id; + uint64_t timeout; + const char *arg; } test_runnable_timer_t; -test_runnable_timer_t runnable_timers[] = -{ - {0, 2000, "3"}, - {1, 2500, "4"}, - {2, 500, "1"}, - {3, 1000, "2"}, - {4, 1000, "2"}, - {5, 0, "0"}, - {6, 10000, "6"}, - {7, 3000, "5"}, - {8, 2500, "4"}, +test_runnable_timer_t runnable_timers[] = { + {0, 2000, "3"}, + {1, 2500, "4"}, + {2, 500, "1"}, + {3, 1000, "2"}, + {4, 1000, "2"}, + {5, 0, "0"}, + {6, 10000, "6"}, + {7, 3000, "5"}, + {8, 2500, "4"}, }; -typedef struct tsk_obj_s -{ - TSK_DECLARE_OBJECT; +typedef struct tsk_obj_s { + TSK_DECLARE_OBJECT; - tsk_timer_id_t timer_id; + tsk_timer_id_t timer_id; } tsk_obj_t; -static void* tsk_obj_ctor(void * self, va_list * app){ - tsk_obj_t *obj = self; - if(obj){ - obj->timer_id = va_arg(*app, tsk_timer_id_t); - } - return self; -} -static void* tsk_obj_dtor(void * self) { - return self; +static void* tsk_obj_ctor(void * self, va_list * app) +{ + tsk_obj_t *obj = self; + if(obj) { + obj->timer_id = va_arg(*app, tsk_timer_id_t); + } + return self; } -static int tsk_obj_cmp(const void *obj1, const void *obj2){ - return 0; +static void* tsk_obj_dtor(void * self) +{ + return self; } -static const tsk_object_def_t tsk_obj_def_s = +static int tsk_obj_cmp(const void *obj1, const void *obj2) { - sizeof(tsk_obj_t), - tsk_obj_ctor, - tsk_obj_dtor, - tsk_obj_cmp, + return 0; +} +static const tsk_object_def_t tsk_obj_def_s = { + sizeof(tsk_obj_t), + tsk_obj_ctor, + tsk_obj_dtor, + tsk_obj_cmp, }; const tsk_object_def_t *tsk_obj_def_t = &tsk_obj_def_s; void *run(void* self) { - int i = 0; - tsk_list_item_t *curr; - - TSK_RUNNABLE_RUN_BEGIN(self); - - if(curr = TSK_RUNNABLE_POP_FIRST(self)){ - const tsk_obj_t *obj = (const tsk_obj_t*)curr->data; - printf("\n\nRunnable event-id===>[%llu]\n\n", obj->timer_id); - tsk_object_unref(curr); - } - - TSK_RUNNABLE_RUN_END(self); - - return 0; + int i = 0; + tsk_list_item_t *curr; + + TSK_RUNNABLE_RUN_BEGIN(self); + + if(curr = TSK_RUNNABLE_POP_FIRST(self)) { + const tsk_obj_t *obj = (const tsk_obj_t*)curr->data; + printf("\n\nRunnable event-id===>[%llu]\n\n", obj->timer_id); + tsk_object_unref(curr); + } + + TSK_RUNNABLE_RUN_END(self); + + return 0; } static int test_runnable_timer_callback(const void* arg, tsk_timer_id_t timer_id) { - const tsk_runnable_t* runnable = arg; - if(runnable){ - TSK_RUNNABLE_ENQUEUE(runnable, timer_id); - return 0; - } - return -1; + const tsk_runnable_t* runnable = arg; + if(runnable) { + TSK_RUNNABLE_ENQUEUE(runnable, timer_id); + return 0; + } + return -1; } void test_runnable() { - size_t i; - tsk_timer_manager_handle_t *timer_mgr = tsk_timer_manager_create(); - tsk_runnable_t* runnable = tsk_runnable_create(); - runnable->run = run; - printf("test_runnable//\n"); - - tsk_timer_manager_start(timer_mgr); - tsk_runnable_start(runnable, tsk_obj_def_t); - - for(i=0; i<sizeof(runnable_timers)/sizeof(test_runnable_timer_t); ++i){ - runnable_timers[i].id = tsk_timer_manager_schedule(timer_mgr, runnable_timers[i].timeout, test_runnable_timer_callback, runnable); - } - - tsk_thread_sleep(4000); - - /* Stops and frees both timer manager and runnable object */ - TSK_OBJECT_SAFE_FREE(runnable); - TSK_OBJECT_SAFE_FREE(timer_mgr); + size_t i; + tsk_timer_manager_handle_t *timer_mgr = tsk_timer_manager_create(); + tsk_runnable_t* runnable = tsk_runnable_create(); + runnable->run = run; + printf("test_runnable//\n"); + + tsk_timer_manager_start(timer_mgr); + tsk_runnable_start(runnable, tsk_obj_def_t); + + for(i=0; i<sizeof(runnable_timers)/sizeof(test_runnable_timer_t); ++i) { + runnable_timers[i].id = tsk_timer_manager_schedule(timer_mgr, runnable_timers[i].timeout, test_runnable_timer_callback, runnable); + } + + tsk_thread_sleep(4000); + + /* Stops and frees both timer manager and runnable object */ + TSK_OBJECT_SAFE_FREE(runnable); + TSK_OBJECT_SAFE_FREE(timer_mgr); } #endif /* _TEST_RUNNABLE_H_ */ diff --git a/tinySAK/test/test_safeobject.h b/tinySAK/test/test_safeobject.h index 8f78ae4..48181fc 100755 --- a/tinySAK/test/test_safeobject.h +++ b/tinySAK/test/test_safeobject.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -24,67 +24,66 @@ int so_mutex_count = 0; -typedef struct mysafeobj_s -{ - TSK_DECLARE_SAFEOBJ; - - int test1; - int test2; +typedef struct mysafeobj_s { + TSK_DECLARE_SAFEOBJ; + + int test1; + int test2; } mysafeobj_t; void *threadfunc_safeobj1(void *parm) { - mysafeobj_t *safeobj = (mysafeobj_t *)parm; - int ret = 0; + mysafeobj_t *safeobj = (mysafeobj_t *)parm; + int ret = 0; - so_mutex_count++; - ret = tsk_safeobj_lock(safeobj); - printf("threadfunc_safeobj1/// %d\n", ret); + so_mutex_count++; + ret = tsk_safeobj_lock(safeobj); + printf("threadfunc_safeobj1/// %d\n", ret); - return 0; + return 0; } void *threadfunc_safeobj2(void *parm) { - mysafeobj_t *safeobj = (mysafeobj_t *)parm; - int ret = 0; + mysafeobj_t *safeobj = (mysafeobj_t *)parm; + int ret = 0; - so_mutex_count++; - ret = tsk_safeobj_lock(safeobj); - printf("threadfunc_safeobj2/// %d\n", ret); + so_mutex_count++; + ret = tsk_safeobj_lock(safeobj); + printf("threadfunc_safeobj2/// %d\n", ret); - return 0; + return 0; } /* test safeobject */ void test_safeobject() { - mysafeobj_t* obj = calloc(1, sizeof(mysafeobj_t)); - void* tid[2] = {0, 0}; - int i; + mysafeobj_t* obj = calloc(1, sizeof(mysafeobj_t)); + void* tid[2] = {0, 0}; + int i; + + printf("test_safeobject//\n"); - printf("test_safeobject//\n"); + tsk_safeobj_init(obj); - tsk_safeobj_init(obj); + //assert(!tsk_safeobj_lock(obj)); - //assert(!tsk_safeobj_lock(obj)); + tsk_thread_create(&tid[0], threadfunc_safeobj1, obj); + tsk_thread_create(&tid[1], threadfunc_safeobj2, obj); - tsk_thread_create(&tid[0], threadfunc_safeobj1, obj); - tsk_thread_create(&tid[1], threadfunc_safeobj2, obj); + /* VERY BAD */ + while(so_mutex_count<2); + for(i=0; i<10000000; i++); - /* VERY BAD */ - while(so_mutex_count<2); - for(i=0;i<10000000;i++); - - /*assert(!*/tsk_safeobj_unlock(obj)/*)*/; - /*assert(!*/tsk_safeobj_unlock(obj)/*)*/; + /*assert(!*/tsk_safeobj_unlock(obj)/*)*/; + /*assert(!*/tsk_safeobj_unlock(obj)/*)*/; - tsk_thread_join(&tid[0]); - tsk_thread_join(&tid[1]); + tsk_thread_join(&tid[0]); + tsk_thread_join(&tid[1]); - tsk_safeobj_deinit(obj); - tsk_free((void**)&obj); + tsk_safeobj_deinit(obj); + tsk_free((void**)&obj); } #endif /* _TEST_SAFEOBJ_H_ */ diff --git a/tinySAK/test/test_semaphore.h b/tinySAK/test/test_semaphore.h index 977dd9f..a2b6ebb 100755 --- a/tinySAK/test/test_semaphore.h +++ b/tinySAK/test/test_semaphore.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -24,50 +24,50 @@ void *threadfunc_semaphore1(void *parm) { - tsk_semaphore_handle_t *semaphore = (tsk_semaphore_handle_t *)parm; - int ret = 0; + tsk_semaphore_handle_t *semaphore = (tsk_semaphore_handle_t *)parm; + int ret = 0; - printf("threadfunc_semaphore1/// START %d\n", ret); - ret = tsk_semaphore_decrement(semaphore); - printf("threadfunc_semaphore1/// STOP %d\n", ret); + printf("threadfunc_semaphore1/// START %d\n", ret); + ret = tsk_semaphore_decrement(semaphore); + printf("threadfunc_semaphore1/// STOP %d\n", ret); - return 0; + return 0; } void *threadfunc_semaphore2(void *parm) { - tsk_semaphore_handle_t *semaphore = (tsk_semaphore_handle_t *)parm; - int ret = 0; + tsk_semaphore_handle_t *semaphore = (tsk_semaphore_handle_t *)parm; + int ret = 0; - printf("threadfunc_semaphore2/// START %d\n", ret); - ret = tsk_semaphore_decrement(semaphore); - printf("threadfunc_semaphore2/// STOP %d\n", ret); + printf("threadfunc_semaphore2/// START %d\n", ret); + ret = tsk_semaphore_decrement(semaphore); + printf("threadfunc_semaphore2/// STOP %d\n", ret); - return 0; + return 0; } /* Pthread semaphore */ void test_semaphore() { - tsk_semaphore_handle_t *semaphore = tsk_semaphore_create(); - void* tid[2] = {0,0}; + tsk_semaphore_handle_t *semaphore = tsk_semaphore_create(); + void* tid[2] = {0,0}; + + printf("test_semaphore//\n"); - printf("test_semaphore//\n"); + tsk_thread_create(&tid[0], threadfunc_semaphore1, semaphore); + tsk_thread_create(&tid[1], threadfunc_semaphore2, semaphore); - tsk_thread_create(&tid[0], threadfunc_semaphore1, semaphore); - tsk_thread_create(&tid[1], threadfunc_semaphore2, semaphore); + tsk_thread_sleep(1000); - tsk_thread_sleep(1000); - - assert(!tsk_semaphore_increment(semaphore)); - assert(!tsk_semaphore_increment(semaphore)); + assert(!tsk_semaphore_increment(semaphore)); + assert(!tsk_semaphore_increment(semaphore)); - tsk_thread_sleep(1000); + tsk_thread_sleep(1000); - tsk_thread_join(&tid[0]); - tsk_thread_join(&tid[1]); + tsk_thread_join(&tid[0]); + tsk_thread_join(&tid[1]); - tsk_semaphore_destroy(&semaphore); + tsk_semaphore_destroy(&semaphore); } #endif /* _TEST_SEMAPHORE_H_ */ diff --git a/tinySAK/test/test_sha1.h b/tinySAK/test/test_sha1.h index 812e6ab..f5e63b3 100755 --- a/tinySAK/test/test_sha1.h +++ b/tinySAK/test/test_sha1.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -22,80 +22,70 @@ #ifndef _TEST_SHA1_H_ #define _TEST_SHA1_H_ -struct sha1_result -{ - const char* msg; - const char* xres; +struct sha1_result { + const char* msg; + const char* xres; }; -struct sha1_result msgs[] = -{ - { "", "da39a3ee5e6b4b0d3255bfef95601890afd80709" }, - { "x3JJHMbDL1EzLkh9GBhXDw==258EAFA5-E914-47DA-95CA-C5AB0DC85B11", "1d29ab734b0c9585240069a6e4e3e91b61da1969" }, - { "The quick brown fox jumps over the lazy dog", "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" }, - { "The quick brown fox jumps over the lazy cog", "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3" }, +struct sha1_result msgs[] = { + { "", "da39a3ee5e6b4b0d3255bfef95601890afd80709" }, + { "x3JJHMbDL1EzLkh9GBhXDw==258EAFA5-E914-47DA-95CA-C5AB0DC85B11", "1d29ab734b0c9585240069a6e4e3e91b61da1969" }, + { "The quick brown fox jumps over the lazy dog", "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" }, + { "The quick brown fox jumps over the lazy cog", "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3" }, }; void test_sha1() { - size_t i; - tsk_sha1string_t sha1result; + size_t i; + tsk_sha1string_t sha1result; - for(i=0; i< sizeof(msgs)/sizeof(struct sha1_result); i++) - { - tsk_sha1compute(msgs[i].msg, strlen(msgs[i].msg), &sha1result); - if(tsk_striequals(msgs[i].xres, sha1result)) - { - TSK_DEBUG_INFO("[SHA1-%d] ==> OK", i); - } - else - { - TSK_DEBUG_INFO("[SHA1-%d] ==> NOK", i); - } - } + for(i=0; i< sizeof(msgs)/sizeof(struct sha1_result); i++) { + tsk_sha1compute(msgs[i].msg, strlen(msgs[i].msg), &sha1result); + if(tsk_striequals(msgs[i].xres, sha1result)) { + TSK_DEBUG_INFO("[SHA1-%d] ==> OK", i); + } + else { + TSK_DEBUG_INFO("[SHA1-%d] ==> NOK", i); + } + } } -struct hmac_sha1_result -{ - const char* msg; - const char* key; - const char* xres; +struct hmac_sha1_result { + const char* msg; + const char* key; + const char* xres; }; -struct hmac_sha1_result hmac_sha1_msgs[] = -{ - { "Hi There", "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", "b617318655057264e28bc0b6fb378c8ef146be00" }, - { "what do ya want for nothing?", "Jefe", "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79" }, - { "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "125d7342b9ac11cd91a39af48aa17b4f63f175d3" }, - { "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd", "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19", "4c9007f4026250c6bc8414f9bf50c86c2d7235da" }, - { "Test With Truncation", "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04" }, - { "Test Using Larger Than Block-Size Key - Hash Key First", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "aa4ae5e15272d00e95705637ce8a3b55ed402112" }, - { "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "e8e99d0f45237d786d6bbaa7965c7808bbff1a91" }, +struct hmac_sha1_result hmac_sha1_msgs[] = { + { "Hi There", "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", "b617318655057264e28bc0b6fb378c8ef146be00" }, + { "what do ya want for nothing?", "Jefe", "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79" }, + { "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "125d7342b9ac11cd91a39af48aa17b4f63f175d3" }, + { "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd", "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19", "4c9007f4026250c6bc8414f9bf50c86c2d7235da" }, + { "Test With Truncation", "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04" }, + { "Test Using Larger Than Block-Size Key - Hash Key First", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "aa4ae5e15272d00e95705637ce8a3b55ed402112" }, + { "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "e8e99d0f45237d786d6bbaa7965c7808bbff1a91" }, }; void test_hmac_sha1() { - size_t i; - tsk_sha1string_t sha1result; + size_t i; + tsk_sha1string_t sha1result; - // const uint8_t* bytes = "\x00\x01\x00\x3c\x21\x12\xa4\x42\x33\x6f\x57\x50\x31\x4f\x4d\x65\x65\x58\x73\x7a\x00\x06\x00\x20\x33\x68\x50\x30\x6f\x53\x7a\x6b\x48\x75\x33\x52\x56\x2f\x4c\x35\x48\x49\x78\x49\x70\x34\x73\x55\x46\x47\x73\x38\x55\x6a\x4b\x57\x00\x08\x00\x14\x21\xee\x75\x15\xc0\x9c\x0a\x90\xf2\xf3\xa5\x3e\x22\x00\x0c\xd3\xd5\xc0\x2c\x82"; - //const uint8_t* bytes = "\x00\x01\x00\x24\x21\x12\xa4\x42\x33\x6f\x57\x50\x31\x4f\x4d\x65\x65\x58\x73\x7a\x00\x06\x00\x20\x33\x68\x50\x30\x6f\x53\x7a\x6b\x48\x75\x33\x52\x56\x2f\x4c\x35\x48\x49\x78\x49\x70\x34\x73\x55\x46\x47\x73\x38\x55\x6a\x4b\x57\x00\x08\x00\x14\x21\xee\x75\x15\xc0\x9c\x0a\x90\xf2\xf3\xa5\x3e\x22\x00\x0c\xd3\xd5\xc0\x2c\x82"; + // const uint8_t* bytes = "\x00\x01\x00\x3c\x21\x12\xa4\x42\x33\x6f\x57\x50\x31\x4f\x4d\x65\x65\x58\x73\x7a\x00\x06\x00\x20\x33\x68\x50\x30\x6f\x53\x7a\x6b\x48\x75\x33\x52\x56\x2f\x4c\x35\x48\x49\x78\x49\x70\x34\x73\x55\x46\x47\x73\x38\x55\x6a\x4b\x57\x00\x08\x00\x14\x21\xee\x75\x15\xc0\x9c\x0a\x90\xf2\xf3\xa5\x3e\x22\x00\x0c\xd3\xd5\xc0\x2c\x82"; + //const uint8_t* bytes = "\x00\x01\x00\x24\x21\x12\xa4\x42\x33\x6f\x57\x50\x31\x4f\x4d\x65\x65\x58\x73\x7a\x00\x06\x00\x20\x33\x68\x50\x30\x6f\x53\x7a\x6b\x48\x75\x33\x52\x56\x2f\x4c\x35\x48\x49\x78\x49\x70\x34\x73\x55\x46\x47\x73\x38\x55\x6a\x4b\x57\x00\x08\x00\x14\x21\xee\x75\x15\xc0\x9c\x0a\x90\xf2\xf3\xa5\x3e\x22\x00\x0c\xd3\xd5\xc0\x2c\x82"; - //hmac_sha1_compute(bytes, 56, "tLzlCDl+o9yiWkp3", tsk_strlen("tLzlCDl+o9yiWkp3"), &sha1result); + //hmac_sha1_compute(bytes, 56, "tLzlCDl+o9yiWkp3", tsk_strlen("tLzlCDl+o9yiWkp3"), &sha1result); - for(i=0; i< sizeof(hmac_sha1_msgs)/sizeof(struct hmac_sha1_result); i++) - { - hmac_sha1_compute((const uint8_t*)hmac_sha1_msgs[i].msg, strlen(hmac_sha1_msgs[i].msg), hmac_sha1_msgs[i].key, strlen(hmac_sha1_msgs[i].key), &sha1result); - if(tsk_striequals(hmac_sha1_msgs[i].xres, sha1result)) - { - TSK_DEBUG_INFO("[SHA1-%d] ==> OK", i); - } - else - { - TSK_DEBUG_INFO("[SHA1-%d] ==> NOK", i); - } - } + for(i=0; i< sizeof(hmac_sha1_msgs)/sizeof(struct hmac_sha1_result); i++) { + hmac_sha1_compute((const uint8_t*)hmac_sha1_msgs[i].msg, strlen(hmac_sha1_msgs[i].msg), hmac_sha1_msgs[i].key, strlen(hmac_sha1_msgs[i].key), &sha1result); + if(tsk_striequals(hmac_sha1_msgs[i].xres, sha1result)) { + TSK_DEBUG_INFO("[SHA1-%d] ==> OK", i); + } + else { + TSK_DEBUG_INFO("[SHA1-%d] ==> NOK", i); + } + } } diff --git a/tinySAK/test/test_strings.h b/tinySAK/test/test_strings.h index 2ba0391..03fe988 100755 --- a/tinySAK/test/test_strings.h +++ b/tinySAK/test/test_strings.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -25,51 +25,51 @@ /* test string manipulation */ void test_strings() { - char* str = tsk_null; - int index; + char* str = tsk_null; + int index; + + /* IndexOf */ + index = tsk_strindexOf("C:\\test.zip", 5, "\\"); + index = tsk_strindexOf("C:\\test.zip", tsk_strlen("C:\\test.zip"), "abc"); + index = tsk_strLastIndexOf("C:\\my dirctory\\test.zip", tsk_strlen("C:\\my dirctory\test.zip"), "\\"); + index = tsk_strLastIndexOf("C:\\my dirctory\\test.zip", tsk_strlen("C:\\my dirctory\test.zip"), "."); + + /* LastIndexOf */ - /* IndexOf */ - index = tsk_strindexOf("C:\\test.zip", 5, "\\"); - index = tsk_strindexOf("C:\\test.zip", tsk_strlen("C:\\test.zip"), "abc"); - index = tsk_strLastIndexOf("C:\\my dirctory\\test.zip", tsk_strlen("C:\\my dirctory\test.zip"), "\\"); - index = tsk_strLastIndexOf("C:\\my dirctory\\test.zip", tsk_strlen("C:\\my dirctory\test.zip"), "."); + /* concatenation */ + tsk_strcat(&str, " first "); + printf("test_strings/// strcat=%s\n", str); - /* LastIndexOf */ - - /* concatenation */ - tsk_strcat(&str, " first "); - printf("test_strings/// strcat=%s\n", str); + /* Trim Right */ + tsk_strtrim_right(&str); + printf("test_strings/// trim_right=%s\n", str); - /* Trim Right */ - tsk_strtrim_right(&str); - printf("test_strings/// trim_right=%s\n", str); + tsk_strcat(&str, "second"); + printf("test_strings/// strcat=%s\n", str); - tsk_strcat(&str, "second"); - printf("test_strings/// strcat=%s\n", str); + /* Trim Left */ + tsk_strtrim_left(&str); + printf("test_strings/// trim_left=%s\n", str); - /* Trim Left */ - tsk_strtrim_left(&str); - printf("test_strings/// trim_left=%s\n", str); + tsk_free((void**)&str); - tsk_free((void**)&str); - - /* sprintf */ - tsk_sprintf(&str, " \n\t%s %s\r ", "first", "second"); - printf("test_strings/// strcat=\"%s\"\n", str); + /* sprintf */ + tsk_sprintf(&str, " \n\t%s %s\r ", "first", "second"); + printf("test_strings/// strcat=\"%s\"\n", str); - /* Trim Both */ - tsk_strtrim_both(&str); - printf("test_strings/// trim_both=%s\n", str); + /* Trim Both */ + tsk_strtrim_both(&str); + printf("test_strings/// trim_both=%s\n", str); - /* Quote */ - tsk_strquote(&str); - printf("test_strings/// quote=%s\n", str); + /* Quote */ + tsk_strquote(&str); + printf("test_strings/// quote=%s\n", str); - /* Unquote */ - tsk_strunquote(&str); - printf("test_strings/// unquote=%s\n", str); + /* Unquote */ + tsk_strunquote(&str); + printf("test_strings/// unquote=%s\n", str); - tsk_free((void**)&str); + tsk_free((void**)&str); } #endif /* _TEST_STRINGS_H_ */ diff --git a/tinySAK/test/test_threads.h b/tinySAK/test/test_threads.h index 5d23a69..354fce7 100755 --- a/tinySAK/test/test_threads.h +++ b/tinySAK/test/test_threads.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou@yahoo.fr> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -27,22 +27,22 @@ void* MyThreadFunction(void *arg) { - printf("arg=%d", *((int*)arg)); - return tsk_null; + printf("arg=%d", *((int*)arg)); + return tsk_null; } void test_threads() { - void* tid[1] = {tsk_null}; // thread id - int arg = 112; // arg to pass to the function + void* tid[1] = {tsk_null}; // thread id + int arg = 112; // arg to pass to the function + + printf("test_threads//\n"); - printf("test_threads//\n"); - - // create the thread - tsk_thread_create(&tid[0], MyThreadFunction, &arg); + // create the thread + tsk_thread_create(&tid[0], MyThreadFunction, &arg); - // join the thread - tsk_thread_join(&(tid[0])); + // join the thread + tsk_thread_join(&(tid[0])); } #endif /* _TEST_THREADS_H_ */ diff --git a/tinySAK/test/test_timer.h b/tinySAK/test/test_timer.h index 2b7ab4f..8f28b0c 100755 --- a/tinySAK/test/test_timer.h +++ b/tinySAK/test/test_timer.h @@ -2,103 +2,101 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * */ #ifndef _TEST_TIMER_H_ #define _TEST_TIMER_H_ -typedef struct test_timer_s -{ - tsk_timer_id_t id; - uint64_t timeout; - const char *arg; +typedef struct test_timer_s { + tsk_timer_id_t id; + uint64_t timeout; + const char *arg; } test_timer_t; -test_timer_t timers[] = -{ - {0, 2000, "3"}, - {1, 2500, "4"}, - {2, 500, "1"}, - {3, 1000, "2"}, - {4, 1000, "2"}, - {5, 0, "0"}, - {6, 10000, "6"}, - {7, 3000, "5"}, - {8, 2500, "4"}, +test_timer_t timers[] = { + {0, 2000, "3"}, + {1, 2500, "4"}, + {2, 500, "1"}, + {3, 1000, "2"}, + {4, 1000, "2"}, + {5, 0, "0"}, + {6, 10000, "6"}, + {7, 3000, "5"}, + {8, 2500, "4"}, }; static int test_timer_callback(const void* arg, tsk_timer_id_t timer_id) { - // Do quick job - printf("test_timer - id=%llu and arg=%s//\n", timer_id, arg); - return 0; + // Do quick job + printf("test_timer - id=%llu and arg=%s//\n", timer_id, arg); + return 0; } void test_global_timer() { - size_t i; - tsk_timer_mgr_global_ref(); + size_t i; + tsk_timer_mgr_global_ref(); - // for test: start it two times - tsk_timer_mgr_global_start(); - tsk_timer_mgr_global_start(); + // for test: start it two times + tsk_timer_mgr_global_start(); + tsk_timer_mgr_global_start(); - for(i=0; i<sizeof(timers)/sizeof(test_timer_t); ++i){ - timers[i].id = tsk_timer_mgr_global_schedule(timers[i].timeout, test_timer_callback, timers[i].arg); - } + for(i=0; i<sizeof(timers)/sizeof(test_timer_t); ++i) { + timers[i].id = tsk_timer_mgr_global_schedule(timers[i].timeout, test_timer_callback, timers[i].arg); + } - tsk_timer_mgr_global_cancel(timers[6].id); - tsk_timer_mgr_global_cancel(timers[2].id); + tsk_timer_mgr_global_cancel(timers[6].id); + tsk_timer_mgr_global_cancel(timers[2].id); - tsk_thread_sleep(4000); + tsk_thread_sleep(4000); - // for test: stop it only one time - tsk_timer_mgr_global_stop(); - tsk_timer_mgr_global_stop(); + // for test: stop it only one time + tsk_timer_mgr_global_stop(); + tsk_timer_mgr_global_stop(); - tsk_timer_mgr_global_unref(); + tsk_timer_mgr_global_unref(); } void test_single_timer() { - size_t i; - tsk_timer_manager_handle_t *handle = tsk_timer_manager_create(); - printf("test_timer//\n"); - - tsk_timer_manager_start(handle); - - for(i=0; i<sizeof(timers)/sizeof(test_timer_t); ++i){ - timers[i].id = tsk_timer_manager_schedule(handle, timers[i].timeout, test_timer_callback, timers[i].arg); - } - - tsk_timer_manager_cancel(handle, timers[6].id); - tsk_timer_manager_cancel(handle, timers[2].id); - - tsk_thread_sleep(4000); - - /* Stops and frees the timer manager */ - TSK_OBJECT_SAFE_FREE(handle); + size_t i; + tsk_timer_manager_handle_t *handle = tsk_timer_manager_create(); + printf("test_timer//\n"); + + tsk_timer_manager_start(handle); + + for(i=0; i<sizeof(timers)/sizeof(test_timer_t); ++i) { + timers[i].id = tsk_timer_manager_schedule(handle, timers[i].timeout, test_timer_callback, timers[i].arg); + } + + tsk_timer_manager_cancel(handle, timers[6].id); + tsk_timer_manager_cancel(handle, timers[2].id); + + tsk_thread_sleep(4000); + + /* Stops and frees the timer manager */ + TSK_OBJECT_SAFE_FREE(handle); } void test_timer() { - //test_single_timer(); - test_global_timer(); + //test_single_timer(); + test_global_timer(); } #endif /* _TEST_TIMER_H_ */ diff --git a/tinySAK/test/test_url.h b/tinySAK/test/test_url.h index 643cb34..ef41bd4 100755 --- a/tinySAK/test/test_url.h +++ b/tinySAK/test/test_url.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -25,19 +25,19 @@ /* url encoding/decoding */ void test_url() { - const char *url = "http://xcap.example.org/resource-lists/users/sip:RCSUser@example.org/index/~~/resource-lists/list%5B@name=%22rcs%22%5D"; - char *str1, *str2; + const char *url = "http://xcap.example.org/resource-lists/users/sip:RCSUser@example.org/index/~~/resource-lists/list%5B@name=%22rcs%22%5D"; + char *str1, *str2; - /*decode url*/ - str1 = tsk_url_decode(url); - printf("test_url/// decoded url:%s\n", str1); + /*decode url*/ + str1 = tsk_url_decode(url); + printf("test_url/// decoded url:%s\n", str1); - /*encode url*/ - str2 = tsk_url_encode(str1); - printf("test_url/// encoded url:%s\n", str2); + /*encode url*/ + str2 = tsk_url_encode(str1); + printf("test_url/// encoded url:%s\n", str2); - tsk_free((void**)&str1); - tsk_free((void**)&str2); + tsk_free((void**)&str1); + tsk_free((void**)&str2); } #endif /* _TEST_URL_H_ */ diff --git a/tinySAK/test/test_uuid.h b/tinySAK/test/test_uuid.h index 7656b8f..7c54ec2 100755 --- a/tinySAK/test/test_uuid.h +++ b/tinySAK/test/test_uuid.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou@yahoo.fr> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -24,11 +24,11 @@ void test_uuid() { - tsk_uuidstring_t uuid; + tsk_uuidstring_t uuid; - tsk_uuidgenerate(&uuid); + tsk_uuidgenerate(&uuid); - TSK_DEBUG_INFO("Generated UUID: %s", uuid); + TSK_DEBUG_INFO("Generated UUID: %s", uuid); } #endif /* _TEST_UUID_H_ */ |