Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

rspamd_cxx_unit.cxx 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. int main(int argc, char **argv)
  31. {
  32. struct rspamd_main *rspamd_main;
  33. rspamd_mempool_t *pool;
  34. struct rspamd_config *cfg;
  35. GOptionContext *options_context;
  36. pool = rspamd_mempool_new(rspamd_mempool_suggest_size(), NULL, 0);
  37. rspamd_main = (struct rspamd_main *) rspamd_mempool_alloc0(pool, sizeof(*rspamd_main));
  38. rspamd_main->server_pool = pool;
  39. cfg = rspamd_config_new(RSPAMD_CONFIG_INIT_DEFAULT);
  40. cfg->libs_ctx = rspamd_init_libs();
  41. rspamd_main->cfg = cfg;
  42. cfg->cfg_pool = pool;
  43. options_context = g_option_context_new("- run rspamd cxx test");
  44. g_option_context_add_main_entries(options_context, entries, NULL);
  45. g_option_context_set_ignore_unknown_options(options_context, true);
  46. g_option_context_set_help_enabled(options_context, false);
  47. GError *error = NULL;
  48. if (!g_option_context_parse(options_context, &argc, &argv, &error)) {
  49. fprintf(stderr, "option parsing failed: %s\n", error->message);
  50. g_option_context_free(options_context);
  51. exit(1);
  52. }
  53. if (verbose) {
  54. rspamd_main->logger = rspamd_log_open_emergency(rspamd_main->server_pool,
  55. RSPAMD_LOG_FLAG_USEC | RSPAMD_LOG_FLAG_ENFORCED | RSPAMD_LOG_FLAG_RSPAMADM);
  56. rspamd_log_set_log_level(rspamd_main->logger, G_LOG_LEVEL_DEBUG);
  57. }
  58. else {
  59. rspamd_main->logger = rspamd_log_open_emergency(rspamd_main->server_pool,
  60. RSPAMD_LOG_FLAG_RSPAMADM);
  61. rspamd_log_set_log_level(rspamd_main->logger, G_LOG_LEVEL_MESSAGE);
  62. }
  63. doctest::Context context(argc, argv);
  64. int res = context.run();
  65. if (context.shouldExit()) {
  66. return res;
  67. }
  68. rspamd_mempool_delete(pool);
  69. return res;
  70. }