From 854f4945ed9f5c63bb70a41847c27f07c8c15500 Mon Sep 17 00:00:00 2001
From: mahach666 <79989386+mahach666@users.noreply.github.com>
Date: Sun, 29 Nov 2026 00:22:58 +0300
Subject: [PATCH 1/2] Vector tests for the drawing table and the drawing file
container
The format facts of the drawing table (key 27, rows of 256 bytes) and of the
.dg container (type 0x20, the id list of 47 records and the content start at
byte 256) are now backed by the private vectors:
- db-tables-office-sec027-drawings.bin: the whole drawing table of the office
sample, 24 rows, with the expected id, object type, mark, save times, file
name and type name of every row and the row stamps a and b.
- db-container-office-dg-head272.bin: the first 272 unpacked bytes of a
drawing file: the 12-byte header, the record list and the first 16 bytes of
the content area.
VectorTests.Drawings decodes both and checks the manifest values; the tests
skip without the private vector folder.
---
tests/TdbIO.Tests/VectorTests.Drawings.cs | 83 +++++++++++++++++++++++
1 file changed, 83 insertions(+)
create mode 100644 tests/TdbIO.Tests/VectorTests.Drawings.cs
diff --git a/tests/TdbIO.Tests/VectorTests.Drawings.cs b/tests/TdbIO.Tests/VectorTests.Drawings.cs
new file mode 100644
index 0000000..7affa54
--- /dev/null
+++ b/tests/TdbIO.Tests/VectorTests.Drawings.cs
@@ -0,0 +1,83 @@
+using System.Buffers.Binary;
+using System.Text;
+using System.Text.Json;
+using TdbIO.Internal;
+using Xunit;
+
+namespace TdbIO.Tests;
+
+/// The drawing table and the drawing-file container against the private vectors. Entries are selected by the
+/// keys of their expected values, never by name.
+public partial class VectorTests
+{
+ [SkippableFact]
+ public void DrawingTableVectorDecodesAsExpected()
+ {
+ foreach (var entry in TableJson.Selected(TestVectors.WithKeys("drawings"), "drawing tables"))
+ {
+ string name = TestVectors.Name(entry);
+ byte[] data = TestVectors.Read(entry);
+ var expected = TableJson.Expected(entry);
+ var sections = SectionWalker.Walk(data, 0, expected.GetProperty("ordinal").GetInt32(), SectionMode.Db1, null);
+ var section = Assert.Single(sections);
+ Assert.Equal(expected.GetProperty("K").GetInt32(), section.Key);
+ Assert.Equal(expected.GetProperty("row_size").GetInt32(), section.RowSize);
+ Assert.Equal(expected.GetProperty("rows").GetInt32(), section.Rows.Count);
+ var drawings = section.AsDrawings();
+ var rows = expected.GetProperty("drawings").EnumerateArray().ToList();
+ Assert.Equal(rows.Count, drawings.Count);
+ for (int i = 0; i < rows.Count; i++)
+ {
+ var e = rows[i];
+ string at = $"{name}: drawing {i}";
+ Assert.True(e.GetProperty("id").GetInt32() == drawings[i].Id, $"{at}: id");
+ Assert.True(e.GetProperty("obj_type").GetInt32() == drawings[i].ObjType, $"{at}: obj_type");
+ Assert.Equal(e.GetProperty("mark").GetString(), drawings[i].Mark);
+ Assert.True((uint)e.GetProperty("created").GetDouble() == drawings[i].CreatedAt, $"{at}: created");
+ Assert.True((uint)e.GetProperty("modified").GetDouble() == drawings[i].ModifiedAt, $"{at}: modified");
+ Assert.Equal(e.GetProperty("file_name").GetString(), drawings[i].FileName);
+ Assert.Equal(e.GetProperty("type_name").GetString(), drawings[i].TypeName);
+ Assert.Equal((e.GetProperty("a").GetInt32(), e.GetProperty("b").GetInt32()),
+ (section.Rows[i].A, section.Rows[i].B));
+ }
+ Assert.Equal(expected.GetProperty("descriptors").EnumerateArray().Select(x => (uint)x.GetInt32()).ToArray(),
+ section.Descriptors.ToArray());
+ TestVectors.CheckKeys(entry, ["ordinal", "K", "row_size", "descriptors", "rows", "drawings"], []);
+ }
+ }
+
+ [SkippableFact]
+ public void DgContainerVectorMatchesTheHeader()
+ {
+ foreach (var entry in TableJson.Selected(TestVectors.WithKeys("list_count", "list"), ".dg containers"))
+ {
+ string name = TestVectors.Name(entry);
+ byte[] data = TestVectors.Read(entry);
+ var expected = TableJson.Expected(entry);
+ Assert.True(data[6] == expected.GetProperty("type_byte").GetByte(), $"{name}: type byte");
+ Assert.Equal(expected.GetProperty("version").GetString(), Encoding.ASCII.GetString(data[8..12]));
+ int count = (int)BinaryPrimitives.ReadUInt32LittleEndian(data.AsSpan(12));
+ Assert.Equal(expected.GetProperty("list_count").GetInt32(), count);
+
+ var ids = new List();
+ var flags = new List();
+ for (int q = 16; q + 5 <= 16 + 5 * (count + 1); q += 5)
+ {
+ ids.Add(BinaryPrimitives.ReadUInt32LittleEndian(data.AsSpan(q)));
+ flags.Add(data[q + 4]);
+ }
+ Assert.Equal(count + 1, ids.Count);
+ Assert.True(flags[^1] == 0 && flags.Take(flags.Count - 1).All(f => f == 4), $"{name}: flags");
+ Assert.Equal(expected.GetProperty("list").EnumerateArray().Select(x => x.GetUInt32()), ids);
+ int contentStart = 16 + 5 * (count + 1);
+ Assert.Equal(expected.GetProperty("content_start").GetInt32(), contentStart);
+ // The vector pins the first 16 bytes of the content area; the rest of the drawing is not part of it.
+ Assert.Equal(contentStart + 16, data.Length);
+ if (expected.TryGetProperty("first_content_hex", out var content))
+ Assert.Equal(content.GetString(), Convert.ToHexString(data[256..]).ToLowerInvariant());
+ TestVectors.CheckKeys(entry,
+ ["type_byte", "version", "list_count", "list", "flags", "content_start", "first_content_hex", "content_word_at_11"],
+ ["content_word_at_11"]);
+ }
+ }
+}
From ce15732d249c8fde3be59d87ef6e8f1ab1126c99 Mon Sep 17 00:00:00 2001
From: mahach666 <79989386+mahach666@users.noreply.github.com>
Date: Sun, 29 Nov 2026 05:10:39 +0300
Subject: [PATCH 2/2] Fix the checks of the drawing vector tests
Take the content of the drawing file from the end of the id list, compare the
times without cutting off a fraction, and check through the library that the
file is recognised as a drawing and not read as a model database.
List the value of the flags key as ignored, because the test checks the flag
bytes against its own pattern. Remove a check that could not fail.
---
tests/TdbIO.Tests/VectorTests.Drawings.cs | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/tests/TdbIO.Tests/VectorTests.Drawings.cs b/tests/TdbIO.Tests/VectorTests.Drawings.cs
index 7affa54..bd6c202 100644
--- a/tests/TdbIO.Tests/VectorTests.Drawings.cs
+++ b/tests/TdbIO.Tests/VectorTests.Drawings.cs
@@ -33,8 +33,8 @@ public void DrawingTableVectorDecodesAsExpected()
Assert.True(e.GetProperty("id").GetInt32() == drawings[i].Id, $"{at}: id");
Assert.True(e.GetProperty("obj_type").GetInt32() == drawings[i].ObjType, $"{at}: obj_type");
Assert.Equal(e.GetProperty("mark").GetString(), drawings[i].Mark);
- Assert.True((uint)e.GetProperty("created").GetDouble() == drawings[i].CreatedAt, $"{at}: created");
- Assert.True((uint)e.GetProperty("modified").GetDouble() == drawings[i].ModifiedAt, $"{at}: modified");
+ Assert.True(e.GetProperty("created").GetDouble() == drawings[i].CreatedAt, $"{at}: created");
+ Assert.True(e.GetProperty("modified").GetDouble() == drawings[i].ModifiedAt, $"{at}: modified");
Assert.Equal(e.GetProperty("file_name").GetString(), drawings[i].FileName);
Assert.Equal(e.GetProperty("type_name").GetString(), drawings[i].TypeName);
Assert.Equal((e.GetProperty("a").GetInt32(), e.GetProperty("b").GetInt32()),
@@ -55,6 +55,11 @@ public void DgContainerVectorMatchesTheHeader()
byte[] data = TestVectors.Read(entry);
var expected = TableJson.Expected(entry);
Assert.True(data[6] == expected.GetProperty("type_byte").GetByte(), $"{name}: type byte");
+ // The library recognises a drawing and does not read it. It does not read the id list either, so the checks of
+ // the list below compare the vector with its manifest only.
+ Assert.Equal(XsteelHeader.DrawingType, data[6]);
+ Assert.Equal(TdbFileKind.Drawing, TdbFile.DetectKind(new MemoryStream(Synthetic.Gzip(data))));
+ Assert.Throws(() => Db1Document.Create(data));
Assert.Equal(expected.GetProperty("version").GetString(), Encoding.ASCII.GetString(data[8..12]));
int count = (int)BinaryPrimitives.ReadUInt32LittleEndian(data.AsSpan(12));
Assert.Equal(expected.GetProperty("list_count").GetInt32(), count);
@@ -66,7 +71,6 @@ public void DgContainerVectorMatchesTheHeader()
ids.Add(BinaryPrimitives.ReadUInt32LittleEndian(data.AsSpan(q)));
flags.Add(data[q + 4]);
}
- Assert.Equal(count + 1, ids.Count);
Assert.True(flags[^1] == 0 && flags.Take(flags.Count - 1).All(f => f == 4), $"{name}: flags");
Assert.Equal(expected.GetProperty("list").EnumerateArray().Select(x => x.GetUInt32()), ids);
int contentStart = 16 + 5 * (count + 1);
@@ -74,10 +78,11 @@ public void DgContainerVectorMatchesTheHeader()
// The vector pins the first 16 bytes of the content area; the rest of the drawing is not part of it.
Assert.Equal(contentStart + 16, data.Length);
if (expected.TryGetProperty("first_content_hex", out var content))
- Assert.Equal(content.GetString(), Convert.ToHexString(data[256..]).ToLowerInvariant());
+ Assert.Equal(content.GetString(), Convert.ToHexString(data[contentStart..]).ToLowerInvariant());
+ // The value of "flags" is not read: the flag bytes are checked against the pattern above.
TestVectors.CheckKeys(entry,
- ["type_byte", "version", "list_count", "list", "flags", "content_start", "first_content_hex", "content_word_at_11"],
- ["content_word_at_11"]);
+ ["type_byte", "version", "list_count", "list", "content_start", "first_content_hex"],
+ ["flags", "content_word_at_11"]);
}
}
}