Remove legacy test suite

Summary: Now that gentest has been used to cover all flexbox properties as well as some internal behavior I thought it was time to remove the old CSSLayoutTest.cpp. This removes a huge amount of previously regex transpiled code in favor of the new test suite which does more fine grained assertions and uses the public api. Given that RTL support was added to gentest now I feel confident that the new test suite covers all and more cases than the old one.

Reviewed By: lucasr

Differential Revision: D3863095

fbshipit-source-id: a2c4f87cd2263b4cc1fcdec4f2a0964f0696472f
This commit is contained in:
Emil Sjolander
2016-09-14 08:51:08 -07:00
committed by Facebook Github Bot 0
parent 21a05417cd
commit 0be3b1013f
5 changed files with 78 additions and 9641 deletions

View File

@@ -1,93 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#pragma once
#include "CSSLayout.h"
#include "CSSNodeList.h"
CSS_EXTERN_C_BEGIN
typedef struct CSSCachedMeasurement {
float availableWidth;
float availableHeight;
CSSMeasureMode widthMeasureMode;
CSSMeasureMode heightMeasureMode;
float computedWidth;
float computedHeight;
} CSSCachedMeasurement;
// This value was chosen based on empiracle data. Even the most complicated
// layouts should not require more than 16 entries to fit within the cache.
enum { CSS_MAX_CACHED_RESULT_COUNT = 16 };
typedef struct CSSLayout {
float position[4];
float dimensions[2];
CSSDirection direction;
float computedFlexBasis;
// Instead of recomputing the entire layout every single time, we
// cache some information to break early when nothing changed
uint32_t generationCount;
CSSDirection lastParentDirection;
uint32_t nextCachedMeasurementsIndex;
CSSCachedMeasurement cachedMeasurements[CSS_MAX_CACHED_RESULT_COUNT];
float measuredDimensions[2];
CSSCachedMeasurement cached_layout;
} CSSLayout;
typedef struct CSSStyle {
CSSDirection direction;
CSSFlexDirection flexDirection;
CSSJustify justifyContent;
CSSAlign alignContent;
CSSAlign alignItems;
CSSAlign alignSelf;
CSSPositionType positionType;
CSSWrapType flexWrap;
CSSOverflow overflow;
float flexGrow;
float flexShrink;
float flexBasis;
float margin[CSSEdgeCount];
float position[CSSEdgeCount];
float padding[CSSEdgeCount];
float border[CSSEdgeCount];
float dimensions[2];
float minDimensions[2];
float maxDimensions[2];
} CSSStyle;
typedef struct CSSNode {
CSSStyle style;
CSSLayout layout;
uint32_t lineIndex;
bool hasNewLayout;
bool isTextNode;
CSSNodeRef parent;
CSSNodeListRef children;
bool isDirty;
struct CSSNode *nextChild;
CSSSize (*measure)(void *context,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode);
void (*print)(void *context);
void *context;
} CSSNode;
CSS_EXTERN_C_END

View File

