mirror of
https://github.com/fmtlib/fmt.git
synced 2026-06-15 00:16:15 +08:00
Add a test for fmt_print
This commit is contained in:
parent
841040e781
commit
c1c7296bfa
@ -10,6 +10,7 @@
|
||||
#include <fmt/base.h>
|
||||
|
||||
constexpr size_t max_c_format_args = 16;
|
||||
|
||||
static int convert_c_format_args(
|
||||
fmt::basic_format_arg<fmt::format_context>* format_args,
|
||||
const fmt_arg* args, size_t num_args) {
|
||||
|
||||
@ -83,10 +83,30 @@ void test_buffer_size_query(void) {
|
||||
ASSERT_INT_EQ(size, 15);
|
||||
}
|
||||
|
||||
void test_print(void) {
|
||||
FILE* file = tmpfile();
|
||||
if (!file) {
|
||||
fprintf(stderr, "\nFailed to create temporary file\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int ret = fmt_print(file, "{} and {}", 42, "foo");
|
||||
ASSERT_INT_EQ(ret, 0);
|
||||
|
||||
rewind(file);
|
||||
char buf[100];
|
||||
size_t n = fread(buf, 1, sizeof(buf) - 1, file);
|
||||
buf[n] = '\0';
|
||||
ASSERT_STR_EQ(buf, "42 and foo");
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
printf("Running C API tests\n");
|
||||
test_types();
|
||||
test_zero_arguments();
|
||||
test_buffer_size_query();
|
||||
test_print();
|
||||
printf("C API tests passed\n");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user