2016-05-19 17:55:46 -07:00
using MatterHackers.MatterControl ;
using NUnit.Framework ;
using System ;
using System.IO ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.Linq ;
using System.Reflection ;
using System.Text ;
using System.Globalization ;
using MatterHackers.MatterControl.SlicerConfiguration ;
2016-07-19 17:28:06 -07:00
using System.Collections.ObjectModel ;
2016-07-20 15:23:26 -07:00
using MatterHackers.Agg.PlatformAbstract ;
2016-07-20 20:05:56 -07:00
using MatterHackers.MatterControl.Tests.Automation ;
2016-05-19 17:55:46 -07:00
namespace MatterControl.Tests.MatterControl
{
2016-07-26 15:34:52 -07:00
[TestFixture, Category("OemProfiles")]
public class OemProfileTests
2016-05-19 17:55:46 -07:00
{
private static List < PrinterConfig > allPrinters ;
private static string matterControlDirectory = Path . GetFullPath ( Path . Combine ( ".." , ".." , ".." , ".." ) ) ;
2016-07-19 17:28:06 -07:00
private static string printerSettingsDirectory = Path . GetFullPath ( Path . Combine ( matterControlDirectory , "StaticData" , "Profiles" ) ) ;
2016-05-19 17:55:46 -07:00
2016-07-26 15:34:52 -07:00
static OemProfileTests ( )
2016-05-19 17:55:46 -07:00
{
2016-07-20 20:05:56 -07:00
MatterControlUtilities . OverrideAppDataLocation ( ) ;
2016-07-20 15:23:26 -07:00
StaticData . Instance = new MatterHackers . Agg . FileSystemStaticData ( Path . Combine ( matterControlDirectory , "StaticData" ) ) ;
allPrinters = ( from printerFile in new DirectoryInfo ( printerSettingsDirectory ) . GetFiles ( "*.printer" , SearchOption . AllDirectories )
2016-05-19 17:55:46 -07:00
select new PrinterConfig
{
2016-07-19 17:28:06 -07:00
PrinterName = printerFile . Name ,
2016-08-08 15:58:55 -07:00
Oem = printerFile . Directory . Name ,
2016-07-19 17:28:06 -07:00
ConfigPath = printerFile . FullName ,
2016-07-20 15:23:26 -07:00
RelativeFilePath = printerFile . FullName . Substring ( printerSettingsDirectory . Length + 1 ) ,
PrinterSettings = PrinterSettings . LoadFile ( printerFile . FullName )
2016-05-19 17:55:46 -07:00
} ) . ToList ( ) ;
2016-06-07 09:41:12 -07:00
}
2016-07-25 16:13:20 -07:00
[Test]
2016-07-26 15:32:36 -07:00
public void StartGCodeWithExtrudesMustFollowM109Heatup ( )
2016-07-25 16:13:20 -07:00
{
ValidateOnAllPrinters ( ( printer , settings ) = >
{
2016-07-26 15:32:36 -07:00
// Get the start_gcode string
string startGcode = settings . OemLayer . ValueOrDefault ( SettingsKey . start_gcode ) ? ? string . Empty ;
2016-07-25 16:13:20 -07:00
2016-07-26 15:32:36 -07:00
// Only validate start_gcode configs that have M109 and extrude statements
if ( startGcode . Contains ( "M109" ) & & startGcode . Contains ( "G1 E" ) )
2016-07-25 16:13:20 -07:00
{
2016-07-26 15:32:36 -07:00
// Split start_gcode on newlines
2016-07-25 16:13:20 -07:00
var lines = startGcode . Split ( new string [ ] { "\\n" } , StringSplitOptions . RemoveEmptyEntries ) . Select ( l = > l . ToUpper ( ) . Trim ( ) ) . ToList ( ) ;
2016-07-26 15:32:36 -07:00
// Find first instance of M109 or 'G1 E' extrude
2016-07-25 16:13:20 -07:00
string m109Line = lines . Where ( l = > l . StartsWith ( "M109 " ) ) . FirstOrDefault ( ) ;
2016-07-26 15:32:36 -07:00
string extrudeLine = lines . Where ( l = > l . StartsWith ( "G1 E" ) ) . FirstOrDefault ( ) ;
2016-07-25 16:13:20 -07:00
if ( m109Line = = null )
{
printer . RuleViolated = true ;
return ;
}
int m109Pos = lines . IndexOf ( m109Line ) ;
2016-07-26 15:32:36 -07:00
int extrudePos = lines . IndexOf ( extrudeLine ) ;
2016-07-25 16:13:20 -07:00
Assert . IsNotNull ( m109Line ) ;
//Assert.IsNotNull(emptyExtrudeLine);
//Assert.Greater(emptyExtrudePos, m109Pos);
2016-07-26 15:32:36 -07:00
if ( extrudePos < m109Pos )
2016-07-25 16:13:20 -07:00
{
printer . RuleViolated = true ;
}
}
} ) ;
}
2016-05-19 17:55:46 -07:00
[Test]
public void CsvBedSizeExistsAndHasTwoValues ( )
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-06-07 09:49:48 -07:00
// Bed size is not required in slice files
2016-07-20 15:23:26 -07:00
if ( printer . RelativeFilePath . IndexOf ( ".slice" , StringComparison . OrdinalIgnoreCase ) ! = - 1 )
2016-06-07 09:49:48 -07:00
{
return ;
}
2016-06-07 09:41:12 -07:00
2016-07-20 15:23:26 -07:00
string bedSize = settings . GetValue ( SettingsKey . bed_size ) ;
2016-05-19 17:55:46 -07:00
// Must exist in all configs
2016-07-20 15:23:26 -07:00
Assert . IsNotNullOrEmpty ( bedSize , "[bed_size] must exist: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
string [ ] segments = bedSize . Trim ( ) . Split ( ',' ) ;
// Must be a CSV and have two values
2016-07-20 15:23:26 -07:00
Assert . AreEqual ( 2 , segments . Length , "[bed_size] should have two values separated by a comma: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
} ) ;
}
[Test]
public void CsvPrintCenterExistsAndHasTwoValues ( )
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-06-07 09:49:48 -07:00
// Printer center is not required in slice files
2016-07-20 15:23:26 -07:00
if ( printer . RelativeFilePath . IndexOf ( ".slice" , StringComparison . OrdinalIgnoreCase ) ! = - 1 )
2016-06-07 09:49:48 -07:00
{
return ;
}
2016-07-20 15:23:26 -07:00
string printCenter = settings . GetValue ( SettingsKey . print_center ) ;
2016-05-19 17:55:46 -07:00
// Must exist in all configs
2016-07-20 15:23:26 -07:00
Assert . IsNotNullOrEmpty ( printCenter , "[print_center] must exist: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
string [ ] segments = printCenter . Trim ( ) . Split ( ',' ) ;
// Must be a CSV and have only two values
2016-07-20 15:23:26 -07:00
Assert . AreEqual ( 2 , segments . Length , "[print_center] should have two values separated by a comma: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
} ) ;
}
[Test]
public void RetractLengthIsLessThanTwenty ( )
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
string retractLengthString = settings . GetValue ( "retract_length" ) ;
2016-05-19 17:55:46 -07:00
if ( ! string . IsNullOrEmpty ( retractLengthString ) )
{
float retractLength ;
if ( ! float . TryParse ( retractLengthString , out retractLength ) )
{
2016-07-20 15:23:26 -07:00
Assert . Fail ( "Invalid [retract_length] value (float parse failed): " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
}
2016-07-20 15:23:26 -07:00
Assert . Less ( retractLength , 20 , "[retract_length]: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
}
} ) ;
}
[Test]
public void ExtruderCountIsGreaterThanZero ( )
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
string extruderCountString = settings . GetValue ( "extruder_count" ) ;
2016-05-25 11:04:51 -07:00
if ( ! string . IsNullOrEmpty ( extruderCountString ) )
2016-05-19 17:55:46 -07:00
{
2016-05-25 11:04:51 -07:00
int extruderCount ;
if ( ! int . TryParse ( extruderCountString , out extruderCount ) )
{
2016-07-20 15:23:26 -07:00
Assert . Fail ( "Invalid [extruder_count] value (int parse failed): " + printer . RelativeFilePath ) ;
2016-05-25 11:04:51 -07:00
}
2016-05-19 17:55:46 -07:00
2016-05-25 11:04:51 -07:00
// Must be greater than zero
2016-07-20 15:23:26 -07:00
Assert . Greater ( extruderCount , 0 , "[extruder_count]: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
}
} ) ;
}
[Test]
public void MinFanSpeedOneHundredOrLess ( )
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
string fanSpeedString = settings . GetValue ( "min_fan_speed" ) ;
2016-05-19 17:55:46 -07:00
if ( ! string . IsNullOrEmpty ( fanSpeedString ) )
{
// Must be valid int data
int minFanSpeed ;
if ( ! int . TryParse ( fanSpeedString , out minFanSpeed ) )
{
2016-07-20 15:23:26 -07:00
Assert . Fail ( "Invalid [min_fan_speed] value (int parse failed): " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
}
// Must be less than or equal to 100
2016-07-20 15:23:26 -07:00
Assert . LessOrEqual ( minFanSpeed , 100 , "[min_fan_speed]: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
}
} ) ;
}
2016-07-25 14:18:56 -07:00
[Test]
public void PlaAndAbsDensitySetCorrectly ( )
{
ValidateOnAllPrinters ( ( printer , settings ) = >
{
2016-08-10 14:04:33 -07:00
if ( settings . OemLayer . ContainsKey ( SettingsKey . layer_name ) )
2016-07-25 14:18:56 -07:00
{
2016-08-10 14:04:33 -07:00
if ( settings . OemLayer [ SettingsKey . layer_name ] . ToUpper ( ) = = "ABS" )
2016-07-25 14:18:56 -07:00
{
double absDensity = settings . GetValue < double > ( SettingsKey . filament_density ) ;
if ( absDensity ! = 1.04 )
{
Assert . Fail ( "[filament_density] value should be set to ABS 1.04: " + printer . RelativeFilePath ) ;
}
}
2016-08-10 14:04:33 -07:00
else if ( settings . OemLayer [ SettingsKey . layer_name ] . ToUpper ( ) = = "PLA" )
2016-07-25 14:18:56 -07:00
{
double absDensity = settings . GetValue < double > ( SettingsKey . filament_density ) ;
if ( absDensity ! = 1.24 )
{
Assert . Fail ( "[filament_density] value should be set to PLA 1.24: " + printer . RelativeFilePath ) ;
}
}
}
} ) ;
}
2016-05-19 17:55:46 -07:00
[Test]
public void MaxFanSpeedOneHundredOrLess ( )
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
string fanSpeedString = settings . GetValue ( "max_fan_speed" ) ;
2016-05-19 17:55:46 -07:00
if ( ! string . IsNullOrEmpty ( fanSpeedString ) )
{
// Must be valid int data
int maxFanSpeed ;
if ( ! int . TryParse ( fanSpeedString , out maxFanSpeed ) )
{
2016-07-20 15:23:26 -07:00
Assert . Fail ( "Invalid [max_fan_speed] value (int parse failed): " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
}
// Must be less than or equal to 100
2016-07-20 15:23:26 -07:00
Assert . LessOrEqual ( maxFanSpeed , 100 , "[max_fan_speed]: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
}
} ) ;
}
[Test]
public void NoCurlyBracketsInGcode ( )
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
// TODO: Why aren't we testing all gcode sections?
string [ ] keysToTest = { "start_gcode" , "end_gcode" } ;
foreach ( string gcodeKey in keysToTest )
{
2016-07-20 15:23:26 -07:00
string gcode = settings . GetValue ( gcodeKey ) ;
2016-05-19 17:55:46 -07:00
if ( gcode . Contains ( "{" ) | | gcode . Contains ( "}" ) )
{
2016-07-20 15:23:26 -07:00
Assert . Fail ( string . Format ( "[{0}] Curly brackets not allowed: {1}" , gcodeKey , printer . RelativeFilePath ) ) ;
2016-05-19 17:55:46 -07:00
}
}
} ) ;
}
2016-07-20 15:38:38 -07:00
[Test]
2016-05-19 17:55:46 -07:00
public void BottomSolidLayersEqualsOneMM ( )
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
string bottomSolidLayers = settings . GetValue ( "bottom_solid_layers" ) ;
2016-05-23 15:28:46 -07:00
if ( ! string . IsNullOrEmpty ( bottomSolidLayers ) )
2016-05-19 17:55:46 -07:00
{
2016-05-23 15:28:46 -07:00
if ( bottomSolidLayers ! = "1mm" )
{
printer . RuleViolated = true ;
return ;
}
2016-05-19 17:55:46 -07:00
2016-07-20 15:23:26 -07:00
Assert . AreEqual ( "1mm" , bottomSolidLayers , "[bottom_solid_layers] must be 1mm: " + printer . RelativeFilePath ) ;
2016-05-23 15:28:46 -07:00
}
2016-05-19 17:55:46 -07:00
} ) ;
}
[Test]
public void NoFirstLayerTempInStartGcode ( )
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
string startGcode = settings . GetValue ( "start_gcode" ) ;
Assert . False ( startGcode . Contains ( "first_layer_temperature" ) , "[start_gcode] should not contain [first_layer_temperature]" + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
} ) ;
}
[Test]
public void NoFirstLayerBedTempInStartGcode ( )
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
string startGcode = settings . GetValue ( "start_gcode" ) ;
Assert . False ( startGcode . Contains ( "first_layer_bed_temperature" ) , "[start_gcode] should not contain [first_layer_bed_temperature]" + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
} ) ;
}
2016-08-08 15:58:55 -07:00
[Test]
2016-05-25 11:04:51 -07:00
public void FirstLayerHeightLessThanNozzleDiameterXExtrusionMultiplier ( )
2016-05-19 17:55:46 -07:00
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
if ( settings . GetValue ( "output_only_first_layer" ) = = "1" )
2016-05-31 15:11:29 -07:00
{
return ;
}
2016-07-20 15:23:26 -07:00
float nozzleDiameter = float . Parse ( settings . GetValue ( SettingsKey . nozzle_diameter ) ) ;
float layerHeight = float . Parse ( settings . GetValue ( SettingsKey . layer_height ) ) ;
2016-05-19 17:55:46 -07:00
2016-05-25 11:04:51 -07:00
float firstLayerExtrusionWidth ;
2016-07-20 15:23:26 -07:00
string firstLayerExtrusionWidthString = settings . GetValue ( SettingsKey . first_layer_extrusion_width ) ;
2016-05-25 11:04:51 -07:00
if ( ! string . IsNullOrEmpty ( firstLayerExtrusionWidthString ) & & firstLayerExtrusionWidthString . Trim ( ) ! = "0" )
{
firstLayerExtrusionWidth = ValueOrPercentageOf ( firstLayerExtrusionWidthString , nozzleDiameter ) ;
}
else
{
firstLayerExtrusionWidth = nozzleDiameter ;
}
2016-07-20 15:23:26 -07:00
string firstLayerHeightString = settings . GetValue ( SettingsKey . first_layer_height ) ;
2016-05-19 17:55:46 -07:00
if ( ! string . IsNullOrEmpty ( firstLayerHeightString ) )
{
float firstLayerHeight = ValueOrPercentageOf ( firstLayerHeightString , layerHeight ) ;
2016-08-08 15:58:55 -07:00
double maximumLayerHeight = firstLayerExtrusionWidth * 0.85 ;
2016-05-25 11:04:51 -07:00
2016-05-19 17:55:46 -07:00
// TODO: Remove once validated and resolved
2016-08-08 15:58:55 -07:00
if ( firstLayerHeight > = maximumLayerHeight )
2016-05-19 17:55:46 -07:00
{
printer . RuleViolated = true ;
return ;
}
2016-08-08 15:58:55 -07:00
Assert . Less ( firstLayerHeight , maximumLayerHeight , "[first_layer_height] must be less than [firstLayerExtrusionWidth]: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
}
2016-05-25 11:04:51 -07:00
2016-05-19 17:55:46 -07:00
} ) ;
}
2016-08-08 15:58:55 -07:00
[Test]
2016-05-23 14:30:27 -07:00
public void LayerHeightLessThanNozzleDiameter ( )
2016-05-19 17:55:46 -07:00
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
if ( settings . GetValue ( "output_only_first_layer" ) = = "1" )
2016-05-31 15:18:16 -07:00
{
return ;
}
2016-07-20 15:23:26 -07:00
float nozzleDiameter = float . Parse ( settings . GetValue ( SettingsKey . nozzle_diameter ) ) ;
float layerHeight = float . Parse ( settings . GetValue ( SettingsKey . layer_height ) ) ;
2016-05-19 17:55:46 -07:00
2016-08-08 15:58:55 -07:00
double maximumLayerHeight = nozzleDiameter * 85 ;
2016-05-25 11:04:51 -07:00
2016-05-19 17:55:46 -07:00
// TODO: Remove once validated and resolved
2016-08-08 15:58:55 -07:00
if ( layerHeight > = maximumLayerHeight )
2016-05-19 17:55:46 -07:00
{
printer . RuleViolated = true ;
return ;
}
2016-08-08 15:58:55 -07:00
Assert . Less ( layerHeight , maximumLayerHeight , "[layer_height] must be less than [minimumLayerHeight]: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
} ) ;
}
[Test]
2016-05-25 11:04:51 -07:00
public void FirstLayerExtrusionWidthGreaterThanNozzleDiameterIfSet ( )
2016-05-19 17:55:46 -07:00
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
float nozzleDiameter = float . Parse ( settings . GetValue ( SettingsKey . nozzle_diameter ) ) ;
2016-05-19 17:55:46 -07:00
2016-07-20 15:23:26 -07:00
string firstLayerExtrusionWidthString = settings . GetValue ( SettingsKey . first_layer_extrusion_width ) ;
2016-05-19 17:55:46 -07:00
if ( ! string . IsNullOrEmpty ( firstLayerExtrusionWidthString ) )
{
float firstLayerExtrusionWidth = ValueOrPercentageOf ( firstLayerExtrusionWidthString , nozzleDiameter ) ;
2016-05-25 11:04:51 -07:00
if ( firstLayerExtrusionWidth = = 0 )
2016-05-19 17:55:46 -07:00
{
2016-05-25 11:04:51 -07:00
// Ignore zeros
2016-05-19 17:55:46 -07:00
return ;
}
2016-07-20 15:23:26 -07:00
Assert . GreaterOrEqual ( firstLayerExtrusionWidth , nozzleDiameter , "[first_layer_extrusion_width] must be nozzle diameter or greater: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
}
} ) ;
}
[Test]
public void SupportMaterialAssignedToExtruderOne ( )
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
string supportMaterialExtruder = settings . GetValue ( "support_material_extruder" ) ;
2016-05-23 14:30:27 -07:00
if ( ! string . IsNullOrEmpty ( supportMaterialExtruder ) & & printer . Oem ! = "Esagono" )
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
Assert . AreEqual ( "1" , supportMaterialExtruder , "[support_material_extruder] must be assigned to extruder 1: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
}
} ) ;
}
2016-08-08 15:58:55 -07:00
[Test]
2016-05-19 17:55:46 -07:00
public void SupportInterfaceMaterialAssignedToExtruderOne ( )
{
2016-06-07 11:22:53 -07:00
ValidateOnAllPrinters ( ( printer , settings ) = >
2016-05-19 17:55:46 -07:00
{
2016-06-09 16:02:54 -07:00
// Make exception for extruder assignment on 3D Stuffmaker slice files
2016-08-08 15:58:55 -07:00
if ( printer . Oem = = "3D Stuffmaker" )
2016-06-09 16:02:54 -07:00
{
return ;
}
2016-07-20 15:23:26 -07:00
string supportMaterialInterfaceExtruder = settings . GetValue ( "support_material_interface_extruder" ) ;
2016-05-23 14:30:27 -07:00
if ( ! string . IsNullOrEmpty ( supportMaterialInterfaceExtruder ) & & printer . Oem ! = "Esagono" )
2016-05-19 17:55:46 -07:00
{
2016-07-20 15:23:26 -07:00
Assert . AreEqual ( "1" , supportMaterialInterfaceExtruder , "[support_material_interface_extruder] must be assigned to extruder 1: " + printer . RelativeFilePath ) ;
2016-05-19 17:55:46 -07:00
}
} ) ;
}
private static float ValueOrPercentageOf ( string valueOrPercent , float baseValue )
{
if ( valueOrPercent . Contains ( "%" ) )
{
float percentage = float . Parse ( valueOrPercent . Replace ( "%" , "" ) ) / 100 ;
return baseValue * percentage ;
}
else
{
return float . Parse ( valueOrPercent ) ;
}
}
/// <summary>
/// Calls the given delegate for each known printer, passing in a PrinterConfig object that has
2016-07-20 15:23:26 -07:00
/// printer settings loaded into a SettingsLayer as well as state about the printer
2016-05-19 17:55:46 -07:00
/// </summary>
/// <param name="action">The action to invoke for each printer</param>
2016-07-20 15:23:26 -07:00
private void ValidateOnAllPrinters ( Action < PrinterConfig , PrinterSettings > action )
2016-05-19 17:55:46 -07:00
{
var ruleViolations = new List < string > ( ) ;
foreach ( var printer in allPrinters )
{
printer . RuleViolated = false ;
2016-06-07 09:41:12 -07:00
2016-07-20 15:23:26 -07:00
PrinterSettingsLayer oemLayer = printer . PrinterSettings . OemLayer ;
action ( printer , new PrinterSettings ( ) { OemLayer = oemLayer } ) ;
2016-05-19 17:55:46 -07:00
if ( printer . RuleViolated )
{
2016-07-20 15:23:26 -07:00
ruleViolations . Add ( printer . RelativeFilePath ) ;
2016-06-07 09:41:12 -07:00
}
2016-07-20 15:23:26 -07:00
foreach ( var layer in printer . PrinterSettings . MaterialLayers )
2016-06-07 09:41:12 -07:00
{
printer . RuleViolated = false ;
2016-07-20 15:23:26 -07:00
action ( printer , new PrinterSettings ( ) { BaseLayer = oemLayer , OemLayer = layer } ) ;
2016-06-07 09:41:12 -07:00
if ( printer . RuleViolated )
{
2016-07-20 15:23:26 -07:00
ruleViolations . Add ( printer . RelativeFilePath + " -> " + layer . Name ) ;
2016-06-07 09:41:12 -07:00
}
}
2016-07-20 15:23:26 -07:00
foreach ( var layer in printer . PrinterSettings . QualityLayers )
2016-06-07 09:41:12 -07:00
{
printer . RuleViolated = false ;
2016-07-20 15:23:26 -07:00
action ( printer , new PrinterSettings ( ) { BaseLayer = oemLayer , OemLayer = layer } ) ;
2016-06-07 09:41:12 -07:00
if ( printer . RuleViolated )
{
2016-07-20 15:23:26 -07:00
ruleViolations . Add ( printer . RelativeFilePath + " -> " + layer . Name ) ;
2016-06-07 09:41:12 -07:00
}
2016-05-19 17:55:46 -07:00
}
}
2016-05-23 14:30:27 -07:00
Assert . IsTrue (
ruleViolations . Count = = 0 , /* Use == instead of Assert.AreEqual to better convey failure details */
string . Format ( "One or more printers violate this rule: \r\n\r\n{0}\r\n" , string . Join ( "\r\n" , ruleViolations . ToArray ( ) ) ) ) ;
2016-05-19 17:55:46 -07:00
}
private class PrinterConfig
{
public string PrinterName { get ; set ; }
public string Oem { get ; set ; }
public string ConfigPath { get ; set ; }
2016-07-20 15:23:26 -07:00
public string RelativeFilePath { get ; set ; }
public PrinterSettings PrinterSettings { get ; set ; }
2016-05-19 17:55:46 -07:00
// HACK: short term hack to support a general purpose test rollup function for cases where multiple config files
// violate a rule and in the short term we want to report and resolve the issues in batch rather than having a
// single test failure. Long term the single test failure better communicates the issue and assist with troubleshooting
// by using .AreEqual .LessOrEqual, etc. to communicate intent
public bool RuleViolated { get ; set ; } = false ;
}
}
}