diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e2bd1ea..6cb6835 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,10 +67,8 @@ Run the compile check with a separate artifact directory. dotnet build src/DwgIO.Scene/DwgIO.Scene.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path ./artifacts/native-core-check ``` -Tests that need real drawings are skipped with a message when no drawing is -available. Set `DWGIO_TEST_FILES` to the folder containing your private -drawings, or place them in a `test_files` folder, to run them. The repository -ships no drawings. See [test fixtures](docs/test-fixtures.md). +CI exercises the committed public drawings. Set `DWGIO_TEST_FILES` to the folder containing your private +drawings, or place them in a `test_files` folder, to include them in local tests. See [test fixtures](docs/test-fixtures.md). ## Code conventions diff --git a/README.md b/README.md index a206203..1928624 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,8 @@ dotnet build DwgIO.slnx -c Release dotnet test ``` -Tests requiring real DWG files are skipped with a message unless `DWGIO_TEST_FILES` or a `test_files` folder provides private drawings. The repository includes no DWG drawings. See [test fixtures](docs/test-fixtures.md). +CI uses committed public drawings for R2010, R2013 and R2018. Set `DWGIO_TEST_FILES` or use a +`test_files` folder to include private drawings in local tests. See [test fixtures](docs/test-fixtures.md). ## Contributing diff --git a/docs/test-fixtures.md b/docs/test-fixtures.md index a66bc5e..c91303a 100644 --- a/docs/test-fixtures.md +++ b/docs/test-fixtures.md @@ -1,15 +1,18 @@ -# Private test fixtures +# DWG test fixtures Most tests build their input in the test itself (cipher, decompression, checksums, bit reading, version detection, handle map, object stream and metadata parsing) and run everywhere. The fixture tests in `DwgFixtureTests` need real -drawings. The repository ships no drawings yet. Private fixtures belong in the ignored test folder or outside the -repository. Small redistributable drawings can be added under `test-files/public`. Once available, the fixture -tests will use them in CI on Windows, Linux and macOS. +drawings. The committed [public primitives](https://github.com/IOExtend/DwgIO/blob/main/test-files/public/README.md) cover R2010, R2013 and R2018 +in CI on Windows, Linux and macOS. Private fixtures still belong in the ignored test folder or outside the +repository. ## Where the drawings are looked for -The fixture tests find their input through one helper, `TestFiles` in the test project. Drawings are taken from all -of these folders together: +The required `PublicDrawing_DecodesAuthoredPrimitives` theory reads only the three committed drawings, copied +to a dedicated subfolder of the test output at build time. This works even when `--artifacts-path` places the +assembly outside the checkout. + +The optional fixture checks take drawings from all of these folders together: - the folder named by the environment variable `DWGIO_TEST_FILES` (ignored when the folder does not exist); - the committed redistributable drawings of [test-files/public](https://github.com/IOExtend/DwgIO/blob/main/test-files/public/README.md), with their @@ -17,17 +20,18 @@ of these folders together: - a folder `test_files` in the repository root (or in any parent of the test binary folder). Every `*.dwg` file directly in such a folder or in one level of subfolders is used, whatever its name. Drawings of the -supported releases (AC1018, AC1024, AC1027, AC1032) are the useful ones. AC1018 has been checked on real local drawings and -still needs a redistributable fixture. Drawings of an unsupported version +supported releases (AC1018, AC1024, AC1027, AC1032) are the useful ones. AC1018 still needs a public fixture. +Drawings of an unsupported version (AC1012 to AC1015, AC1021) are ignored by the fixture tests and counted in the skip reason, so one file of a planned release does not fail every test. ## Without drawings -When no drawing is found, the fixture tests are reported as **skipped with a reason** that names `DWGIO_TEST_FILES`. -They never pass silently and never fail for lack of a file. The attributes `[SkippableFact]` and `[SkippableTheory]` -(`SkippableFact.cs`) report a test that throws `SkipException` as skipped, because xunit 2.9 has no runtime skip of its -own; `TestFiles` throws it when no drawing is available. +Optional fixture checks are reported as **skipped with a reason** when no eligible drawing is available. +If no drawing is found, the reason names `DWGIO_TEST_FILES`. The attributes `[SkippableFact]` and +`[SkippableTheory]` (`SkippableFact.cs`) report `SkipException` as a skip, because xunit 2.9 has no runtime skip +of its own. The public geometry theory requires all three committed drawings and fails if any is missing +from the test output. No test uses a fixed absolute path. @@ -39,5 +43,5 @@ DWGIO_TEST_FILES= dotnet test In PowerShell: `$env:DWGIO_TEST_FILES = ''; dotnet test`. -Do not commit drawings, and do not put file names, object counts or other details of private drawings into tests, +Do not commit private drawings or put their file names, object counts or other details into tests, comments or documentation. diff --git a/docs/toc.yml b/docs/toc.yml index d675fed..e561bac 100644 --- a/docs/toc.yml +++ b/docs/toc.yml @@ -5,7 +5,7 @@ items: - name: Public API href: public-api.md - - name: Private test fixtures + - name: DWG test fixtures href: test-fixtures.md - name: API reference href: api/ diff --git a/test-files/public/README.md b/test-files/public/README.md index 8a76c53..5234741 100644 --- a/test-files/public/README.md +++ b/test-files/public/README.md @@ -1,9 +1,61 @@ # Redistributable test drawings (#33) -This folder is reserved for small DWG files whose licence allows redistribution, one per supported release -(AC1018, AC1024, AC1027, AC1032 — then AC1012 to AC1015 as the readers for those land). The fixture tests -run over every drawing in the fixture folders, so a drawing committed here turns its skipped tests into -real runs in CI on all three systems. +These small DWG drawings exercise R2010, R2013 and R2018 in CI on Windows, Linux and macOS. + +| Drawing | DWG release | SHA-256 of the committed file | +| --- | --- | --- | +| `primitives-ac1024.dwg` | AC1024 (2010) | `e28711b8b875d7d8203e0eef784304e39c95d12e44d28b236fa0765c700c372c` | +| `primitives-ac1027.dwg` | AC1027 (2013) | `1f04c46e0af453898f941b3242843bf07576a55f9066ec52db5830b331dc28c3` | +| `primitives-ac1032.dwg` | AC1032 (2018) | `73443dc0d95e9081aeb16ddb9c7f223ccb96541368c1f08ef4c5318aba3bd112` | + +**Origin and licence:** Each drawing was created from scratch for DwgIO #33 and is distributed +under [DwgIO's MIT licence](../../LICENSE). The independent writer is +[ACadSharp 3.8.35](https://www.nuget.org/packages/ACadSharp/3.8.35) (MIT). +No vendor or third-party drawing, writer implementation, or assembly is included. + +**Contents:** Model space, default layer `0`: one line from (1, 2, 3) to (4, 6, 8), one arc +centred at (-3, 7, 2) with radius 5 from π/6 to π/2 radians, one circle centred at (7, -2, 1) +with radius 4, and one point at (-5, -6, 9). These values are authored inputs, not values +captured from DwgIO. The xUnit theory checks the decoded values and version for every file. + +**Remaining coverage:** AC1018 (R2004) still needs a compatible public fixture. An ACadSharp 3.8.35 +R2004 candidate reopened in that writer's reader, but DwgIO did not decode the four authored entities +and failed its AppInfo and handle-map fixture checks. It is not committed. + +### Regenerating equivalent drawings + +Outside this repository, create a disposable .NET 10 console project and add the pinned writer: + +```sh +dotnet new console --framework net10.0 -o DwgFixtureGenerator +cd DwgFixtureGenerator +dotnet add package ACadSharp --version 3.8.35 +``` + +Replace `Program.cs` with this original fixture recipe: + +```csharp +using ACadSharp; +using ACadSharp.Entities; +using ACadSharp.IO; +using CSMath; + +foreach (var version in new[] { ACadVersion.AC1024, ACadVersion.AC1027, ACadVersion.AC1032 }) +{ + var drawing = new CadDocument(version); + drawing.Entities.Add(new Line(new XYZ(1, 2, 3), new XYZ(4, 6, 8))); + drawing.Entities.Add(new Arc(new XYZ(-3, 7, 2), 5, Math.PI / 6, Math.PI / 2)); + drawing.Entities.Add(new Circle(new XYZ(7, -2, 1), 4)); + drawing.Entities.Add(new Point(new XYZ(-5, -6, 9))); + var name = $"primitives-{version.ToString().ToLowerInvariant()}.dwg"; + DwgWriter.Write(name, drawing); +} +``` + +Run `dotnet run -c Release`. Writer metadata such as timestamps can change the bytes, so the hashes +above identify the committed drawings, not all equivalent regenerations. Validate the version and +geometry with DwgIO before replacing a file, then update the recorded hash. These fixtures exercise +the independent writer's output, not every DWG writer or entity kind. ## How a drawing qualifies @@ -19,6 +71,8 @@ see `docs/test-fixtures.md`) remains the place for larger local test sets. ## The fixture search -`TestFiles` looks for drawings in the folder named by `DWGIO_TEST_FILES`, in a `test_files` folder and in -this `test-files/public` folder; one level of subfolders is searched too. Nothing else about the search -changes: unsupported versions are skipped and counted, and a missing drawing never fails a test. +For optional fixture checks, `TestFiles` looks in `DWGIO_TEST_FILES`, ancestor `test_files` and +`test-files/public` folders, and one level of subfolders. Unsupported versions are skipped and counted; +checks with no eligible drawing are skipped. The required `PublicDrawing_DecodesAuthoredPrimitives` theory +instead reads the three committed files copied into the test output at build time. A missing copy fails +that theory even when no private drawings are configured. diff --git a/test-files/public/primitives-ac1024.dwg b/test-files/public/primitives-ac1024.dwg new file mode 100644 index 0000000..6a25c65 Binary files /dev/null and b/test-files/public/primitives-ac1024.dwg differ diff --git a/test-files/public/primitives-ac1027.dwg b/test-files/public/primitives-ac1027.dwg new file mode 100644 index 0000000..c9cbcd2 Binary files /dev/null and b/test-files/public/primitives-ac1027.dwg differ diff --git a/test-files/public/primitives-ac1032.dwg b/test-files/public/primitives-ac1032.dwg new file mode 100644 index 0000000..b71131d Binary files /dev/null and b/test-files/public/primitives-ac1032.dwg differ diff --git a/tests/DwgIO.Tests/DwgFixtureTests.cs b/tests/DwgIO.Tests/DwgFixtureTests.cs index 2e66a52..bedbfdd 100644 --- a/tests/DwgIO.Tests/DwgFixtureTests.cs +++ b/tests/DwgIO.Tests/DwgFixtureTests.cs @@ -4,9 +4,9 @@ namespace DwgIO.Tests; /// -/// Smoke tests against private DWG files located by (DWGIO_TEST_FILES or a -/// test_files folder; no fixtures are committed to the repository). Each test checks every file and reports -/// all failing files at once; with no file available it is reported as skipped with the reason. +/// Smoke tests against committed public or optional private DWG files located by . +/// Each test checks every file and reports all failing files at once; if no eligible file is available, +/// the test is reported as skipped with the reason. /// public class DwgFixtureTests { @@ -39,8 +39,8 @@ internal static void CheckAll(Func check, string requirement) if (checkedFiles == 0) { throw new SkipException(unsupported > 0 - ? $"No private fixture has {requirement}; {unsupported} drawing(s) of an unsupported version were ignored." - : $"No private fixture has {requirement}."); + ? $"No fixture has {requirement}; {unsupported} drawing(s) of an unsupported version were ignored." + : $"No fixture has {requirement}."); } } @@ -53,6 +53,33 @@ private static bool HasReadableSection(DwgDocument doc, string name) => private static string Diagnostics(DwgDocument doc) => string.Join(" | ", doc.Diagnostics); + [Theory] + [InlineData("AC1024", "primitives-ac1024.dwg")] + [InlineData("AC1027", "primitives-ac1027.dwg")] + [InlineData("AC1032", "primitives-ac1032.dwg")] + public void PublicDrawing_DecodesAuthoredPrimitives(string signature, string fileName) + { + var doc = DwgDocument.Open(TestFiles.PublicDrawing(fileName), new DwgReaderOptions { VerifyChecksums = true }); + + Assert.Equal(signature, doc.Version.Magic); + Assert.Equal(4, doc.Entities.Count(entity => entity.Geometry is not null)); + AssertGeometry(doc, DwgEntityKind.Line, [1, 2, 3, 4, 6, 8]); + AssertGeometry(doc, DwgEntityKind.Arc, [-3, 7, 2, 5, Math.PI / 6, Math.PI / 2]); + AssertGeometry(doc, DwgEntityKind.Circle, [7, -2, 1, 4]); + AssertGeometry(doc, DwgEntityKind.Point, [-5, -6, 9]); + } + + private static void AssertGeometry(DwgDocument document, DwgEntityKind kind, double[] expected) + { + var entity = Assert.Single(document.Entities, entity => entity.Kind == kind); + var geometry = Assert.IsType(entity.Geometry); + Assert.Equal(expected.Length, geometry.Length); + for (int i = 0; i < expected.Length; i++) + { + Assert.Equal(expected[i], geometry[i], precision: 10); + } + } + [SkippableFact] public void Open_ParsesSectionMap() => CheckAll(path => { diff --git a/tests/DwgIO.Tests/DwgIO.Tests.csproj b/tests/DwgIO.Tests/DwgIO.Tests.csproj index 7c0fbb6..2335e61 100644 --- a/tests/DwgIO.Tests/DwgIO.Tests.csproj +++ b/tests/DwgIO.Tests/DwgIO.Tests.csproj @@ -17,6 +17,12 @@ + + + + diff --git a/tests/DwgIO.Tests/TestFiles.cs b/tests/DwgIO.Tests/TestFiles.cs index 62399a9..02099a9 100644 --- a/tests/DwgIO.Tests/TestFiles.cs +++ b/tests/DwgIO.Tests/TestFiles.cs @@ -1,9 +1,7 @@ namespace DwgIO.Tests; -/// Where the tests find DWG fixtures: the folder named by the environment variable DWGIO_TEST_FILES, the committed -/// redistributable drawings of test-files/public, and a test_files folder in the repository root (or in an ancestor of the test -/// binary). Files may lie directly in a folder or in one level of subfolders. A test that needs a file which is not -/// there is reported as skipped with the reason, never passed. +/// Resolves required public DWG fixtures from the test output and finds optional inputs from +/// DWGIO_TEST_FILES and fixture folders in ancestors of the test binary. internal static class TestFiles { public const string EnvironmentVariable = "DWGIO_TEST_FILES"; @@ -24,6 +22,15 @@ public static IEnumerable Roots() } } + /// Resolve the build's fixture copy, never a private file with the same name. + public static string PublicDrawing(string fileName) + { + // Keep these copies outside the fixture roots searched by DwgFiles. + string path = Path.Combine(AppContext.BaseDirectory, "PublicFixtures", fileName); + if (File.Exists(path)) return path; + throw new FileNotFoundException($"Required public DWG fixture '{fileName}' is missing from the test output.", path); + } + /// Every *.dwg in the fixture folders (root plus one level of subfolders, so a mistyped variable cannot sweep a /// whole tree), sorted ordinally, or a when there is none. public static List DwgFiles()