str.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. #include "src/str.h"
  2. #include <assert.h>
  3. #include <string.h>
  4. void test_strncpy_without_suffix(const char *expected_dest, const char *src,
  5. const char *suffix, size_t max_len) {
  6. char dest[32] = "default";
  7. int result = rgpgfs_strncpy_without_suffix(dest, src, suffix, max_len);
  8. if (expected_dest == NULL) {
  9. assert(result);
  10. assert(!strcmp(dest, "default"));
  11. } else {
  12. assert(!result);
  13. assert(!strcmp(dest, expected_dest));
  14. }
  15. }
  16. int main() {
  17. test_strncpy_without_suffix("abc", "abc", "", 8);
  18. test_strncpy_without_suffix("ab", "abc", "c", 8);
  19. test_strncpy_without_suffix("a", "abc", "bc", 8);
  20. test_strncpy_without_suffix("", "abc", "abc", 8);
  21. test_strncpy_without_suffix("abcda", "abcdabc", "bc", 8);
  22. test_strncpy_without_suffix(NULL, "abc", "d", 8);
  23. test_strncpy_without_suffix("a", "abc", "bc", 1);
  24. test_strncpy_without_suffix("ab", "abc", "c", 2);
  25. test_strncpy_without_suffix(NULL, "abc", "c", 1);
  26. test_strncpy_without_suffix(NULL, "abc", "abcd", 8);
  27. test_strncpy_without_suffix(NULL, "bcd", "abcd", 8);
  28. test_strncpy_without_suffix("/folder/sub/file.txt",
  29. "/folder/sub/file.txt.gpg", ".gpg", 24);
  30. return 0;
  31. }