// Copyright (C) Stichting Deltares 2021. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System.Collections.Generic; using Deltares.Dam.Data; using Deltares.Dam.TestHelper.TestUtils; using Deltares.Dam.Tests.TestUtils; using Deltares.Geometry; using Deltares.Geotechnics.GeotechnicalGeometry; using Deltares.Geotechnics.SurfaceLines; using NUnit.Framework; namespace Deltares.Dam.Tests.Memoryleaks { public class DamMemoryLeakTests : MemoryLeakTestBase { [Test] public void Location_ShouldNotLeak() { MonitorMemoryLeakage(GetMonitoredChildren); } private IEnumerable GetMonitoredChildren(Location location) { var list = new List(); // Local surfaceline is a composite child of Location: var localXzSurfaceLine2 = new SurfaceLine2 { Geometry = new LocalizedGeometryPointString(), CharacteristicPoints = { GeometryMustContainPoint = true } }; localXzSurfaceLine2.AddCharacteristicPoint(new GeometryPoint(1.1, 0.0, 2.2), CharacteristicPointType.ShoulderBaseInside); location.LocalXZSurfaceLine2 = localXzSurfaceLine2; list.Add(localXzSurfaceLine2); return list; } [Test] public void Dike_ShouldNotLeak() { MonitorMemoryLeakage(GetMonitoredChildren); } private IEnumerable GetMonitoredChildren(Dike dike) { var list = new List(); var localizedGeometryPointString = new LocalizedGeometryPointString(); // Aggregation relationship // A composite child of Dike var surfaceLine = new SurfaceLine2 { Geometry = localizedGeometryPointString, CharacteristicPoints = { GeometryMustContainPoint = true } }; surfaceLine.AddCharacteristicPoint(new GeometryPoint(1.1, 0.0, 2.2), CharacteristicPointType.InsertRiverChannel, CharacteristicPointType.SurfaceLevelInside); list.Add(surfaceLine); dike.SurfaceLines2.Add(surfaceLine); // Composite child of Dike var location = new Location(); list.Add(location); GetMonitoredChildren(location); // Sets up 'leakable' Location instance dike.Locations.Add(location); return list; } [Test] public void WaterBoard_ShouldNotLeak() { MonitorMemoryLeakage(GetMonitoredChildren); } private IEnumerable GetMonitoredChildren(WaterBoard waterBoard) { var list = new List(); var dike = new Dike(); list.Add(dike); GetMonitoredChildren(dike); // Create 'leakable' Dike instance waterBoard.Dikes.Add(dike); return list; } [Test] public void DamProjectData_ShouldNotLeak() { MonitorMemoryLeakage(GetMonitoredChildren); } private IEnumerable GetMonitoredChildren(DamProjectData projectData) { var list = new List { projectData.WaterBoard }; GetMonitoredChildren(projectData.WaterBoard); // Create 'leakable' WaterBoard data list.Add(projectData.DamProjectCalculationSpecification); return list; } [Test] public void DamProjectCalculationSpecification_ShouldNotLeak() { MonitorMemoryLeakage(null); } [Test] public void DamProject_ShouldNotLeak() { MonitorMemoryLeakage(GetMonitoredChildren); } private IEnumerable GetMonitoredChildren(DamProject damProject) { var list = new List { damProject.DamProjectData }; GetMonitoredChildren(damProject.DamProjectData); // Create 'leakable' DamProjectData data return list; } } }