1
0
Fork 0
libfort/tests/wb_tests/test_table_geometry.c

90 lines
2.4 KiB
C
Raw Normal View History

2018-03-19 21:07:18 +01:00
#include "tests.h"
#include "table.h"
void test_table_sizes(void)
{
2018-05-05 21:34:45 +02:00
ft_table_t *table = ft_create_table();
2018-03-31 12:33:37 +02:00
assert_true(table != NULL);
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
2018-03-19 21:07:18 +01:00
size_t rows = 0;
size_t cols = 0;
int status = FT_SUCCESS;
WHEN("Table is empty") {
status = get_table_sizes(table, &rows, &cols);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(rows == 0);
assert_true(cols == 0);
2018-03-19 21:07:18 +01:00
}
WHEN("Insert one cell") {
int n = ft_printf_ln(table, "%c", 'c');
2018-03-31 12:33:37 +02:00
assert_true(n == 1);
2018-03-19 21:07:18 +01:00
status = get_table_sizes(table, &rows, &cols);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(rows == 1);
assert_true(cols == 1);
2018-03-19 21:07:18 +01:00
}
WHEN("Insert two cells in the next row") {
int n = ft_printf_ln(table, "%c|%c", 'c', 'd');
2018-03-31 12:33:37 +02:00
assert_true(n == 2);
2018-03-19 21:07:18 +01:00
status = get_table_sizes(table, &rows, &cols);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(rows == 2);
assert_true(cols == 2);
2018-03-19 21:07:18 +01:00
}
WHEN("Insert five cells in the next row") {
int n = ft_printf_ln(table, "%d|%d|%d|%d|%d", 1, 2, 3, 4, 5);
2018-03-31 12:33:37 +02:00
assert_true(n == 5);
2018-03-19 21:07:18 +01:00
status = get_table_sizes(table, &rows, &cols);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(rows == 3);
assert_true(cols == 5);
2018-03-19 21:07:18 +01:00
}
ft_destroy_table(table);
}
void test_table_geometry(void)
{
2018-05-05 21:34:45 +02:00
ft_table_t *table = ft_create_table();
2018-03-31 12:33:37 +02:00
assert_true(table != NULL);
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
2018-03-19 21:07:18 +01:00
size_t height = 0;
size_t width = 0;
int status = FT_SUCCESS;
WHEN("Table is empty") {
status = table_geometry(table, &height, &width);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(height == 2);
assert_true(width == 3);
2018-03-19 21:07:18 +01:00
}
WHEN("Table has one cell") {
int n = ft_printf_ln(table, "%c", 'c');
2018-03-31 12:33:37 +02:00
assert_true(n == 1);
2018-03-19 21:07:18 +01:00
status = table_geometry(table, &height, &width);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(height == 5);
assert_true(width == 6);
2018-03-19 21:07:18 +01:00
}
WHEN("Inserting 3 cells in the next row") {
int n = ft_printf_ln(table, "%c|%s|%c", 'c', "as", 'e');
2018-03-31 12:33:37 +02:00
assert_true(n == 3);
2018-03-19 21:07:18 +01:00
status = table_geometry(table, &height, &width);
2018-05-05 17:38:45 +02:00
assert_true(FT_IS_SUCCESS(status));
2018-03-31 12:33:37 +02:00
assert_true(height == 9);
assert_true(width == 15);
2018-03-19 21:07:18 +01:00
}
ft_destroy_table(table);
}