libfort/tests/test_table.c

32 lines
815 B
C
Raw Normal View History

2018-01-01 09:26:34 +01:00
#include "tests.h"
#include "fort.h"
#include <string.h>
2018-01-01 19:45:01 +01:00
#include <stdlib.h>
#include <stdio.h>
2018-01-01 09:26:34 +01:00
void test_table_basic(void **state)
{
(void)state;
FTABLE *table = ft_create_table();
int n = ft_hdr_printf(table, "%d , %c|| %s|%f", 3, 'c', "234", 3.14);
2018-01-01 19:45:01 +01:00
assert_true( n == 4 );
n = ft_row_printf(table, 0, "%d , %c|| %s|%f", 3, 'c', "234", 3.14);
assert_true( n == 4 );
n = ft_row_printf(table, 1, "%d , %c|| %s|%f", 3, 'c', "234", 3.14);
assert_true( n == 4 );
2018-01-01 09:26:34 +01:00
2018-01-01 19:45:01 +01:00
char *table_str = ft_to_string(table);
const char *table_str_etalon =
"| 3 , c| | 234| 3.140000\n"
"| 3 , c| | 234| 3.140000\n"
"| 3 , c| | 234| 3.140000\n";
2018-01-01 09:26:34 +01:00
2018-01-01 19:45:01 +01:00
assert_true( strcmp(table_str, table_str_etalon) == 0);
2018-01-01 09:26:34 +01:00
2018-01-01 19:45:01 +01:00
free(table_str);
2018-01-01 09:26:34 +01:00
ft_destroy_table(table);
}