libfort/tests/test_table.c

57 lines
1.3 KiB
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-02 10:03:58 +01:00
#include "fort.c"
void test_table_geometry(void **state)
{
(void)state;
FTABLE *table = ft_create_table();
int n = ft_hdr_printf(table, "%c", 'c');
assert_true( n == 1 );
size_t height = 0;
size_t width = 0;
int status = table_geometry(table, &height, &width);
assert_true( IS_SUCCESS(status) );
ft_destroy_table(table);
}
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, 1, "%d , %c|| %s|%f", 3, 'c', "234", 3.14);
assert_true( n == 4 );
2018-01-02 10:03:58 +01:00
n = ft_row_printf(table, 2, "%d , %c|| %s|%f", 3, 'c', "234", 3.14);
assert_true( n == 4 );
n = ft_row_printf(table, 4, "%d , %c|| %s|%f", 3, 'c', "234", 3.14);
assert_true( n == 4 );
2018-01-01 19:45:01 +01:00
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"
2018-01-02 10:03:58 +01:00
"| 3 , c| | 234| 3.140000\n"
"\n"
2018-01-01 19:45:01 +01:00
"| 3 , c| | 234| 3.140000\n";
2018-01-02 10:03:58 +01:00
fprintf(stderr, "%s", table_str);
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);
}