Made relevant JS tests transpile to C ; [src/Layout.c]: print_css_node_rec(): print alignContent ; [src/Layout-test-utils.c]: add_failed_test(): Sets failed_test->next to NULL, otherwise the test crashes if there's one and only one failure ; Added type casts so that it can be compiled as C++ by MSVC on Windows ; [Makefile]: Added c_test_msvc target when running in Windows so that the test executable can be built and debugged with Visual Studio on Windows ;
This commit is contained in:
@@ -10,6 +10,17 @@
|
||||
#include "Layout-test-utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <float.h>
|
||||
#define isnan _isnan
|
||||
__forceinline const float fmaxf(const float a, const float b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
__forceinline const float fminf(const float a, const float b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** START_GENERATED **/
|
||||
#define SMALL_WIDTH 35
|
||||
#define SMALL_HEIGHT 18
|
||||
@@ -30,7 +41,8 @@ typedef struct failed_test_t {
|
||||
static failed_test_t *failed_test_head = NULL;
|
||||
static failed_test_t *failed_test_tail = NULL;
|
||||
static void add_failed_test(const char *name, css_node_t *style, css_node_t *expected) {
|
||||
failed_test_t *failed_test = malloc(sizeof(failed_test_t));
|
||||
failed_test_t *failed_test = (failed_test_t *)malloc(sizeof(failed_test_t));
|
||||
failed_test->next = NULL;
|
||||
failed_test->name = name;
|
||||
failed_test->style = style;
|
||||
failed_test->expected = expected;
|
||||
@@ -65,7 +77,7 @@ static bool are_layout_equal(css_node_t *a, css_node_t *b) {
|
||||
}
|
||||
|
||||
css_dim_t measure(void *context, float width) {
|
||||
const char *text = context;
|
||||
const char *text = (const char *)context;
|
||||
css_dim_t dim;
|
||||
if (width != width) {
|
||||
width = 1000000;
|
||||
@@ -87,7 +99,10 @@ css_dim_t measure(void *context, float width) {
|
||||
return dim;
|
||||
}
|
||||
|
||||
static int test_ran_count = 0;
|
||||
void test(const char *name, css_node_t *style, css_node_t *expected_layout) {
|
||||
++test_ran_count;
|
||||
|
||||
layoutNode(style, CSS_UNDEFINED);
|
||||
|
||||
if (!are_layout_equal(style, expected_layout)) {
|
||||
@@ -109,12 +124,12 @@ int tests_finished() {
|
||||
printf("%sFAIL%s %s\n", "\x1B[31m", "\x1B[0m", failed_test->name);
|
||||
|
||||
printf("Input: ");
|
||||
print_css_node(failed_test->style, CSS_PRINT_STYLE | CSS_PRINT_CHILDREN);
|
||||
print_css_node(failed_test->style, (css_print_options_t)(CSS_PRINT_STYLE | CSS_PRINT_CHILDREN));
|
||||
printf("Output: ");
|
||||
print_css_node(failed_test->style, CSS_PRINT_LAYOUT | CSS_PRINT_CHILDREN);
|
||||
print_css_node(failed_test->style, (css_print_options_t)(CSS_PRINT_LAYOUT | CSS_PRINT_CHILDREN));
|
||||
|
||||
printf("Expected: ");
|
||||
print_css_node(failed_test->expected, CSS_PRINT_LAYOUT | CSS_PRINT_CHILDREN);
|
||||
print_css_node(failed_test->expected, (css_print_options_t)(CSS_PRINT_LAYOUT | CSS_PRINT_CHILDREN));
|
||||
|
||||
free_css_node(failed_test->style);
|
||||
free_css_node(failed_test->expected);
|
||||
@@ -131,7 +146,7 @@ int tests_finished() {
|
||||
printf("TESTS FAILED: %d\n", tests_failed);
|
||||
return 1;
|
||||
} else {
|
||||
printf("ALL TESTS PASSED\n");
|
||||
printf("ALL TESTS PASSED: %d tests ran.\n", test_ran_count);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user