Debian Codegraph @

Xpjproject/pjlib/src/pjlib-test/main.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
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
21 #include <pj/string.h>
22 #include <pj/sock.h>
23 #include <pj/log.h>
24 #include <pj/unittest.h>
25 #include <stdio.h>
26
27 //#if defined(PJ_WIN32) && PJ_WIN32!=0
28 #if 0
29 #include <windows.h>
30 static void boost(void)
31 {
32 SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
33 }
34 #else
35 #define boost()
36 #endif
37
38
39 static void usage()
40 {
41 puts("Usage:");
42 puts(" pjlib-test [OPTION] [test_to_run] [..]");
43 puts("");
44 puts("where OPTIONS:");
45 puts("");
46 puts(" -h, --help Show this help screen");
47
48 ut_usage();
49
50 puts(" --skip-e Skip essential tests");
51 puts(" -i Ask ENTER before quitting");
52 puts(" -p PORT Use port PORT for echo port");
53 puts(" -s SERVER Use SERVER as ech oserver");
54 puts(" -t ucp,tcp Set echo socket type to UDP or TCP");
55 }
56
57
58 int main(int argc, char *argv[])
59 {
60 int rc;
61 int interractive = 0;
62
63 boost();
64 ut_app_init0(&test_app.ut_app);
65
66 /*
67 * Parse arguments
68 */
69 if (pj_argparse_get_bool(&argc, argv, "-h") ||
70 pj_argparse_get_bool(&argc, argv, "--help"))
71 {
72 usage();
73 return 0;
74 }
75 interractive = pj_argparse_get_bool(&argc, argv, "-i");
76 if (pj_argparse_get_int(&argc, argv, "-p", &test_app.param_echo_port)) {
77 usage();
78 return 1;
79 }
80 if (pj_argparse_get_str(&argc, argv, "-s",
81 (char**)&test_app.param_echo_server))
82 {
83 usage();
84 return 1;
85 }
86
87 if (pj_argparse_exists(argv, "-t")) {
88 char *sock_type;
89 if (pj_argparse_get_str(&argc, argv, "-t", &sock_type)==PJ_SUCCESS) {
90 if (pj_ansi_stricmp(sock_type, "tcp")==0)
91 test_app.param_echo_sock_type = pj_SOCK_STREAM();
92 else if (pj_ansi_stricmp(sock_type, "udp")==0)
93 test_app.param_echo_sock_type = pj_SOCK_DGRAM();
94 else {
95 printf("Error: unknown socket type %s for -t option\n",
96 sock_type);
97 usage();
98 return 1;
99 }
100 } else {
101 usage();
102 return 1;
103 }
104 }
105
106 if (ut_parse_args(&test_app.ut_app, &argc, argv)) {
107 usage();
108 return 1;
109 }
110 test_app.param_skip_essentials = pj_argparse_get_bool(&argc, argv,
111 "--skip-e");
112
113
114 if (pj_argparse_peek_next_option(argv)) {
115 printf("Error: unknown argument %s\n",
116 pj_argparse_peek_next_option(argv));
117 usage();
118 return 1;
119 }
120
121 /* argc/argv now contains option values only, if any */
122 rc = test_main(argc, argv);
123
124 if (interractive) {
125 char s[10];
126 puts("");
127 puts("Press <ENTER> to exit");
128 if (!fgets(s, sizeof(s), stdin))
129 return rc;
130 }
131
132 return rc;
133 }
134