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_utils.hxx 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. /* Detached unit tests for the utils */
  17. #ifndef RSPAMD_RSPAMD_CXX_UNIT_UTILS_HXX
  18. #define RSPAMD_RSPAMD_CXX_UNIT_UTILS_HXX
  19. #define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
  20. #include "doctest/doctest.h"
  21. #include "libmime/mime_headers.h"
  22. #include <vector>
  23. #include <utility>
  24. #include <string>
  25. TEST_SUITE("rspamd_utils") {
  26. TEST_CASE("rspamd_strip_smtp_comments_inplace")
  27. {
  28. std::vector<std::pair<std::string, std::string>> cases{
  29. {"abc", "abc"},
  30. {"abc(foo)", "abc"},
  31. {"abc(foo()", "abc"},
  32. {"abc(foo))", "abc)"},
  33. {"abc(foo(bar))", "abc"},
  34. {"(bar)abc(foo)", "abc"},
  35. {"ab(ololo)c(foo)", "abc"},
  36. {"ab(olo\\)lo)c(foo)", "abc"},
  37. {"ab(trol\\\1lo)c(foo)", "abc"},
  38. {"\\ab(trol\\\1lo)c(foo)", "abc"},
  39. {"", ""},
  40. };
  41. for (const auto &c : cases) {
  42. SUBCASE (("strip comments in " + c.first).c_str()) {
  43. auto *cpy = new char[c.first.size()];
  44. memcpy(cpy, c.first.data(), c.first.size());
  45. auto nlen = rspamd_strip_smtp_comments_inplace(cpy, c.first.size());
  46. CHECK(std::string{cpy, nlen} == c.second);
  47. delete[] cpy;
  48. }
  49. }
  50. }
  51. }
  52. #endif