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