mutt_buffer_strcpy_n(&buf, NULL, 3);
TEST_CHECK_(1, "mutt_buffer_strcpy_n(&buf, NULL, 3)");
}
+
+ TEST_CASE("Copy to an empty Buffer");
+
+ {
+ const char *str = "a quick brown fox";
+ const size_t len = strlen(str);
+ size_t sizes[] = { 0, 5, len, 99 };
+
+ for (size_t i = 0; i < mutt_array_size(sizes); i++)
+ {
+ TEST_CASE_("%ld", sizes[i]);
+ struct Buffer *buf = mutt_buffer_new();
+ mutt_buffer_strcpy_n(buf, str, sizes[i]);
+ TEST_CHECK(strlen(mutt_b2s(buf)) == MIN(len, sizes[i]));
+ TEST_CHECK(strncmp(mutt_b2s(buf), str, sizes[i]) == 0);
+ mutt_buffer_free(&buf);
+ }
+ }
+
+ TEST_CASE("Copy to a non-empty Buffer");
+
+ {
+ const char *base = "test";
+ const char *str = "a quick brown fox";
+ const size_t len = strlen(str);
+ size_t sizes[] = { 0, 5, len, 99 };
+
+ for (size_t i = 0; i < mutt_array_size(sizes); i++)
+ {
+ TEST_CASE_("%ld", sizes[i]);
+ struct Buffer *buf = mutt_buffer_from(base);
+ mutt_buffer_strcpy_n(buf, str, sizes[i]);
+ TEST_CHECK(strlen(mutt_b2s(buf)) == MIN(len, sizes[i]));
+ TEST_CHECK(strncmp(mutt_b2s(buf), str, sizes[i]) == 0);
+ mutt_buffer_free(&buf);
+ }
+ }
}