2017-08-20 15:52:43 -07:00
|
|
|
|
#if !__ANDROID__
|
2016-09-20 14:32:22 -07:00
|
|
|
|
using MatterHackers.MatterControl.Tests.Automation;
|
2016-09-28 10:24:11 -07:00
|
|
|
|
#endif
|
2015-05-05 07:25:47 -07:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Diagnostics;
|
2015-12-17 12:21:55 -08:00
|
|
|
|
using System.IO;
|
2015-05-05 07:25:47 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reflection;
|
2015-12-17 12:21:55 -08:00
|
|
|
|
using System.Xml.Linq;
|
2016-10-25 06:17:37 -07:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Threading;
|
2017-08-20 18:56:50 -07:00
|
|
|
|
using MatterHackers.MatterControl;
|
2015-05-05 07:25:47 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterControl.Tests
|
|
|
|
|
|
{
|
2018-04-30 15:40:47 -07:00
|
|
|
|
[TestFixture, Apartment(ApartmentState.STA), RunInApplicationDomain]
|
2015-12-22 16:44:54 -08:00
|
|
|
|
public class ReleaseBuildTests
|
|
|
|
|
|
{
|
|
|
|
|
|
private static Type debuggableAttribute = typeof(DebuggableAttribute);
|
|
|
|
|
|
|
|
|
|
|
|
[Test, Category("ReleaseQuality")]
|
|
|
|
|
|
public void MatterControlAssemblyIsOptimized()
|
|
|
|
|
|
{
|
|
|
|
|
|
#if (!DEBUG)
|
2018-09-06 17:16:35 -07:00
|
|
|
|
IsAssemblyOptimized(Assembly.Load("MatterControlLib, Culture=neutral, PublicKeyToken=null"));
|
2015-05-05 07:25:47 -07:00
|
|
|
|
#endif
|
2015-12-22 16:44:54 -08:00
|
|
|
|
}
|
2015-05-05 07:25:47 -07:00
|
|
|
|
|
2015-12-17 12:21:55 -08:00
|
|
|
|
[Test, Category("ReleaseQuality")]
|
|
|
|
|
|
public void MatterControlKnownAssembliesAreOptimized()
|
|
|
|
|
|
{
|
2016-10-11 17:27:43 -07:00
|
|
|
|
#if DEBUG
|
|
|
|
|
|
string configuration = "Debug";
|
|
|
|
|
|
#else
|
|
|
|
|
|
string configuration = "Release";
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2018-08-17 19:19:39 -07:00
|
|
|
|
//MatterHackers.RenderOpenGl.dll
|
|
|
|
|
|
|
2016-10-11 17:27:43 -07:00
|
|
|
|
// This list can be refreshed via the rebuildDependencies() helper function below
|
2018-08-09 11:58:47 -07:00
|
|
|
|
string knownAssemblies = @"VectorMath.dll
|
|
|
|
|
|
Agg.dll
|
|
|
|
|
|
PolygonMesh.dll
|
2019-06-29 09:06:23 -07:00
|
|
|
|
agg_clipper_library.dll
|
2018-08-09 11:58:47 -07:00
|
|
|
|
Gui.dll
|
2015-12-17 12:21:55 -08:00
|
|
|
|
Tesselate.dll
|
2018-08-09 11:58:47 -07:00
|
|
|
|
DataConverters2D.dll
|
2015-12-17 12:21:55 -08:00
|
|
|
|
RayTracer.dll
|
2018-08-09 11:58:47 -07:00
|
|
|
|
DataConverters3D.dll
|
|
|
|
|
|
Localizations.dll
|
2015-12-17 12:21:55 -08:00
|
|
|
|
Community.CsharpSqlite.dll
|
|
|
|
|
|
MatterHackers.Agg.ImageProcessing.dll
|
|
|
|
|
|
MatterHackers.MarchingSquares.dll
|
2018-07-27 22:17:38 -07:00
|
|
|
|
GuiAutomation.dll";
|
2015-12-17 12:21:55 -08:00
|
|
|
|
|
|
|
|
|
|
foreach (string assemblyName in knownAssemblies.Split('\n').Select(s => s.Trim()))
|
|
|
|
|
|
{
|
2016-10-11 17:27:43 -07:00
|
|
|
|
var assemblyPath = TestContext.CurrentContext.ResolveProjectPath(4, "bin", configuration, assemblyName);
|
2015-12-17 12:21:55 -08:00
|
|
|
|
|
2016-10-11 17:27:43 -07:00
|
|
|
|
// Missing/renamed assemblies should fail the test and force a correction
|
2016-10-11 17:42:03 -07:00
|
|
|
|
Assert.IsTrue(File.Exists(assemblyPath), "Assembly missing: " + assemblyPath);
|
2015-12-17 12:21:55 -08:00
|
|
|
|
#if (!DEBUG)
|
2016-10-11 17:27:43 -07:00
|
|
|
|
var assembly = Assembly.LoadFrom(assemblyPath);
|
2015-12-17 12:21:55 -08:00
|
|
|
|
IsAssemblyOptimized(assembly);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void rebuildDependencies()
|
|
|
|
|
|
{
|
2016-10-11 18:00:04 -07:00
|
|
|
|
// Modify path to point at a recent BuildAgent results file
|
2015-12-17 12:21:55 -08:00
|
|
|
|
var elem = XElement.Load(@"C:\Data\Sources\MatterHackers\BuildAndDeployment\MatterControl\build_sln.xml");
|
|
|
|
|
|
var items = elem.Descendants().Where(e => e.Name == "target" && "CopyFilesToOutputDirectory" == (string)e.Attribute("name")).SelectMany(e => e.Elements("message").Select(e2 => e2.Value.TrimEnd('.')).Where(s => s.Contains("Copying") && s.Contains(".dll")));
|
|
|
|
|
|
|
|
|
|
|
|
var referencedItems = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items)
|
|
|
|
|
|
{
|
|
|
|
|
|
var segments = System.Text.RegularExpressions.Regex.Split(item, "to \"");
|
|
|
|
|
|
|
|
|
|
|
|
var relativeAssemblyName = segments[1].TrimEnd('"');
|
|
|
|
|
|
|
|
|
|
|
|
var assemblyName = Path.GetFileName(relativeAssemblyName);
|
|
|
|
|
|
|
|
|
|
|
|
referencedItems.Add(assemblyName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(referencedItems);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-28 10:24:11 -07:00
|
|
|
|
#if !__ANDROID__
|
2018-04-30 15:40:47 -07:00
|
|
|
|
[Test]
|
2016-10-25 06:17:37 -07:00
|
|
|
|
public async Task MatterControlRuns()
|
2016-09-20 14:32:22 -07:00
|
|
|
|
{
|
2017-05-20 15:50:17 -07:00
|
|
|
|
await MatterControlUtilities.RunTest((testRunner) =>
|
2016-09-20 14:32:22 -07:00
|
|
|
|
{
|
2018-10-31 16:23:44 -07:00
|
|
|
|
testRunner.WaitForName("PartPreviewContent");
|
|
|
|
|
|
|
2018-10-29 21:47:03 -07:00
|
|
|
|
Assert.IsTrue(testRunner.NameExists("PartPreviewContent"));
|
2016-10-25 06:17:37 -07:00
|
|
|
|
|
2017-06-04 08:35:29 -07:00
|
|
|
|
return Task.CompletedTask;
|
2017-05-20 15:50:17 -07:00
|
|
|
|
});
|
2016-09-20 14:32:22 -07:00
|
|
|
|
}
|
2016-09-28 10:24:11 -07:00
|
|
|
|
#endif
|
2015-12-17 12:21:55 -08:00
|
|
|
|
|
|
|
|
|
|
[Test, Category("ReleaseQuality")]
|
2015-12-22 16:44:54 -08:00
|
|
|
|
public void MatterControlDependenciesAreOptimized()
|
|
|
|
|
|
{
|
|
|
|
|
|
#if (!DEBUG)
|
2018-09-06 17:16:35 -07:00
|
|
|
|
var matterControl = Assembly.Load("MatterControlLib, Culture=neutral, PublicKeyToken=null");
|
2015-05-05 07:25:47 -07:00
|
|
|
|
|
2017-11-20 14:01:51 -08:00
|
|
|
|
// Loop over all referenced assemblies to verify they are optimized and lack (symbols and Debug compile flag)
|
|
|
|
|
|
foreach (var assemblyName in matterControl.GetReferencedAssemblies())
|
|
|
|
|
|
{
|
|
|
|
|
|
var assembly = Assembly.Load(assemblyName.FullName);
|
|
|
|
|
|
var firstNamespace = assembly?.GetTypes()?.FirstOrDefault()?.Namespace;
|
2015-05-05 07:25:47 -07:00
|
|
|
|
|
2017-11-20 14:01:51 -08:00
|
|
|
|
// Only validate our assemblies
|
2015-06-02 15:08:05 -07:00
|
|
|
|
if (firstNamespace != null && (firstNamespace.Contains("MatterHackers") || firstNamespace.Contains("MatterControl")))
|
2017-11-20 14:01:51 -08:00
|
|
|
|
{
|
|
|
|
|
|
IsAssemblyOptimized(assembly);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-05-05 07:25:47 -07:00
|
|
|
|
#endif
|
2015-12-17 12:21:55 -08:00
|
|
|
|
}
|
2015-05-05 07:25:47 -07:00
|
|
|
|
|
2015-12-17 12:21:55 -08:00
|
|
|
|
[Test, Category("ReleaseQuality")]
|
2015-12-22 16:44:54 -08:00
|
|
|
|
public void ClassicDebugComplicationFlagTests()
|
|
|
|
|
|
{
|
|
|
|
|
|
#if (!DEBUG)
|
2018-10-31 16:23:44 -07:00
|
|
|
|
BuildValidationTests.CheckKnownAssemblyConditionalCompSymbols();
|
2015-05-05 07:25:47 -07:00
|
|
|
|
#endif
|
2015-12-22 16:44:54 -08:00
|
|
|
|
}
|
2015-05-05 07:25:47 -07:00
|
|
|
|
|
2015-12-22 16:44:54 -08:00
|
|
|
|
private static void IsAssemblyOptimized(Assembly assm)
|
|
|
|
|
|
{
|
|
|
|
|
|
var matchedAttributes = assm.GetCustomAttributes(debuggableAttribute, false);
|
|
|
|
|
|
var assemblyName = assm.GetName();
|
2015-05-05 07:25:47 -07:00
|
|
|
|
|
2015-12-22 16:44:54 -08:00
|
|
|
|
if (matchedAttributes.Count() == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.Inconclusive("Symbols likely missing from Release build: " + assemblyName.FullName + ". \r\n\r\nTo resolve the issue, switch Project Properties -> Build -> Advanced -> Debug Info property to 'pdb-only'");
|
|
|
|
|
|
}
|
2015-05-05 07:25:47 -07:00
|
|
|
|
|
2015-12-22 16:44:54 -08:00
|
|
|
|
var debuggable = matchedAttributes.First() as DebuggableAttribute;
|
|
|
|
|
|
Assert.IsFalse(debuggable.IsJITOptimizerDisabled, "Referenced assembly is not optimized: " + assemblyName.Name);
|
2018-09-06 17:16:35 -07:00
|
|
|
|
Assert.IsFalse(debuggable.IsJITTrackingEnabled, "Referenced assembly has symbols: " + assemblyName.Name);
|
2015-12-22 16:44:54 -08:00
|
|
|
|
Console.WriteLine("Assembly is optimized: " + assemblyName.Name);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-05-05 07:25:47 -07:00
|
|
|
|
}
|