• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DomCR / ACadSharp / 22172461551

19 Feb 2026 07:24AM UTC coverage: 77.585% (-0.008%) from 77.593%
22172461551

Pull #981

github

web-flow
Merge 42f92cfbf into ae77202b7
Pull Request #981: Refactor DWG AC15 file header writing and section logic

8147 of 11366 branches covered (71.68%)

Branch coverage included in aggregate %.

403 of 420 new or added lines in 6 files covered. (95.95%)

14 existing lines in 5 files now uncovered.

29494 of 37150 relevant lines covered (79.39%)

151481.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.14
/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgFileHeaderWriterBase.cs
1
using CSUtilities.Converters;
2
using System;
3
using System.IO;
4
using System.Text;
5

6
namespace ACadSharp.IO.DWG.DwgStreamWriters;
7

8
internal abstract class DwgFileHeaderWriterBase<T> : IDwgFileHeaderWriter
9
        where T : DwgFileHeader, new()
10
{
11
        public T FileHeader { get; } = new T();
11,420✔
12

13
        public abstract int FileHeaderSize { get; }
14

15
        public abstract int HandleSectionOffset { get; }
16

17
        protected CadDocument _document;
18

19
        protected Encoding _encoding;
20

21
        protected Stream _stream;
22

23
        protected ACadVersion _version;
24

25
        public DwgFileHeaderWriterBase(Stream stream, Encoding encoding, CadDocument model)
332✔
26
        {
332✔
27
                if (!stream.CanSeek || !stream.CanWrite)
332!
UNCOV
28
                {
×
NEW
29
                        throw new ArgumentException();
×
30
                }
31

32
                this._document = model;
332✔
33
                this._stream = stream;
332✔
34
                this._version = model.Header.Version;
332✔
35
                this._encoding = encoding;
332✔
36
        }
332✔
37

38
        public abstract void AddSection(string name, MemoryStream stream, bool isCompressed, int decompsize = 0x7400);
39

40
        public abstract void WriteFile();
41

42
        protected void applyMagicSequence(MemoryStream stream)
43
        {
264✔
44
                byte[] buffer = stream.GetBuffer();
264✔
45
                for (int i = 0; i < (int)stream.Length; i++)
57,552✔
46
                {
28,512✔
47
                        buffer[i] ^= DwgCheckSumCalculator.MagicSequence[i];
28,512✔
48
                }
28,512✔
49
        }
264✔
50

51
        protected void applyMask(byte[] buffer, int offset, int length)
52
        {
3,432✔
53
                byte[] bytes = LittleEndianConverter.Instance.GetBytes(0x4164536B ^ (int)this._stream.Position);
3,432✔
54
                int diff = offset + length;
3,432✔
55
                while (offset < diff)
30,888✔
56
                {
27,456✔
57
                        for (int i = 0; i < 4; i++)
274,560✔
58
                        {
109,824✔
59
                                buffer[offset + i] ^= bytes[i];
109,824✔
60
                        }
109,824✔
61

62
                        offset += 4;
27,456✔
63
                }
27,456✔
64
        }
3,432✔
65

66
        protected bool checkEmptyBytes(byte[] buffer, ulong offset, ulong spearBytes)
67
        {
3,168✔
68
                bool result = true;
3,168✔
69
                ulong num = offset + spearBytes;
3,168✔
70

71
                for (ulong i = offset; i < num; i++)
20,692✔
72
                {
9,818✔
73
                        if (buffer[i] != 0)
9,818✔
74
                        {
2,640✔
75
                                result = false;
2,640✔
76
                                break;
2,640✔
77
                        }
78
                }
7,178✔
79

80
                return result;
3,168✔
81
        }
3,168✔
82

83
        protected ushort getFileCodePage()
84
        {
332✔
85
                ushort codePage = (ushort)CadUtils.GetCodeIndex(CadUtils.GetCodePage(_document.Header.CodePage));
332✔
86
                if (codePage < 1)
332!
UNCOV
87
                {
×
NEW
88
                        return 30;
×
89
                }
90
                else
91
                {
332✔
92
                        return codePage;
332✔
93
                }
94
        }
332✔
95

96
        protected void writeMagicNumber()
97
        {
3,960✔
98
                for (int i = 0; i < (int)(this._stream.Position % 0x20); i++)
7,920!
UNCOV
99
                {
×
NEW
100
                        this._stream.WriteByte(DwgCheckSumCalculator.MagicSequence[i]);
×
UNCOV
101
                }
×
102
        }
3,960✔
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc