libslic3r_tests.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <catch_main.hpp>
  2. #include "libslic3r/Utils.hpp"
  3. namespace {
  4. TEST_CASE("sort_remove_duplicates", "[utils]") {
  5. std::vector<int> data_src = { 3, 0, 2, 1, 15, 3, 5, 6, 3, 1, 0 };
  6. std::vector<int> data_dst = { 0, 1, 2, 3, 5, 6, 15 };
  7. Slic3r::sort_remove_duplicates(data_src);
  8. REQUIRE(data_src == data_dst);
  9. }
  10. TEST_CASE("string_printf", "[utils]") {
  11. SECTION("Empty format with empty data should return empty string") {
  12. std::string outs = Slic3r::string_printf("");
  13. REQUIRE(outs.empty());
  14. }
  15. SECTION("String output length should be the same as input") {
  16. std::string outs = Slic3r::string_printf("1234");
  17. REQUIRE(outs.size() == 4);
  18. }
  19. SECTION("String format should be interpreted as with sprintf") {
  20. std::string outs = Slic3r::string_printf("%d %f %s", 10, 11.4, " This is a string");
  21. char buffer[1024];
  22. sprintf(buffer, "%d %f %s", 10, 11.4, " This is a string");
  23. REQUIRE(outs.compare(buffer) == 0);
  24. }
  25. SECTION("String format should survive large input data") {
  26. std::string input(2048, 'A');
  27. std::string outs = Slic3r::string_printf("%s", input.c_str());
  28. REQUIRE(outs.compare(input) == 0);
  29. }
  30. }
  31. }