Bug 266950 - Add more `LayoutUnit::fromFloat*` API tests from Blink / Chromium
Summary: Add more `LayoutUnit::fromFloat*` API tests from Blink / Chromium
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-12-31 07:27 PST by Ahmad Saleem
Modified: 2024-01-05 14:52 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ahmad Saleem 2023-12-31 07:27:07 PST
Hi Team,

Just came across following commit, which has more API test, which we should import to get better coverage:

Blink Commit: https://chromium-review.googlesource.com/c/chromium/src/+/4652129

___

API Tests:

TEST(WebCoreLayoutUnit, LayoutUnitFloat)

    ASSERT_EQ(LayoutUnit(1.25f), LayoutUnit(1.25f + tolerance / 2));
    ASSERT_EQ(LayoutUnit(-2.0f), LayoutUnit(-2.0f - tolerance / 2));

TEST(WebCoreLayoutUnit, FromFloatCeil)
{
    const float tolerance = 1.0f / kFixedPointDenominator;
    ASSERT_EQ(LayoutUnit(1.25f), LayoutUnit::fromFloatCeil(1.25f));
    ASSERT_EQ(LayoutUnit(1.25f + tolerance), LayoutUnit::fromFloatCeil(1.25f + tolerance / 2));
    ASSERT_EQ(LayoutUnit(), LayoutUnit::fromFloatCeil(-tolerance / 2));

    using Limits = std::numeric_limits<float>;
    // Larger than max()
    ASSERT_EQ(LayoutUnit::max(), LayoutUnit::FromFloatCeil(Limits::max()));
    ASSERT_EQ(LayoutUnit::max(), LayoutUnit::FromFloatCeil(Limits::infinity()));
    // Smaller than Min()
    ASSERT_EQ(LayoutUnit::min(), LayoutUnit::FromFloatCeil(Limits::lowest()));
    ASSERT_EQ(LayoutUnit::min(), LayoutUnit::FromFloatCeil(-Limits::infinity()));

    ASSERT_EQ(LayoutUnit(), LayoutUnit::FromFloatCeil(Limits::quiet_NaN()));
}

TEST(WebCoreLayoutUnit, FromFloatFloor)
{
    const float tolerance = 1.0f / kFixedPointDenominator;
    ASSERT_EQ(LayoutUnit(1.25f), LayoutUnit::fromFloatFloor(1.25f));
    ASSERT_EQ(LayoutUnit(1.25f), LayoutUnit::fromFloatFloor(1.25f + tolerance / 2));
    ASSERT_EQ(LayoutUnit(-tolerance), LayoutUnit::fromFloatFloor(-tolerance / 2));

    using Limits = std::numeric_limits<float>;
    // Larger than max()
    ASSERT_EQ(LayoutUnit::max(), LayoutUnit::fromFloatFloor(Limits::max()));
    ASSERT_EQ(LayoutUnit::max(), LayoutUnit::fromFloatFloor(Limits::infinity()));
    // Smaller than min()
    ASSERT_EQ(LayoutUnit::min(), LayoutUnit::fromFloatFloor(Limits::lowest()));
    ASSERT_EQ(LayoutUnit::min(), LayoutUnit::fromFloatFloor(-Limits::infinity()));

    ASSERT_EQ(LayoutUnit(), LayoutUnit::fromFloatFloor(Limits::quiet_NaN()));
}

TEST(WebCoreLayoutUnit, FromFloatRound)
{
    const float tolerance = 1.0f / kFixedPointDenominator;
    ASSERT_EQ(LayoutUnit(1.25f), LayoutUnit::fromFloatRound(1.25f));
    ASSERT_EQ(LayoutUnit(1.25f), LayoutUnit::fromFloatRound(1.25f + tolerance / 4));
    ASSERT_EQ(LayoutUnit(1.25f + tolerance), LayoutUnit::fromFloatRound(1.25f + tolerance * 3 / 4));
    ASSERT_EQ(LayoutUnit(-tolerance), LayoutUnit::fromFloatRound(-tolerance * 3 / 4));

    using Limits = std::numeric_limits<float>;
    // Larger than max()
    ASSERT_EQ(LayoutUnit::max(), LayoutUnit::fromFloatRound(Limits::max()));
    ASSERT_EQ(LayoutUnit::max(), LayoutUnit::fromFloatRound(Limits::infinity()));
    // Smaller than Min()
    ASSERT_EQ(LayoutUnit::min(), LayoutUnit::fromFloatRound(Limits::lowest()));
    ASSERT_EQ(LayoutUnit::min(), LayoutUnit::fromFloatRound(-Limits::infinity()));

    ASSERT_EQ(LayoutUnit(), LayoutUnit::fromFloatRound(Limits::quiet_NaN()));
}

___

Just wanted to raise so we can import these as well. Will run locally to confirm that we don't fail them etc.

Thanks!
Comment 1 Ahmad Saleem 2023-12-31 08:43:47 PST
It fails:

Ran 4 tests of 4 with 1 successful
------------------------------
Test suite failed

