Tristan Matthews | 0a329cc | 2013-07-17 13:20:14 -0400 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) |
| 4 | * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | #include "test.h" |
| 21 | #include <pjlib.h> |
| 22 | #include <pjlib-util.h> |
| 23 | |
| 24 | void app_perror(const char *msg, pj_status_t rc) |
| 25 | { |
| 26 | char errbuf[256]; |
| 27 | |
| 28 | PJ_CHECK_STACK(); |
| 29 | |
| 30 | pj_strerror(rc, errbuf, sizeof(errbuf)); |
| 31 | PJ_LOG(1,("test", "%s: [pj_status_t=%d] %s", msg, rc, errbuf)); |
| 32 | } |
| 33 | |
| 34 | #define DO_TEST(test) do { \ |
| 35 | PJ_LOG(3, ("test", "Running %s...", #test)); \ |
| 36 | rc = test; \ |
| 37 | PJ_LOG(3, ("test", \ |
| 38 | "%s(%d)", \ |
| 39 | (char*)(rc ? "..ERROR" : "..success"), rc)); \ |
| 40 | if (rc!=0) goto on_return; \ |
| 41 | } while (0) |
| 42 | |
| 43 | |
| 44 | pj_pool_factory *mem; |
| 45 | |
| 46 | int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | |
| 47 | PJ_LOG_HAS_MICRO_SEC; |
| 48 | |
| 49 | static int test_inner(void) |
| 50 | { |
| 51 | pj_caching_pool caching_pool; |
| 52 | int rc = 0; |
| 53 | |
| 54 | mem = &caching_pool.factory; |
| 55 | |
| 56 | pj_log_set_level(3); |
| 57 | pj_log_set_decor(param_log_decor); |
| 58 | |
| 59 | rc = pj_init(); |
| 60 | if (rc != 0) { |
| 61 | app_perror("pj_init() error!!", rc); |
| 62 | return rc; |
| 63 | } |
| 64 | |
| 65 | rc = pjlib_util_init(); |
| 66 | pj_assert(rc == 0); |
| 67 | |
| 68 | pj_dump_config(); |
| 69 | pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 ); |
| 70 | |
| 71 | #if INCLUDE_XML_TEST |
| 72 | DO_TEST(xml_test()); |
| 73 | #endif |
| 74 | |
| 75 | #if INCLUDE_ENCRYPTION_TEST |
| 76 | DO_TEST(encryption_test()); |
| 77 | DO_TEST(encryption_benchmark()); |
| 78 | #endif |
| 79 | |
| 80 | #if INCLUDE_STUN_TEST |
| 81 | DO_TEST(stun_test()); |
| 82 | #endif |
| 83 | |
| 84 | #if INCLUDE_RESOLVER_TEST |
| 85 | DO_TEST(resolver_test()); |
| 86 | #endif |
| 87 | |
| 88 | #if INCLUDE_HTTP_CLIENT_TEST |
| 89 | DO_TEST(http_client_test()); |
| 90 | #endif |
| 91 | |
| 92 | on_return: |
| 93 | return rc; |
| 94 | } |
| 95 | |
| 96 | int test_main(void) |
| 97 | { |
| 98 | PJ_USE_EXCEPTION; |
| 99 | |
| 100 | PJ_TRY { |
| 101 | return test_inner(); |
| 102 | } |
| 103 | PJ_CATCH_ANY { |
| 104 | int id = PJ_GET_EXCEPTION(); |
| 105 | PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)", |
| 106 | id, pj_exception_id_name(id))); |
| 107 | } |
| 108 | PJ_END; |
| 109 | |
| 110 | return -1; |
| 111 | } |
| 112 | |