예제 #1
0
        public void When_reading_and_writing_byte_arrays()
        {
            const ushort byteArrayAddress = Length / 4;
            var          writtenBytes     = Rng.Bytes(Length / 2);

            Subject.WriteBytes(byteArrayAddress, writtenBytes);

            Subject.ReadBytes(byteArrayAddress, writtenBytes.Length).ShouldBe(writtenBytes);
        }
예제 #2
0
        public PrefetchQueueTests()
        {
            _bytes = Rng.Bytes(ushort.MaxValue);

            var mmu = The <IMmu>();

            mmu.Setup(x => x.ReadBytes(It.IsAny <ushort>(), It.IsAny <int>()))
            .Returns((ushort address, int length) => _bytes.Skip(address).Take(length).ToArray());
            mmu.Setup(x => x.ReadWord(It.IsAny <ushort>())).Returns((ushort address) => BitConverter.ToUInt16(_bytes, address));
            mmu.Setup(x => x.ReadByte(It.IsAny <ushort>())).Returns((ushort address) => _bytes[address]);
            Subject.ReBuildCache(Address);
        }
예제 #3
0
        public ReadOnlyMemoryBankTests()
        {
            _byteContent = Rng.Bytes(Length);
            _wordContent = new ushort[Length / 2];
            for (var i = 0; i < Length / 2; i++)
            {
                _wordContent[i] = BitConverter.ToUInt16(_byteContent, i * 2);
            }

            var memoryBankConfig = The <IMemoryBankConfig>();

            memoryBankConfig.Setup(x => x.Address).Returns(Address);
            memoryBankConfig.Setup(x => x.Length).Returns(Length);
            memoryBankConfig.Setup(x => x.InitialState).Returns(_byteContent);
        }
예제 #4
0
파일: UUID.cs 프로젝트: JGDIFF/VAPOR-Client
        public static string UUID_Make()
        {
            // 12345678 9012 3456 7890 123456789012
            // Returns a 36-character string in the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
            // where "X" is an "upper-case" hexadecimal digit [0-9A-F].
            // Use the LCase function if you want lower-case letters.

            byte[] abData = null;
            string strHex = null;

            // 1. Generate 16 random bytes = 128 bits
            abData = Rng.Bytes(16);
            // DEBUGGING...
            //'Console.WriteLine("RNG=" & Cnv.ToHex(abData))

            // 2. Adjust certain bits according to RFC 4122 section 4.4.
            // This just means do the following
            // (a) set the high nibble of the 7th byte equal to 4 and
            // (b) set the two most significant bits of the 9th byte to 10'B,
            //     so the high nibble will be one of {8,9,A,B}.
            abData[6] = (byte)(0x40 | ((int)abData[6] & 0xf));
            abData[8] = (byte)(0x80 | ((int)abData[8] & 0x3f));

            // 3. Convert the adjusted bytes to hex values
            strHex = Cnv.ToHex(abData);
            // DEBUGGING...
            //'Console.WriteLine("ADJ=" & Cnv.ToHex(abData))
            //'Console.WriteLine("                ^   ^") ' point to the nibbles we've changed

            // 4. Add four hyphen '-' characters
            //'strHex = Left$(strHex, 8) & "-" & Mid$(strHex, 9, 4) & "-" & Mid$(strHex, 13, 4) _
            //'    & "-" & Mid$(strHex, 17, 4) & "-" & Right$(strHex, 12)
            strHex = strHex.Substring(0, 8) + "-" + strHex.Substring(8, 4) + "-" + strHex.Substring(12, 4) + "-" + strHex.Substring(16, 4) + "-" + strHex.Substring(20, 12);

            // Return the UUID string
            return(strHex);
        }
예제 #5
0
 public void When_seting_initial_state()
 {
     InitialState = Rng.Bytes(Length);
     Subject.ReadBytes(0, Length).ShouldBe(InitialState);
 }