xref: /freebsd/contrib/expat/tests/runtests.c (revision f126890a)
1 /* Run the Expat test suite
2                             __  __            _
3                          ___\ \/ /_ __   __ _| |_
4                         / _ \\  /| '_ \ / _` | __|
5                        |  __//  \| |_) | (_| | |_
6                         \___/_/\_\ .__/ \__,_|\__|
7                                  |_| XML parser
8 
9    Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
10    Copyright (c) 2003      Greg Stein <gstein@users.sourceforge.net>
11    Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
12    Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
13    Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org>
14    Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
15    Copyright (c) 2017      Joe Orton <jorton@redhat.com>
16    Copyright (c) 2017      José Gutiérrez de la Concha <jose@zeroc.com>
17    Copyright (c) 2018      Marco Maggi <marco.maggi-ipsu@poste.it>
18    Copyright (c) 2019      David Loffredo <loffredo@steptools.com>
19    Copyright (c) 2020      Tim Gates <tim.gates@iress.com>
20    Copyright (c) 2021      Donghee Na <donghee.na@python.org>
21    Copyright (c) 2022      Sean McBride <sean@rogue-research.com>
22    Copyright (c) 2023      Sony Corporation / Snild Dolkow <snild@sony.com>
23    Licensed under the MIT license:
24 
25    Permission is  hereby granted,  free of charge,  to any  person obtaining
26    a  copy  of  this  software   and  associated  documentation  files  (the
27    "Software"),  to  deal in  the  Software  without restriction,  including
28    without  limitation the  rights  to use,  copy,  modify, merge,  publish,
29    distribute, sublicense, and/or sell copies of the Software, and to permit
30    persons  to whom  the Software  is  furnished to  do so,  subject to  the
31    following conditions:
32 
33    The above copyright  notice and this permission notice  shall be included
34    in all copies or substantial portions of the Software.
35 
36    THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
37    EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
38    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
39    NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
40    DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
41    OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
42    USE OR OTHER DEALINGS IN THE SOFTWARE.
43 */
44 
45 #include "expat_config.h"
46 
47 #include <stdio.h>
48 #include <string.h>
49 
50 #include "expat.h"
51 #include "internal.h"
52 #include "minicheck.h"
53 #include "common.h"
54 
55 #include "basic_tests.h"
56 #include "ns_tests.h"
57 #include "misc_tests.h"
58 #include "alloc_tests.h"
59 #include "nsalloc_tests.h"
60 #include "acc_tests.h"
61 
62 XML_Parser g_parser = NULL;
63 
64 static Suite *
65 make_suite(void) {
66   Suite *s = suite_create("basic");
67 
68   make_basic_test_case(s);
69   make_namespace_test_case(s);
70   make_miscellaneous_test_case(s);
71   make_alloc_test_case(s);
72   make_nsalloc_test_case(s);
73 #if XML_GE == 1
74   make_accounting_test_case(s);
75 #endif
76 
77   return s;
78 }
79 
80 int
81 main(int argc, char *argv[]) {
82   int i, nf;
83   int verbosity = CK_NORMAL;
84   Suite *s = make_suite();
85   SRunner *sr = srunner_create(s);
86 
87   for (i = 1; i < argc; ++i) {
88     char *opt = argv[i];
89     if (strcmp(opt, "-v") == 0 || strcmp(opt, "--verbose") == 0)
90       verbosity = CK_VERBOSE;
91     else if (strcmp(opt, "-q") == 0 || strcmp(opt, "--quiet") == 0)
92       verbosity = CK_SILENT;
93     else {
94       fprintf(stderr, "runtests: unknown option '%s'\n", opt);
95       return 2;
96     }
97   }
98   if (verbosity != CK_SILENT)
99     printf("Expat version: %" XML_FMT_STR "\n", XML_ExpatVersion());
100 
101   for (g_chunkSize = 0; g_chunkSize <= 5; g_chunkSize++) {
102     for (int enabled = 0; enabled <= 1; ++enabled) {
103       char context[100];
104       g_reparseDeferralEnabledDefault = enabled;
105       snprintf(context, sizeof(context), "chunksize=%d deferral=%d",
106                g_chunkSize, enabled);
107       context[sizeof(context) - 1] = '\0';
108       srunner_run_all(sr, context, verbosity);
109     }
110   }
111   srunner_summarize(sr, verbosity);
112   nf = srunner_ntests_failed(sr);
113   srunner_free(sr);
114 
115   return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
116 }
117