Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View.Add/Remove should throw exceptions if invalid #3970

Open
tig opened this issue Mar 8, 2025 · 2 comments
Open

View.Add/Remove should throw exceptions if invalid #3970

tig opened this issue Mar 8, 2025 · 2 comments
Labels
Milestone

Comments

@tig
Copy link
Collaborator

tig commented Mar 8, 2025

TileView tests assume Views can be Added to SuperView twice

e.g.:

[Fact]
public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringInsertTile ()
{
    TileView tv = GetTileView (20, 10);

    var myReusableView = new DisposeCounter ();

    // I want my view in the first tile
    tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
    Assert.Equal (0, myReusableView.DisposalCount);

    // I've changed my mind, I want 3 tiles now
    tv.InsertTile (0);
    tv.InsertTile (2);

    // but I still want my view in the first tile
    // BUGBUG: Adding a view twice is not legit
    tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);

    Assert.Multiple (
                     () => Assert.Equal (0, myReusableView.DisposalCount),
                     () =>
                     {
                         tv.Dispose ();
                         Assert.True (myReusableView.DisposalCount >= 1);
                     }
                    );
}
@tig tig added the bug label Mar 8, 2025
@tig tig changed the title TileView tests assume Views can be added to two SuperViews TileView tests assume Views can be Added to SuperView twice Mar 8, 2025
@tznind
Copy link
Collaborator

tznind commented Mar 8, 2025

Should have a remove call first before adding to the other view.

Test doesn't want view in 2 places at once, at most it wants to see view move to new home.

It can be either

  • when you add view to second place, it does implicit Remove
  • or, when you add to second place it throws Exception

Either works for me

@tig
Copy link
Collaborator Author

tig commented Mar 8, 2025

The View Disposal tests also have a similar problem, but they add a view to multiple superviews.

I'd like to have this fixed after I merge

AND, to make View.Add/Remove throw exceptions when these situations are detected. The both emit warnings now, but I had to remove the throws for tests to pass.

@tig tig added this to the V2 Alpha milestone Mar 8, 2025
@tig tig changed the title TileView tests assume Views can be Added to SuperView twice View.Add/Remove should throw exceptions if invalid Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

2 participants