You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rspamd_cxx_unit.cxx 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*-
  2. * Copyright 2021 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "config.h"
  17. #include "rspamd.h"
  18. #include <memory>
  19. #define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
  20. #include "doctest/doctest.h"
  21. #include "rspamd_cxx_unit_utils.hxx"
  22. #include "rspamd_cxx_local_ptr.hxx"
  23. #include "rspamd_cxx_unit_dkim.hxx"
  24. static gboolean verbose = false;
  25. static const GOptionEntry entries[] =
  26. {
  27. {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
  28. "Enable verbose logging", NULL},
  29. {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
  30. };
  31. int
  32. main(int argc, char **argv) {
  33. struct rspamd_main *rspamd_main;
  34. rspamd_mempool_t *pool;
  35. struct rspamd_config *cfg;
  36. GOptionContext *options_context;
  37. pool = rspamd_mempool_new(rspamd_mempool_suggest_size(), NULL, 0);
  38. rspamd_main = (struct rspamd_main *) rspamd_mempool_alloc0(pool, sizeof(*rspamd_main));
  39. rspamd_main->server_pool = pool;
  40. cfg = rspamd_config_new(RSPAMD_CONFIG_INIT_DEFAULT);
  41. cfg->libs_ctx = rspamd_init_libs();
  42. rspamd_main->cfg = cfg;
  43. cfg->cfg_pool = pool;
  44. options_context = g_option_context_new("- run rspamd cxx test");
  45. g_option_context_add_main_entries(options_context, entries, NULL);
  46. g_option_context_set_ignore_unknown_options(options_context, true);
  47. g_option_context_set_help_enabled(options_context, false);
  48. GError *error = NULL;
  49. if (!g_option_context_parse(options_context, &argc, &argv, &error)) {
  50. fprintf(stderr, "option parsing failed: %s\n", error->message);
  51. g_option_context_free(options_context);
  52. exit(1);
  53. }
  54. if (verbose) {
  55. rspamd_main->logger = rspamd_log_open_emergency(rspamd_main->server_pool,
  56. RSPAMD_LOG_FLAG_USEC | RSPAMD_LOG_FLAG_ENFORCED | RSPAMD_LOG_FLAG_RSPAMADM);
  57. rspamd_log_set_log_level(rspamd_main->logger, G_LOG_LEVEL_DEBUG);
  58. }
  59. else {
  60. rspamd_main->logger = rspamd_log_open_emergency(rspamd_main->server_pool,
  61. RSPAMD_LOG_FLAG_RSPAMADM);
  62. rspamd_log_set_log_level(rspamd_main->logger, G_LOG_LEVEL_MESSAGE);
  63. }
  64. doctest::Context context(argc, argv);
  65. int res = context.run();
  66. if (context.shouldExit()) {
  67. return res;
  68. }
  69. rspamd_mempool_delete(pool);
  70. return res;
  71. }