Failed

    TestWebKitAPI.WebCoreLayoutUnit.FromFloatCeil
        /Users/ahmadsaleem/Documents/GitHub-Webkit-Ahmad-Fork/Untitled/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnitTests.cpp:287Expected equality of these values:  LayoutUnit()    Which is: 4-byte object <00-00 00-00>  LayoutUnit::fromFloatCeil(Limits::quiet_NaN())    Which is: 4-byte object <00-00 00-80>

    TestWebKitAPI.WebCoreLayoutUnit.FromFloatFloor
        /Users/ahmadsaleem/Documents/GitHub-Webkit-Ahmad-Fork/Untitled/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnitTests.cpp:305Expected equality of these values:  LayoutUnit()    Which is: 4-byte object <00-00 00-00>  LayoutUnit::fromFloatFloor(Limits::quiet_NaN())    Which is: 4-byte object <00-00 00-80>

    TestWebKitAPI.WebCoreLayoutUnit.FromFloatRound
        /Users/ahmadsaleem/Documents/GitHub-Webkit-Ahmad-Fork/Untitled/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnitTests.cpp:324Expected equality of these values:  LayoutUnit()    Which is: 4-byte object <00-00 00-00>  LayoutUnit::fromFloatRound(Limits::quiet_NaN())    Which is: 4-byte object <00-00 00-80>
Comment 2 Ahmad Saleem 2024-01-04 19:56:30 PST
One which compiles (previous had some errors):

TEST(WebCoreLayoutUnit, FromFloatCeil)
{
    const float tolerance = 1.0f / kFixedPointDenominator;
    ASSERT_EQ(LayoutUnit(1.25f), LayoutUnit::fromFloatCeil(1.25f));
    ASSERT_EQ(LayoutUnit(1.25f + tolerance), LayoutUnit::fromFloatCeil(1.25f + tolerance / 2));
    ASSERT_EQ(LayoutUnit(), LayoutUnit::fromFloatCeil(-tolerance / 2));

    using Limits = std::numeric_limits<float>;
    // Larger than max()
    ASSERT_EQ(LayoutUnit::max(), LayoutUnit::fromFloatCeil(Limits::max()));
    ASSERT_EQ(LayoutUnit::max(), LayoutUnit::fromFloatCeil(Limits::infinity()));
    // Smaller than Min()
    ASSERT_EQ(LayoutUnit::min(), LayoutUnit::fromFloatCeil(Limits::lowest()));
    ASSERT_EQ(LayoutUnit::min(), LayoutUnit::fromFloatCeil(-Limits::infinity()));

    ASSERT_EQ(LayoutUnit(), LayoutUnit::fromFloatCeil(Limits::quiet_NaN()));
}

TEST(WebCoreLayoutUnit, FromFloatFloor)
{
    const float tolerance = 1.0f / kFixedPointDenominator;
    ASSERT_EQ(LayoutUnit(1.25f), LayoutUnit::fromFloatFloor(1.25f));
    ASSERT_EQ(LayoutUnit(1.25f), LayoutUnit::fromFloatFloor(1.25f + tolerance / 2));
    ASSERT_EQ(LayoutUnit(-tolerance), LayoutUnit::fromFloatFloor(-tolerance / 2));

    using Limits = std::numeric_limits<float>;
    // Larger than max()
    ASSERT_EQ(LayoutUnit::max(), LayoutUnit::fromFloatFloor(Limits::max()));
    ASSERT_EQ(LayoutUnit::max(), LayoutUnit::fromFloatFloor(Limits::infinity()));
    // Smaller than min()
    ASSERT_EQ(LayoutUnit::min(), LayoutUnit::fromFloatFloor(Limits::lowest()));
    ASSERT_EQ(LayoutUnit::min(), LayoutUnit::fromFloatFloor(-Limits::infinity()));

    ASSERT_EQ(LayoutUnit(), LayoutUnit::fromFloatFloor(Limits::quiet_NaN()));
}

TEST(WebCoreLayoutUnit, FromFloatRound)
{
    const float tolerance = 1.0f / kFixedPointDenominator;
    ASSERT_EQ(LayoutUnit(1.25f), LayoutUnit::fromFloatRound(1.25f));
    ASSERT_EQ(LayoutUnit(1.25f), LayoutUnit::fromFloatRound(1.25f + tolerance / 4));
    ASSERT_EQ(LayoutUnit(1.25f + tolerance), LayoutUnit::fromFloatRound(1.25f + tolerance * 3 / 4));
    ASSERT_EQ(LayoutUnit(-tolerance), LayoutUnit::fromFloatRound(-tolerance * 3 / 4));

    using Limits = std::numeric_limits<float>;
    // Larger than max()
    ASSERT_EQ(LayoutUnit::max(), LayoutUnit::fromFloatRound(Limits::max()));
    ASSERT_EQ(LayoutUnit::max(), LayoutUnit::fromFloatRound(Limits::infinity()));
    // Smaller than Min()
    ASSERT_EQ(LayoutUnit::min(), LayoutUnit::fromFloatRound(Limits::lowest()));
    ASSERT_EQ(LayoutUnit::min(), LayoutUnit::fromFloatRound(-Limits::infinity()));

    ASSERT_EQ(LayoutUnit(), LayoutUnit::fromFloatRound(Limits::quiet_NaN()));
}


___

I think I would remove 'quiet_Nan()' and land this to just have good coverage.
Comment 3 EWS 2024-01-05 14:51:29 PST
Committed 272707@main (0058f6b04bfb): <https://commits.webkit.org/272707@main>

Reviewed commits have been landed. Closing PR #22418 and removing active labels.
Comment 4 Radar WebKit Bug Importer 2024-01-05 14:52:18 PST
<rdar://problem/120561655>