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 ConfMsgTest()
        {
            ConnectionMock mc     = new ConnectionMock();
            sHGG           ggmock = new sHGG(mc);
            string         msg    = "Conference message output test";

            int[] recs = new int[] { 12345, 67890, 98765, 4321, 100001 };
            ggmock.GGSendMessage(recs, msg);
            Assert.AreEqual(mc.data.Length, (20 + 1 + msg.Length + 5 + (4 * recs.Length)) * recs.Length);
            for (int i = 0; i < recs.Length; i++)
            {
                Assert.AreEqual(mc.ReadUInt(), 0xb);                                         // type
                Assert.AreEqual(mc.ReadUInt(), 12 + 1 + msg.Length + 5 + (4 * recs.Length)); // size
                Assert.AreEqual(mc.ReadUInt(), recs[i]);                                     // rec
                mc.ReadUInt();                                                               // seq
                mc.ReadUInt();                                                               // msg class
                for (int j = 0; j < msg.Length; j++)
                {
                    Assert.AreEqual(mc.ReadByte(), Convert.ToByte(msg[j]));
                }
                Assert.AreEqual(mc.ReadByte(), 0); // null char
                Assert.AreEqual(mc.ReadByte(), 1); // conf flag
                Assert.AreEqual(mc.ReadUInt(), recs.Length);
                for (int m = 0; m < recs.Length; m++)
                {
                    Assert.AreEqual(mc.ReadUInt(), recs[m]);
                }
            }
            Assert.IsTrue(mc.IsEnd);
        }
Esempio n. 3
0
        public void ThrowOverflowTest()
        {
            basic bstr = new basic()
            {
                one = 0xe
            };
            ConnectionMock mock = new ConnectionMock();

            mock.Write(sHGG.RawSerialize(bstr));
            byte oneRe = mock.ReadByte();

            Assert.AreEqual(oneRe, bstr.one);
            mock.ReadByte(); // throw
        }
Esempio n. 4
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. 5
0
        public void SimpleMsgTest()
        {
            ConnectionMock mc     = new ConnectionMock();
            sHGG           ggmock = new sHGG(mc);
            string         msg    = "Simple message output test";
            int            rec    = 234567;

            ggmock.GGSendMessage(rec, msg);
            Assert.AreEqual(mc.data.Length, 20 + 1 + msg.Length);
            Assert.AreEqual(mc.ReadUInt(), 0xb);                 // type
            Assert.AreEqual(mc.ReadUInt(), 12 + 1 + msg.Length); // 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.IsTrue(mc.IsEnd);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public void FakeStatusNDescTest()
        {
            ConnectionMock mc     = new ConnectionMock();
            sHGG           mockGG = new sHGG(mc);

            // available
            mockGG.GGStatus = GGStatusType.Available;
            Assert.AreEqual(mc.data.Length, 12);
            Assert.AreEqual(mc.ReadUInt(), 0x2); // type
            Assert.AreEqual(mc.ReadUInt(), 4);   // size
            Assert.AreEqual(mc.ReadUInt(), 0x2); // status
            mc.ClearData();
            // busy
            mockGG.GGStatus = GGStatusType.Busy;
            Assert.AreEqual(mc.data.Length, 12);
            Assert.AreEqual(mc.ReadUInt(), 0x2); // type
            Assert.AreEqual(mc.ReadUInt(), 4);   // size
            Assert.AreEqual(mc.ReadUInt(), 0x3); // status
            mc.ClearData();
            // + desc
            string desc = "abcdefghijk lmno";

            mockGG.GGDescription = desc;
            Assert.AreEqual(mc.ReadUInt(), 0x2);                 // type
            Assert.AreEqual(mc.ReadUInt(), 4 + 1 + desc.Length); // size
            Assert.AreEqual(mc.ReadUInt(), 0x5);                 // status
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('a'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('b'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('c'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('d'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('e'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('f'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('g'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('h'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('i'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('j'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('k'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte(' '));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('l'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('m'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('n'));
            Assert.AreEqual(mc.ReadByte(), Convert.ToByte('o'));
            Assert.AreEqual(mc.ReadByte(), 0);
            Assert.IsTrue(mc.IsEnd);
        }
Esempio n. 8
0
        public void UnmanagedReadMockTest()
        {
            ConnectionMock  mock = new ConnectionMock();
            UnmanagedStruct ustr = new UnmanagedStruct()
            {
                ByteArr = new byte[] { 3, 5, 7 },
                Number  = UInt32.MaxValue,
                Str     = "Unmanaged!"
            };

            mock.Write(sHGG.RawSerialize(ustr));
            Assert.AreEqual(mock.data.Length, 18);
            Assert.AreEqual(mock.ReadUInt(), UInt32.MaxValue);
            // byte[]
            Assert.AreEqual(mock.ReadByte(), 3);
            Assert.AreEqual(mock.ReadByte(), 5);
            Assert.AreEqual(mock.ReadByte(), 7);
            // string + 0 char
            Assert.AreEqual(mock.ReadByte(), Convert.ToByte('U'));
            Assert.AreEqual(mock.ReadByte(), Convert.ToByte('n'));
            Assert.AreEqual(mock.ReadByte(), Convert.ToByte('m'));
            Assert.AreEqual(mock.ReadByte(), Convert.ToByte('a'));
            Assert.AreEqual(mock.ReadByte(), Convert.ToByte('n'));
            Assert.AreEqual(mock.ReadByte(), Convert.ToByte('a'));
            Assert.AreEqual(mock.ReadByte(), Convert.ToByte('g'));
            Assert.AreEqual(mock.ReadByte(), Convert.ToByte('e'));
            Assert.AreEqual(mock.ReadByte(), Convert.ToByte('d'));
            Assert.AreEqual(mock.ReadByte(), Convert.ToByte('!'));
            Assert.AreEqual(mock.ReadByte(), 0);
        }
Esempio n. 9
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);
        }