Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Nov 21, 2023
2 parents 2dc34e0 + 69f4555 commit 049dba7
Show file tree
Hide file tree
Showing 285 changed files with 25,177 additions and 4,417 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build_n_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ on:
branches: [ master ]

env:
GITHUB_WORKFLOW: BUILD_TEST
LOCAL_ENV: "false"
DELTA: "0.00001"
DECIMAL_PRECISION: "5"
DXF_CONSOLE_CHECK: "true"
DWG_CONSOLE_CHECK: "false"
RUN_DWG_WRITER_SINGLE_CASES_TEST: "false"

jobs:
build:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,5 @@ MigrationBackup/

/local
/samples/local
/local
/samples/out
/ACadTestGenerator
2 changes: 1 addition & 1 deletion ACadSharp.Examples/ACadSharp.Examples.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
22 changes: 14 additions & 8 deletions ACadSharp.Tests/ACadSharp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="coverlet.collector" Version="1.3.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="MSTest.TestAdapter" Version="3.*" />
<PackageReference Include="MSTest.TestFramework" Version="3.*" />
<PackageReference Include="coverlet.collector" Version="6.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.*" />
<PackageReference Include="xunit.extensibility.core" Version="2.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 13 additions & 3 deletions ACadSharp.Tests/CadDocumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,17 @@ public void RemoveCadObject()
Assert.Null(l.LineType.Document);
}

[Fact(Skip = "Implementation in branch : table-operations")]
[Fact]
public void Get0HandleObject()
{
CadDocument doc = new CadDocument();

Assert.Null(doc.GetCadObject(0));
Assert.False(doc.TryGetCadObject(0, out CadObject cadObject));
Assert.Null(cadObject);
}

[Fact]
public void RemoveLayer()
{
string layerName = "custom_layer";
Expand All @@ -189,7 +199,7 @@ public void RemoveLayer()
Assert.Equal(doc.Layers[Layer.DefaultName], line.Layer);
}

[Fact(Skip = "Implementation in branch : table-operations")]
[Fact]
public void RemoveLineType()
{
string ltypeName = "custom_ltype";
Expand All @@ -205,7 +215,7 @@ public void RemoveLineType()
Assert.False(doc.Layers.Contains(ltypeName));
Assert.Null(ltype.Document);
Assert.True(ltype.Handle == 0);
Assert.Equal(doc.LineTypes[LineType.ByBlockName], line.LineType);
Assert.Equal(doc.LineTypes[LineType.ByLayerName], line.LineType);
}

[Fact]
Expand Down
18 changes: 0 additions & 18 deletions ACadSharp.Tests/CadObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,5 @@ public void Clone(Type t)

CadObjectTestUtils.AssertClone(cadObject, clone);
}

[Theory(Skip = "Factory refactor needed")]
[MemberData(nameof(ACadTypes))]
public void CloneUnattachEvent(Type t)
{
CadObject cadObject = Factory.CreateObject(t);
cadObject.OnReferenceChanged += this.cadObject_OnReferenceChanged;

CadObject clone = (CadObject)cadObject.Clone();

CadObjectTestUtils.AssertClone(cadObject, clone);
}

private void cadObject_OnReferenceChanged(object sender, ReferenceChangedEventArgs e)
{
//The clone must not have any attachment
throw new InvalidOperationException();
}
}
}
174 changes: 115 additions & 59 deletions ACadSharp.Tests/ColorTests.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,126 @@
using ACadSharp.Entities;
using ACadSharp.Tests.Common;
using ACadSharp.Tests.Common;
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Xunit;
using Xunit.Abstractions;

namespace ACadSharp.Tests
{
public class ColorTests
{
private ITestOutputHelper _output;

public ColorTests(ITestOutputHelper output)
{
_output = output;
}

[Fact]
public void IndexedColorProperties()
{
Assert.True(new Color(256).IsByLayer);
Assert.True(new Color(0).IsByBlock);
}

private int Int32FromInt24(byte[] array)
{
if (BitConverter.IsLittleEndian)
return array[0] | array[1] << 8 | array[2] << 16;
else
return array[0] << 16 | array[1] << 8 | array[2];
}
[Fact]
public void ParsesTrueColors()
{
var random = new Random();
byte[] colors = new byte[3];
for (int i = 0; i < 1000; i++)
{
random.NextBytes(colors);

var intColor = Int32FromInt24(colors);
var color = new Color(colors);
Assert.True(color.IsTrueColor, color.TrueColor.ToString() + $" Bytes:{colors[0]},{colors[1]},{colors[2]},");
Assert.Equal(intColor, color.TrueColor);
Assert.Equal(-1, color.Index);

var rgb = color.GetTrueColorRgb();
Assert.Equal(colors[0], rgb[0]);
Assert.Equal(colors[1], rgb[1]);
Assert.Equal(colors[2], rgb[2]);
}
}

[Fact]
public void Handles000TrueColor()
{
var color = new Color(new byte[] { 0, 0, 0 });

Assert.True(color.IsTrueColor);
Assert.Equal(0, color.TrueColor);
}

[Fact]
public void HandlesIndexedColors()
{
for (short i = 0; i <= 256; i++)
{
var color = new Color(i);
Assert.False(color.IsTrueColor);
Assert.Equal(i, color.Index);
Assert.Equal(-1, color.TrueColor);
Assert.True(ReadOnlySpan<byte>.Empty.SequenceEqual(color.GetTrueColorRgb()));
}
}
}
Assert.True(new Color(0).IsByBlock);
Assert.True(new Color(256).IsByLayer);

Assert.True(Color.FromTrueColor(2705).IsTrueColor);
Assert.True(Color.FromTrueColor(2706).IsTrueColor);
Assert.True(Color.FromTrueColor(2707).IsTrueColor);
Assert.True(Color.FromTrueColor(2708).IsTrueColor);
}

