Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo n.º 3
0
        public void FakePingTest()
        {
            ConnectionMock mc     = new ConnectionMock();
            sHGG           mockGG = new sHGG(mc);

            mockGG.OutPing(new object(), EventArgs.Empty);
            Assert.AreEqual(mc.data.Length, 8);
            Assert.AreEqual(mc.ReadUInt(), 0x8);
            Assert.AreEqual(mc.ReadUInt(), 0);
            Assert.IsTrue(mc.IsEnd);
        }
Ejemplo n.º 4
0
        public void MockCtorTest()
        {
            sHGG ggNormal = new sHGG();

            Assert.IsFalse(ggNormal.mock);
            Assert.IsNull(ggNormal.mockObj);
            ConnectionMock mock   = new ConnectionMock();
            sHGG           ggMock = new sHGG(mock);

            Assert.IsTrue(ggMock.mock);
            Assert.IsNotNull(ggMock.mockObj);
            Assert.AreEqual(ggMock.mockObj, mock);
            Assert.AreSame(ggMock.mockObj, mock);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public void ImgReplySmallTest()
        {
            ConnectionMock mc     = new ConnectionMock();
            sHGG           ggmock = new sHGG(mc);
            uint           rec    = 956267;
            MemoryStream   stream = new MemoryStream();

            using (Bitmap img = CreateRandomImage(100, 200)) {
                img.Save(stream, ImageFormat.Jpeg);
            }
            // hack
            ggmock.imageBuff.pushSave(956267, new sHGG.imageBuffEl()
            {
                bin  = sHGG.Stream2Array(stream),
                path = "file.jpg"
            });

            ggmock.ImageReply((int)stream.Length, new CRC32().GetCrc32(stream), rec);

            // todo
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
 public void StartupTest()
 {
     ggMock            = new sHGG(new ConnectionMock());
     ggMock.GGNumber   = "123456";
     ggMock.GGPassword = "******";
 }