1 /* Copyright (c) 2009, 2021, Oracle and/or its affiliates.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 // First include (the generated) my_config.h, to get correct platform defines.
24 #include "my_config.h"
25 #include <gtest/gtest.h>
26 #include <gmock/gmock.h>
27 
28 #include "my_getopt.h"
29 #include "my_thread_local.h"
30 
31 #include <stdlib.h>
32 
33 class Cost_constant_cache;
34 
35 namespace {
36 
37 my_bool opt_use_tap= true;
38 my_bool opt_unit_help= false;
39 
40 struct my_option unittest_options[] =
41 {
42   { "tap-output", 1, "TAP (default) or gunit output.",
43     &opt_use_tap, &opt_use_tap, NULL,
44     GET_BOOL, OPT_ARG,
45     opt_use_tap, 0, 1, 0,
46     0, NULL
47   },
48   { "help", 2, "Help.",
49     &opt_unit_help, &opt_unit_help, NULL,
50     GET_BOOL, NO_ARG,
51     opt_unit_help, 0, 1, 0,
52     0, NULL
53   },
54   {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
55 };
56 
57 
get_one_option(int,const struct my_option *,char *)58 extern "C" my_bool get_one_option(int, const struct my_option *, char *)
59 {
60   return FALSE;
61 }
62 
63 }  // namespace
64 
65 // Some globals needed for merge_small_tests.cc
66 mysql_mutex_t LOCK_open;
67 uint    opt_debug_sync_timeout= 0;
68 thread_local_key_t THR_MALLOC;
69 thread_local_key_t THR_THD;
70 bool THR_THD_initialized= false;
71 bool THR_MALLOC_initialized= false;
72 // Needed for linking with opt_costconstantcache.cc and Fake_Cost_model_server
73 Cost_constant_cache *cost_constant_cache= NULL;
74 
sql_alloc_error_handler(void)75 extern "C" void sql_alloc_error_handler(void)
76 {
77   ADD_FAILURE();
78 }
79 
80 
81 extern void install_tap_listener();
82 
main(int argc,char ** argv)83 int main(int argc, char **argv)
84 {
85   ::testing::InitGoogleTest(&argc, argv);
86   ::testing::InitGoogleMock(&argc, argv);
87   MY_INIT(argv[0]);
88 
89   if (handle_options(&argc, &argv, unittest_options, get_one_option))
90     return EXIT_FAILURE;
91   if (opt_use_tap)
92     install_tap_listener();
93   if (opt_unit_help)
94     printf("\n\nTest options: [--[disable-]tap-output]\n");
95 
96   return RUN_ALL_TESTS();
97 }
98