[Fact]
public void ParsesTrueColors()
{
var random = new Random();
byte[] colors = new byte[3];
for (int i = 0; i < 1000; i++)
{
random.NextBytes(colors);

var intColor = this.int32FromInt24(colors);
var color = new Color(colors);
Assert.True(color.IsTrueColor, color.TrueColor.ToString() + $" Bytes:{colors[0]},{colors[1]},{colors[2]},");
Assert.Equal(intColor, color.TrueColor);
Assert.Equal(-1, color.Index);

var rgb = color.GetTrueColorRgb();
Assert.Equal(colors[0], rgb[0]);
Assert.Equal(colors[1], rgb[1]);
Assert.Equal(colors[2], rgb[2]);
}
}

[Fact]
public void Handles000TrueColor()
{
var color = new Color(new byte[] { 0, 0, 0 });

Assert.True(color.IsTrueColor);
Assert.Equal(0, color.TrueColor);
}

[Fact]
public void HandlesIndexedColors()
{
for (short i = 0; i <= 256; i++)
{
var color = new Color(i);
Assert.False(color.IsTrueColor);
Assert.Equal(i, color.Index);
Assert.Equal(-1, color.TrueColor);
Assert.True(ReadOnlySpan<byte>.Empty.SequenceEqual(color.GetTrueColorRgb()));
}
}

[Fact]
public void GetRgbTest()
{
CSMathRandom random = new CSMathRandom();

byte r = random.Next<byte>();
byte g = random.Next<byte>();
byte b = random.Next<byte>();

Color color = new Color(r, g, b);

this._output.WriteLine($"Color value: {color}");

var rgb = color.GetRgb();

Assert.Equal(r, rgb[0]);
Assert.Equal(g, rgb[1]);
Assert.Equal(b, rgb[2]);
}

[Fact]
public void ByLayerTest()
{
Color byLayer = Color.ByLayer;

this._output.WriteLine($"Color value: {byLayer}");

Assert.True(byLayer.IsByLayer);
Assert.False(byLayer.IsByBlock);
Assert.Equal(256, byLayer.Index);
}

[Fact]
public void ByBlockTest()
{
Color byBlock = Color.ByBlock;

this._output.WriteLine($"Color value: {byBlock}");

Assert.True(byBlock.IsByBlock);
Assert.False(byBlock.IsByLayer);
Assert.Equal(0, byBlock.Index);
}

private int int32FromInt24(byte[] array)
{
if (BitConverter.IsLittleEndian)
return array[0] | array[1] << 8 | array[2] << 16;
else
return array[0] << 16 | array[1] << 8 | array[2];
}
}
}
9 changes: 7 additions & 2 deletions ACadSharp.Tests/Common/CSMathRandom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ public CSMathRandom(int seed) : base(seed) { }

public short NextShort()
{
return (short)Next(short.MinValue, short.MaxValue);
return NextShort(short.MinValue, short.MaxValue);
}

public short NextShort(short min, short max)
{
return (short)Next(min, max);
}

public object Next(Type t)
Expand Down Expand Up @@ -55,7 +60,7 @@ public XYZ NextXYZ()

public Color NextColor()
{
return new Color(this.NextShort());
return new Color(this.NextShort(0, 256));
}

public string RandomString(int length)
Expand Down
3 changes: 2 additions & 1 deletion ACadSharp.Tests/Common/DocumentIntegrity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ public void AssertBlockRecords(CadDocument doc)
foreach (BlockRecord br in doc.BlockRecords)
{
Assert.Equal(br.Name, br.BlockEntity.Name);

Assert.NotNull(br.BlockEntity.Document);
this.documentObjectNotNull(doc, br.BlockEntity);

Assert.True(br.Handle == br.BlockEntity.Owner.Handle, "Block entity owner doesn't mach");

Assert.NotNull(br.BlockEnd.Document);
this.documentObjectNotNull(doc, br.BlockEnd);

foreach (Entity e in br.Entities)
Expand Down
8 changes: 6 additions & 2 deletions ACadSharp.Tests/Common/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ protected static T map<T>(T e)
.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
.Where(o => o.CanWrite && !o.PropertyType.IsClass && !o.PropertyType.IsEnum && !o.PropertyType.IsInterface))
{
p.SetValue(e, _random.Next(p.PropertyType));
try
{
p.SetValue(e, _random.Next(p.PropertyType));
}
catch (Exception) { }
}

return e;
Expand All @@ -54,7 +58,7 @@ private static CadObject createObject(Type type, Type original, bool randomize)
return null;
}

if (type == typeof(XRecrod)
if (type == typeof(XRecord)
|| type == typeof(PlotSettings)
|| type == typeof(Material)
|| type == typeof(MLStyle)
Expand Down
Loading

0 comments on commit 049dba7

Please sign in to comment.