Esempio n. 1
0
        public void FakeLogin60Test()
        {
            ConnectionMock mc       = new ConnectionMock();
            sHGG           mockGG   = new sHGG(mc);
            string         pass     = "******";
            uint           fakeSeed = 674456;

            mockGG.GGNumber   = "100001";
            mockGG.GGPassword = pass;
            mockGG.OutLogin60(fakeSeed);
            Assert.AreEqual(mc.data.Length, 39);
            Assert.AreEqual(mc.ReadUInt(), 0x15); // type
            Assert.AreEqual(mc.ReadUInt(), 31);   // size
            Assert.AreEqual(mc.ReadUInt(), 100001);
            Assert.AreEqual(mc.ReadUInt(), sHGG.Hash(pass, fakeSeed));
            Assert.AreEqual(mc.ReadUInt(), 0x14);
            mc.ReadUInt();                       // gg ver
            Assert.AreEqual(mc.ReadByte(), 0x0); // unknown byte
            mc.ReadUInt();                       // local ip
            mc.ReadShort();                      // local port
            mc.ReadUInt();                       // external ip
            mc.ReadShort();                      // external port
            byte imageSize = mc.ReadByte();

            Assert.AreEqual(mc.ReadByte(), 0xbe); // unknown
            Assert.IsTrue(mc.IsEnd);
        }
Esempio n. 2
0
        public void RichMsgTest()
        {
            ConnectionMock mc     = new ConnectionMock();
            sHGG           ggmock = new sHGG(mc);
            int            rec    = 234567;
            string         msg    = "Rich message output test";
            SortedDictionary <short, string> format = new SortedDictionary <short, string>()
            {
                { 5, "<u><green>" },
                { 10, "<b><gray>" },
                { 15, "<n>" }
            };

            ggmock.GGSendMessage(rec, msg, format);
            Assert.AreEqual(mc.data.Length, 38 + msg.Length + 1);
            // msg
            Assert.AreEqual(mc.ReadUInt(), 0xb);                 // type
            Assert.AreEqual(mc.ReadUInt(), 30 + msg.Length + 1); // size
            Assert.AreEqual(mc.ReadUInt(), rec);                 // rec
            mc.ReadUInt();                                       // seq
            mc.ReadUInt();                                       // msg class
            for (int i = 0; i < msg.Length; i++)
            {
                Assert.AreEqual(mc.ReadByte(), Convert.ToByte(msg[i]));
            }
            Assert.AreEqual(mc.ReadByte(), 0); // null char
            Assert.IsFalse(mc.IsEnd);
            // rich info
            Assert.AreEqual(mc.ReadByte(), 2);   // rich info flag
            Assert.AreEqual(mc.ReadShort(), 15); // rich length

            // rich format list
            // { 5, "<u><green>" }
            Assert.AreEqual(mc.ReadShort(), 5);        // pos
            Assert.AreEqual(mc.ReadByte(), 0x4 | 0x8); // font
            Assert.AreEqual(mc.ReadByte(), 91);        // color: R
            Assert.AreEqual(mc.ReadByte(), 164);       // color: G
            Assert.AreEqual(mc.ReadByte(), 42);        // color: B
            // { 10, "<b><gray>" }
            Assert.AreEqual(mc.ReadShort(), 10);       // pos
            Assert.AreEqual(mc.ReadByte(), 0x1 | 0x8); // font
            Assert.AreEqual(mc.ReadByte(), 128);       // color: R
            Assert.AreEqual(mc.ReadByte(), 128);       // color: G
            Assert.AreEqual(mc.ReadByte(), 128);       // color: B
            // { 15, "<n>" }
            Assert.AreEqual(mc.ReadShort(), 15);       // pos
            Assert.AreEqual(mc.ReadByte(), 0x0);       // font

            Assert.IsTrue(mc.IsEnd);
        }
Esempio n. 3
0
        public void ImgRequestTest()
        {
            ConnectionMock mc     = new ConnectionMock();
            sHGG           ggmock = new sHGG(mc);
            string         msg    = "Simple message with image inside";
            int            rec    = 956267;
            int            imgPos = 4;
            MemoryStream   stream = new MemoryStream();

            using (Bitmap img = CreateRandomImage(600, 200)) {
                img.Save(stream, ImageFormat.Jpeg);
            }

            ggmock.GGSendImage(rec, msg, imgPos, stream);

            // msg
            Assert.AreEqual(mc.data.Length, 36 + msg.Length + 1);
            Assert.AreEqual(mc.ReadUInt(), 0xb);                 // type
            Assert.AreEqual(mc.ReadUInt(), 28 + msg.Length + 1); // size
            Assert.AreEqual(mc.ReadUInt(), rec);                 // rec
            mc.ReadUInt();                                       // seq
            mc.ReadUInt();                                       // msg class
            for (int i = 0; i < msg.Length; i++)
            {
                Assert.AreEqual(mc.ReadByte(), Convert.ToByte(msg[i]));
            }
            Assert.AreEqual(mc.ReadByte(), 0); // null char
            Assert.IsFalse(mc.IsEnd);
            // rich info
            Assert.AreEqual(mc.ReadByte(), 2);          // rich info flag
            Assert.AreEqual(mc.ReadShort(), 13);        // rich length
            // rich format list
            Assert.AreEqual(mc.ReadShort(), imgPos);    // pos
            Assert.AreEqual(mc.ReadByte(), 0x0 | 0x80); // font (image)
            Assert.IsFalse(mc.IsEnd);
            // image
            Assert.AreEqual(mc.ReadShort(), 0x109); // unknown flag
            Assert.AreEqual(mc.ReadUInt(), stream.Length);
            Assert.AreEqual(mc.ReadUInt(), new CRC32().GetCrc32(stream));
            Assert.IsTrue(mc.IsEnd);
        }
Esempio n. 4
0
        public void SimpleReadMockTest()
        {
            ConnectionMock mock = new ConnectionMock();
            simpleStruct   str  = new simpleStruct()
            {
                Number      = 9876,
                SampleFlag  = 0x5,
                SampleFlag2 = 0xf,
                SampleInt16 = (UInt16)2001,
                ShortNumber = 1998,
                uNumber     = 1000234
            };

            mock.Write(sHGG.RawSerialize(str));
            Assert.AreEqual(mock.data.Length, 14);
            Assert.AreEqual(mock.ReadUInt(), 1000234);
            Assert.AreEqual(mock.ReadShort(), 1998);
            Assert.AreEqual(mock.ReadByte(), 0x5);
            Assert.AreEqual(mock.ReadShort(), 2001); //todo
            Assert.AreEqual(mock.ReadByte(), 0xf);
            Assert.AreEqual(mock.ReadInt(), 9876);
        }