src/ui/scenic/lib/flatland/tests/flatland_unittest.cc
// Test that Present() fails if it detects a graph cycle.
Test that Present() fails if it detects a graph cycle.
Test that Present () fails if it detects a graph cycle .
TEST_F(FlatlandTest, CycleDetector) {
  Flatland flatland = CreateFlatland();
  const TransformId kId1 = 1;
  const TransformId kId2 = 2;
  const TransformId kId3 = 3;
  const TransformId kId4 = 4;
  {
    flatland.CreateTransform(kId1);
    flatland.AddChild(kId1, kId1);
    PRESENT(flatland, false);
  }
  {
    flatland.ClearGraph();
    flatland.CreateTransform(kId1);
    flatland.CreateTransform(kId2);
    flatland.AddChild(kId1, kId2);
    PRESENT(flatland, true);
    flatland.AddChild(kId2, kId1);
    PRESENT(flatland, false);
  }
  {
    flatland.ClearGraph();
    flatland.CreateTransform(kId1);
    flatland.CreateTransform(kId2);
    flatland.CreateTransform(kId3);
    flatland.CreateTransform(kId4);
    flatland.AddChild(kId1, kId2);
    flatland.AddChild(kId3, kId4);
    PRESENT(flatland, true);
    flatland.AddChild(kId2, kId3);
    flatland.AddChild(kId4, kId1);
    PRESENT(flatland, false);
  }
  {
    flatland.ClearGraph();
    flatland.CreateTransform(kId1);
    flatland.CreateTransform(kId2);
    flatland.CreateTransform(kId3);
    flatland.CreateTransform(kId4);
    flatland.AddChild(kId1, kId2);
    flatland.AddChild(kId2, kId3);
    flatland.AddChild(kId3, kId2);
    flatland.AddChild(kId3, kId4);
    flatland.SetRootTransform(kId1);
    flatland.ReleaseTransform(kId1);
    flatland.ReleaseTransform(kId2);
    flatland.ReleaseTransform(kId3);
    flatland.ReleaseTransform(kId4);
    PRESENT(flatland, false);
  }
}
TEST_F ( FlatlandTest , CycleDetector ) { Flatland flatland = CreateFlatland ( ) ; const TransformId kId1 = 1 ; const TransformId kId2 = 2 ; const TransformId kId3 = 3 ; const TransformId kId4 = 4 ; { flatland . CreateTransform ( kId1 ) ; flatland . AddChild ( kId1 , kId1 ) ; PRESENT ( flatland , false ) ; } { flatland . ClearGraph ( ) ; flatland . CreateTransform ( kId1 ) ; flatland . CreateTransform ( kId2 ) ; flatland . AddChild ( kId1 , kId2 ) ; PRESENT ( flatland , true ) ; flatland . AddChild ( kId2 , kId1 ) ; PRESENT ( flatland , false ) ; } { flatland . ClearGraph ( ) ; flatland . CreateTransform ( kId1 ) ; flatland . CreateTransform ( kId2 ) ; flatland . CreateTransform ( kId3 ) ; flatland . CreateTransform ( kId4 ) ; flatland . AddChild ( kId1 , kId2 ) ; flatland . AddChild ( kId3 , kId4 ) ; PRESENT ( flatland , true ) ; flatland . AddChild ( kId2 , kId3 ) ; flatland . AddChild ( kId4 , kId1 ) ; PRESENT ( flatland , false ) ; } { flatland . ClearGraph ( ) ; flatland . CreateTransform ( kId1 ) ; flatland . CreateTransform ( kId2 ) ; flatland . CreateTransform ( kId3 ) ; flatland . CreateTransform ( kId4 ) ; flatland . AddChild ( kId1 , kId2 ) ; flatland . AddChild ( kId2 , kId3 ) ; flatland . AddChild ( kId3 , kId2 ) ; flatland . AddChild ( kId3 , kId4 ) ; flatland . SetRootTransform ( kId1 ) ; flatland . ReleaseTransform ( kId1 ) ; flatland . ReleaseTransform ( kId2 ) ; flatland . ReleaseTransform ( kId3 ) ; flatland . ReleaseTransform ( kId4 ) ; PRESENT ( flatland , false ) ; } }
Test that Present() fails if it detects a graph cycle.
Test that Present () fails if it detects a graph cycle .
// Create an immediate cycle. // Create a legal chain of depth one. // Then, create a cycle of length 2. // Create two legal chains of length one. // Then, connect each chain into a cycle of length four. // Create a cycle, where the root is not involved in the cycle.