Exemplo n.º 1
0
        public void Read_ValidHeaderAndProcedureWithReference_ProcedureRead()
        {
            byte[] bytes =
            {
                0x61, 0x74, 0x6F, 0x6D, // Magic number.
                0x01, 0x00,             // Version 1.
                0x01,                   // The origin is set.
                0x20, 0x00, 0x00, 0x00, // The origin is set to 0x20.
                0x00, 0x00, 0x00, 0x00,

                // Base part of the atom.
                0x00,                         // Procedure type.
                0x01,                         // The procedure is defined.
                0x01,                         // The procedure is global.
                0x50, 0x72, 0x6F, 0x63, 0x00, // The procedure is called 'Proc'.

                // Procedure part of the atom.
                0x01,                   // This is the main procedure.
                0x04, 0x00, 0x00, 0x00, // The size of the code is 4 bytes.
                0x00, 0x00, 0x00, 0x00, // The procedure code.
                0x01, 0x00,             // Number of references.

                // Reference.
                0x01, 0x00, 0x00, 0x00, // It is atom number 1 that is being referenced (index based).
                0x01,                   // The address is in little endian.
                0x04,                   // The size of the address is 4 bytes.
                0x00, 0x00, 0x00, 0x00, // The address to relocate.

                // Null terminated string.
                0x01,       // Null terminated string type.
                0x01,       // The string is defined.
                0x00,       // The string is not global.
                0x53, 0x00, // The string is called 'S'.

                // String part
                0x54, 0x78, 0x74, 0x00          // The string is 'Txt'.
            };

            using (var stream = new MemoryStream(bytes))
            {
                var reader = new AtomReader();
                var file   = reader.Read(stream);

                Assert.True(file.IsOriginSet);
                Assert.AreEqual(0x20, file.Origin);

                var procedure = (Procedure)file.Atoms[0];
                var s         = (NullTerminatedString)file.Atoms[1];

                Assert.True(procedure.IsDefined);
                Assert.True(procedure.IsGlobal);
                Assert.AreEqual("Proc", procedure.Name);

                Assert.True(procedure.IsMain);
                CollectionAssert.AreEqual(new byte[] { 0x00, 0x00, 0x00, 0x00 }, procedure.Code);

                Assert.AreEqual(1, procedure.References.Count);
                Assert.AreEqual(0, procedure.References[0].Address);
                Assert.AreSame(s, procedure.References[0].Atom);

                Assert.True(s.IsDefined);
                Assert.False(s.IsGlobal);
                Assert.AreEqual("S", s.Name);
                Assert.AreEqual("Txt", s.Content);
            }
        }