@@ -9,7 +9,8 @@
#include <string.h>
#include "CSSLayout-internal.h"
#include "CSSLayout.h"
#include "CSSNodeList.h"
#ifdef _MSC_VER
#include <float.h>
@@ -23,6 +24,82 @@ __forceinline const float fmaxf(const float a, const float b) {
#endif
#endif
typedef struct CSSCachedMeasurement {
float availableWidth;
float availableHeight;
CSSMeasureMode widthMeasureMode;
CSSMeasureMode heightMeasureMode;
float computedWidth;
float computedHeight;
} CSSCachedMeasurement;
// This value was chosen based on empiracle data. Even the most complicated
// layouts should not require more than 16 entries to fit within the cache.
enum { CSS_MAX_CACHED_RESULT_COUNT = 16 };
typedef struct CSSLayout {
float position[4];
float dimensions[2];
CSSDirection direction;
float computedFlexBasis;
// Instead of recomputing the entire layout every single time, we
// cache some information to break early when nothing changed
uint32_t generationCount;
CSSDirection lastParentDirection;
uint32_t nextCachedMeasurementsIndex;
CSSCachedMeasurement cachedMeasurements[CSS_MAX_CACHED_RESULT_COUNT];
float measuredDimensions[2];
CSSCachedMeasurement cached_layout;
} CSSLayout;
typedef struct CSSStyle {
CSSDirection direction;
CSSFlexDirection flexDirection;
CSSJustify justifyContent;
CSSAlign alignContent;
CSSAlign alignItems;
CSSAlign alignSelf;
CSSPositionType positionType;
CSSWrapType flexWrap;
CSSOverflow overflow;
float flexGrow;
float flexShrink;
float flexBasis;
float margin[CSSEdgeCount];
float position[CSSEdgeCount];
float padding[CSSEdgeCount];
float border[CSSEdgeCount];
float dimensions[2];
float minDimensions[2];
float maxDimensions[2];
} CSSStyle;
typedef struct CSSNode {
CSSStyle style;
CSSLayout layout;
uint32_t lineIndex;
bool hasNewLayout;
bool isTextNode;
CSSNodeRef parent;
CSSNodeListRef children;
bool isDirty;
struct CSSNode *nextChild;
CSSSize (*measure)(void *context,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode);
void (*print)(void *context);
void *context;
} CSSNode;
static float
computedEdgeValue(const float edges[CSSEdgeCount], const CSSEdge edge, const float defaultValue) {
CSS_ASSERT(edge <= CSSEdgeEnd, "Cannot get computed value of multi-edge shorthands");

File diff suppressed because it is too large Load Diff

View File

@@ -1,127 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <stdlib.h>
#include "CSSLayoutTestUtils.h"
#ifdef _MSC_VER
#include <float.h>
#define isnan _isnan
/* define fmaxf & fminf if < VC12 */
#if _MSC_VER < 1800
__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
#endif
static bool eq(const float a, const float b) {
return fabs(a - b) < 0.0001;
}
static bool are_layout_equal(const CSSNodeRef a, const CSSNodeRef b) {
if (!eq(a->layout.dimensions[CSSDimensionWidth], b->layout.dimensions[CSSDimensionWidth]) ||
!eq(a->layout.dimensions[CSSDimensionHeight], b->layout.dimensions[CSSDimensionHeight]) ||
!eq(a->layout.position[CSSEdgeTop], b->layout.position[CSSEdgeTop]) ||
!eq(a->layout.position[CSSEdgeLeft], b->layout.position[CSSEdgeLeft]) ||
!eq(CSSNodeChildCount(a), CSSNodeChildCount(b))) {
return false;
}
for (uint32_t i = 0; i < CSSNodeChildCount(a); ++i) {
if (!are_layout_equal(CSSNodeGetChild(a, i), CSSNodeGetChild(b, i))) {
return false;
}
}
return true;
}
CSSSize measure(void *context,
float availableWidth,
CSSMeasureMode widthMode,
float availableHeight,
CSSMeasureMode heightMode) {
const char *text = (const char *) context;
CSSSize result;
float width = availableWidth;
float height = availableHeight;
if (strcmp(text, SMALL_TEXT) == 0) {
if (widthMode == CSSMeasureModeUndefined) {
width = 1000000;
}
result.width = fminf(SMALL_WIDTH, width);
result.height = SMALL_WIDTH > width ? BIG_HEIGHT : SMALL_HEIGHT;
return result;
}
if (strcmp(text, LONG_TEXT) == 0) {
if (widthMode == CSSMeasureModeUndefined) {
width = 1000000;
}
result.width = fminf(BIG_WIDTH, width);
result.height = BIG_WIDTH > width ? BIG_HEIGHT : SMALL_HEIGHT;
return result;
}
if (strcmp(text, MEASURE_WITH_RATIO_2) == 0) {
if (widthMode == CSSMeasureModeExactly) {
result.width = width;
result.height = width * 2;
} else if (heightMode == CSSMeasureModeExactly) {
result.width = height * 2;
result.height = height;
} else if (widthMode == CSSMeasureModeAtMost) {
result.width = width;
result.height = width * 2;
} else if (heightMode == CSSMeasureModeAtMost) {
result.width = height * 2;
result.height = height;
} else {
result.width = 99999;
result.height = 99999;
}
return result;
}
if (strcmp(text, MEASURE_WITH_MATCH_PARENT) == 0) {
if (widthMode == CSSMeasureModeUndefined) {
width = 99999;
}
if (heightMode == CSSMeasureModeUndefined) {
height = 99999;
}
result.width = width;
result.height = height;
return result;
}
// Should not go here
result.width = CSSUndefined;
result.height = CSSUndefined;
return result;
}
bool test(const CSSNodeRef style, const CSSNodeRef expected_layout) {
CSSNodeCalculateLayout(style, CSSUndefined, CSSUndefined, (CSSDirection) -1);
return are_layout_equal(style, expected_layout);
}
CSSNodeRef new_test_css_node() {
CSSNodeRef node = CSSNodeNew();
return node;
}
void init_css_node_children(const CSSNodeRef node, const uint32_t childCount) {
for (uint32_t i = 0; i < childCount; ++i) {
CSSNodeInsertChild(node, new_test_css_node(), 0);
}
}

View File

@@ -1,47 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef __CSS_LAYOUT_TEST_UTILS_H
#define __CSS_LAYOUT_TEST_UTILS_H
#include <math.h>
#include <stdio.h>
#include <string.h>
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include <CSSLayout/CSSLayout-internal.h>
#include <CSSLayout/CSSMacros.h>
#include <CSSLayout/CSSNodeList.h>
#define SMALL_WIDTH 35
#define SMALL_HEIGHT 18
#define BIG_WIDTH 172
#define BIG_HEIGHT 36
#define SMALL_TEXT "small"
#define LONG_TEXT "loooooooooong with space"
#define MEASURE_WITH_RATIO_2 "measureWithRatio2"
#define MEASURE_WITH_MATCH_PARENT "measureWithMatchParent"
CSS_EXTERN_C_BEGIN
bool test(const CSSNodeRef style, const CSSNodeRef expected_layout);
CSSSize measure(void *context,
float availableWidth,
CSSMeasureMode widthMode,
float availableHeight,
CSSMeasureMode heightMode);
void init_css_node_children(const CSSNodeRef node, const uint32_t childCount);
CSSNodeRef new_test_css_node();
CSS_EXTERN_C_END
#endif