File: tests.c

package info (click to toggle)
proftpd-dfsg 1.3.3a-6squeeze7
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 19,868 kB
  • ctags: 10,217
  • sloc: ansic: 111,549; perl: 94,506; sh: 17,265; makefile: 1,986
file content (180 lines) | stat: -rw-r--r-- 5,200 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * ProFTPD - FTP server testsuite
 * Copyright (c) 2008 The ProFTPD Project team
 *
 * This program 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
 *
 * As a special exemption, The ProFTPD Project team and other respective
 * copyright holders give permission to link this program with OpenSSL, and
 * distribute the resulting executable, without including the source code for
 * OpenSSL in the source distribution.
 */

#include "tests.h"

struct testsuite_info {
  const char *name;
  Suite *(*get_suite)(void);
};

static struct testsuite_info suites[] = {
  { "pool", 	tests_get_pool_suite },
  { "array", 	tests_get_array_suite },
  { "str", 	tests_get_str_suite },
  { "sets", 	tests_get_sets_suite },
  { "timers", 	tests_get_timers_suite },
  { "table", 	tests_get_table_suite },
  { "var", 	tests_get_var_suite },
  { "event", 	tests_get_event_suite },
  { "env", 	tests_get_env_suite },
  { "version", 	tests_get_version_suite },
  { "feat", 	tests_get_feat_suite },
  { "netaddr", 	tests_get_netaddr_suite },
  { "netacl",	tests_get_netacl_suite },
  { "class",	tests_get_class_suite },
  { "regexp",	tests_get_regexp_suite },
  { "expr",	tests_get_expr_suite },
  { "scoreboard",	tests_get_scoreboard_suite },
  { "modules",	tests_get_modules_suite },

  { NULL, NULL }
};

static Suite *tests_get_suite(const char *suite) { 
  if (strcmp(suite, "pool") == 0) { 
    return tests_get_pool_suite();
 
  } else if (strcmp(suite, "array") == 0) {
    return tests_get_array_suite(); 

  } else if (strcmp(suite, "str") == 0) {
    return tests_get_str_suite(); 

  } else if (strcmp(suite, "sets") == 0) {
    return tests_get_sets_suite(); 

  } else if (strcmp(suite, "timers") == 0) {
    return tests_get_timers_suite(); 

  } else if (strcmp(suite, "table") == 0) {
    return tests_get_table_suite(); 

  } else if (strcmp(suite, "var") == 0) {
    return tests_get_var_suite(); 

  } else if (strcmp(suite, "event") == 0) {
    return tests_get_event_suite(); 

  } else if (strcmp(suite, "version") == 0) {
    return tests_get_version_suite(); 

  } else if (strcmp(suite, "env") == 0) {
    return tests_get_env_suite(); 

  } else if (strcmp(suite, "feat") == 0) {
    return tests_get_feat_suite(); 

  } else if (strcmp(suite, "netaddr") == 0) {
    return tests_get_netaddr_suite(); 

  } else if (strcmp(suite, "netacl") == 0) {
    return tests_get_netacl_suite();

  } else if (strcmp(suite, "class") == 0) {
    return tests_get_class_suite();

  } else if (strcmp(suite, "regexp") == 0) {
    return tests_get_regexp_suite();

  } else if (strcmp(suite, "expr") == 0) {
    return tests_get_expr_suite();

  } else if (strcmp(suite, "scoreboard") == 0) {
    return tests_get_scoreboard_suite();

  } else if (strcmp(suite, "modules") == 0) {
    return tests_get_modules_suite();
  }

  return NULL;
}

int main(int argc, char *argv[]) {
  const char *log_file = "api-tests.log";
  int nfailed = 0;
  SRunner *runner = NULL;
  char *requested = NULL;

  runner = srunner_create(NULL);

  /* XXX This log name should be set outside this code, e.g. via environment
   * variable or command-line option.
   */
  srunner_set_log(runner, log_file);

  requested = getenv("PR_TEST_SUITE");
  if (requested) {
    Suite *suite;

    suite = tests_get_suite(requested);
    if (suite) {
      srunner_add_suite(runner, suite);

    } else {
      fprintf(stderr, "No such test suite ('%s') requested via PR_TEST_SUITE\n",
        requested);
      return EXIT_FAILURE;
    }

  } else {
    register unsigned int i;

    for (i = 0; suites[i].name; i++) {
      Suite *suite;

      suite = (suites[i].get_suite)();
      if (suite) {
        srunner_add_suite(runner, suite);
      }
    }
  }

  requested = getenv("PR_TEST_NOFORK");
  if (requested) {
    srunner_set_fork_status(runner, CK_NOFORK);
  }

  srunner_run_all(runner, CK_NORMAL);

  nfailed = srunner_ntests_failed(runner);

  if (runner)
    srunner_free(runner);

  if (nfailed != 0) {
    fprintf(stderr, "-------------------------------------------------\n");
    fprintf(stderr, " FAILED %d %s\n\n", nfailed,
      nfailed != 1 ? "tests" : "test");
    fprintf(stderr, " Please send email to:\n\n");
    fprintf(stderr, "   proftp-devel@lists.sourceforge.net\n\n");
    fprintf(stderr, " containing the `%s' file (in the tests/ directory)\n", log_file);
    fprintf(stderr, " and the output from running `proftpd -V'\n");
    fprintf(stderr, "-------------------------------------------------\n");

    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}