コード例 #1
0
        public void TestIgnoringName()
        {
            // Create two clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();

            // Check for IGNORING statements:

            client1.Connect("localhost", 2000, "asd");
            Thread.Sleep(100);
            Assert.AreEqual("IGNORING asd", client1.msgString);

            client1.Connect("localhost", 2000, "PLAY  ");
            Thread.Sleep(100);
            Assert.AreEqual("IGNORING PLAY  ", client1.msgString);
        }
コード例 #2
0
        public void EventSending()
        {
            mre1 = new ManualResetEvent(false);

            Server server = new Server(2000, new string[] { "200", "dictionary.txt" });

            //Create the two clients
            BoggleClientModel model1 = new BoggleClientModel();

            Assert.IsTrue(model1.Connect("localhost", 2000, "hey"));

            //Test that this client connects with an IP address
            BoggleClientModel model2 = new BoggleClientModel();

            Assert.IsTrue(model2.Connect("127.0.0.1", 2000, "hey"));

            //Register the event
            model1.incomingWordEvent += TestWordEvent;

            //Start message should be sent to the event handler since both clients connected
            mre1.WaitOne(2000);
            Assert.AreEqual("START", word.Substring(0, 5));

            server.CloseServer();
        }
コード例 #3
0
        public void TestIgnoringWord()
        {
            // Create two clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();

            // Connect the clients.
            client1.Connect("localhost", 2000, "PLAY Harry");
            client2.Connect("localhost", 2000, "PLAY Hermione");

            // Check start messages.
            Thread.Sleep(50);
            Assert.AreEqual("START TESRRDELEAOBSINM 5 Hermione", client1.msgString);
            Assert.AreEqual("START TESRRDELEAOBSINM 5 Harry", client2.msgString);

            // Send words, and check IGNORING messages:

            client1.SendGoMessage("read");
            Thread.Sleep(100);
            Assert.AreEqual("IGNORING read", client1.msgString);

            client1.SendGoMessage("WORD ");
            Thread.Sleep(100);
            Assert.AreEqual("IGNORING WORD ", client1.msgString);
        }
コード例 #4
0
ファイル: BoggleClientTest.cs プロジェクト: rensk63/cs-3500
            public void run()
            {
                BoggleServer.BoggleServer server = null;
                BoggleClientModel         client = null;

                try
                {
                    string[] args = { "200", "../../../Resources/dictionary.txt" };
                    server = new BoggleServer.BoggleServer(args);

                    // create player one connection
                    client = new BoggleClientModel();
                    client.Connect("localhost");

                    mre = new ManualResetEvent(false);

                    // have player one join the boggle game
                    client.SendPlayerName("Basil");

                    // waits for one second, expecting the callback to trigger the mre signal
                    Assert.IsTrue(mre.WaitOne(1000));
                }
                finally
                {
                    client.Disconnect();
                }
            }
コード例 #5
0
            public void run()
            {
                try{
                    //setup server
                    server = new BoggleServer(80, "dictionary.txt");

                    //setup clients
                    BoggleClientModel target    = new BoggleClientModel();
                    string            IPAddress = "127.0.0.1";
                    string            name      = "test";

                    BoggleClientModel target2 = new BoggleClientModel();
                    string            name2   = "test2";


                    target.IncomingStartEvent += delegate(string line)
                    {
                        MRE.Set();
                    };

                    //trigger event
                    target.Connect(IPAddress, name);
                    target2.Connect(IPAddress, name2);

                    Assert.AreEqual(true, MRE.WaitOne(timeout), "Timed out waiting 1");
                }
                finally
                { server.close(); }
            }
コード例 #6
0
        public void ValidConnection()
        {
            //Start a server and create a client with a valid address this time
            Server            server = new Server(2000, new string[] { "200", "dictionary.txt" });
            BoggleClientModel model  = new BoggleClientModel();

            Assert.IsTrue(model.Connect("localhost", 2000, "hey"));

            server.CloseServer();
        }
コード例 #7
0
ファイル: BoggleClientTest.cs プロジェクト: rensk63/cs-3500
        public void BoggleClientTest1()
        {
            ManualResetEvent mre1 = new ManualResetEvent(false);

            string[] args = { "30", "..\\..\\..\\Resources\\dictionary.txt" };
            new BoggleServer.BoggleServer(args);
            BoggleClientModel player1 = new BoggleClientModel();

            player1.Connect("localhost");
            player1.Disconnect();
            mre1.WaitOne();
        }
コード例 #8
0
ファイル: BoggleClientTest.cs プロジェクト: rensk63/cs-3500
        public void BoggleClientTest10()
        {
            string[] args = { "30", "..\\..\\..\\Resources\\dictionary.txt" };
            new BoggleServer.BoggleServer(args);
            BoggleClientModel player1 = new BoggleClientModel();
            BoggleClientModel player2 = new BoggleClientModel();

            player1.Connect("localhost");
            player2.Connect("localhost");
            player1.SendPlayerName("Basil");
            player2.SendPlayerName("Lance");

            player1.ScoreLineEvent += testScore;
        }
コード例 #9
0
ファイル: BoggleClientTest1.cs プロジェクト: jimibue/cs3505
        public void TestTerminated()
        {
            // Create two clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();

            // Connect the clients.
            client1.Connect("localhost", 2000, "Harry");
            client2.Connect("localhost", 2000, "Hermione");
            Thread.Sleep(100);

            client1.disconnect();
            Thread.Sleep(100);

            Assert.AreEqual("TERMINATED", client2.msgString);
        }
コード例 #10
0
        public void TestSimpleGame()
        {
            // Create two clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();

            // Connect the clients.
            client1.Connect("localhost", 2000, "PLAY Harry");
            client2.Connect("localhost", 2000, "PLAY Hermione");

            // Check start messages.
            Thread.Sleep(100);
            Assert.AreEqual("START TESRRDELEAOBSINM 5 Hermione", client1.msgString);
            Assert.AreEqual("START TESRRDELEAOBSINM 5 Harry", client2.msgString);

            // Send words, and check the score messages:

            client1.SendGoMessage("WORD read");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 1 0", client1.msgString);
            Assert.AreEqual("SCORE 0 1", client2.msgString);

            client2.SendGoMessage("WORD reads");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 1 2", client1.msgString);
            Assert.AreEqual("SCORE 2 1", client2.msgString);

            // Send a word already played by other player
            client2.SendGoMessage("WORD read");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 0 2", client1.msgString);
            Assert.AreEqual("SCORE 2 0", client2.msgString);

            // Send an invalid word
            client2.SendGoMessage("WORD asdfjkl");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 0 1", client1.msgString);
            Assert.AreEqual("SCORE 1 0", client2.msgString);

            // Make time run out, then check game summary messages.
            Thread.Sleep(6000);
            Assert.AreEqual("STOP 0 1 READS 1 READ 0 1 ASDFJKL", client1.msgString);
            Assert.AreEqual("STOP 1 READS 0 1 READ 1 ASDFJKL 0", client2.msgString);
        }
コード例 #11
0
        public void TestIllegalWords()
        {
            // Create two clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();

            // Connect the clients.
            client1.Connect("localhost", 2000, "PLAY Harry");
            client2.Connect("localhost", 2000, "PLAY Hermione");
            Thread.Sleep(100);

            // Send words, and check the score messages:

            client1.SendGoMessage("WORD asdfjkl");
            client1.SendGoMessage("WORD re");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE -1 0", client1.msgString);
            Assert.AreEqual("SCORE 0 -1", client2.msgString);
        }
コード例 #12
0
            public void run()
            {
                try
                {
                    //setup server
                    server = new BoggleServer(10, "dictionary.txt", "AAAAAAAAAAAAAAAA");
                    server.LegalWords.Add("AAA");

                    //setup clients
                    BoggleClientModel target    = new BoggleClientModel();
                    string            IPAddress = "127.0.0.1";
                    string            name      = "test";

                    BoggleClientModel target2 = new BoggleClientModel();
                    string            name2   = "test2";

                    target.IncomingScoreEvent += delegate(string line)
                    {
                        MRE.Set();
                    };


                    target2.IncomingScoreEvent += delegate(string line)
                    {
                        MRE1.Set();
                    };

                    //connect the clients
                    target.Connect(IPAddress, name);
                    target2.Connect(IPAddress, name2);

                    //trigger event
                    target.SendMessage("WORD AAA");

                    Assert.AreEqual(true, MRE.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual(true, MRE1.WaitOne(timeout), "Timed out waiting 2");
                }
                finally
                {
                    server.close();
                }
            }
コード例 #13
0
        public void CloseSocket()
        {
            //Start a server and client
            Server            server = new Server(2000, new string[] { "200", "dictionary.txt" });
            BoggleClientModel model  = new BoggleClientModel();

            Assert.IsTrue(model.Connect("localhost", 2000, "hey"));

            model.CloseClient();

            try
            {
                model.SendWord("Test");
                Assert.Fail();
            }
            catch
            { }

            server.CloseServer();
        }
コード例 #14
0
        public void TestLargePointWords()
        {
            // Create two clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();

            // Connect the clients.
            client1.Connect("localhost", 2000, "PLAY Harry");
            client2.Connect("localhost", 2000, "PLAY Hermione");
            Thread.Sleep(100);

            // Send words and check scores.

            client1.SendGoMessage("WORD reloader");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 11 0", client1.msgString);
            Assert.AreEqual("SCORE 0 11", client2.msgString);

            client1.SendGoMessage("WORD RELOAD");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 14 0", client1.msgString);
            Assert.AreEqual("SCORE 0 14", client2.msgString);

            client2.SendGoMessage("WORD reload");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 11 0", client1.msgString);
            Assert.AreEqual("SCORE 0 11", client2.msgString);

            client2.SendGoMessage("WORD ReLoaDS");
            Thread.Sleep(100);
            Assert.AreEqual("SCORE 11 5", client1.msgString);
            Assert.AreEqual("SCORE 5 11", client2.msgString);

            // Make time run out, then check game summary messages.
            Thread.Sleep(6000);
            Assert.AreEqual("STOP 1 RELOADER 1 RELOADS 1 RELOAD 0 0", client1.msgString);
            Assert.AreEqual("STOP 1 RELOADS 1 RELOADER 1 RELOAD 0 0", client2.msgString);
        }
コード例 #15
0
        public void TwoGames()
        {
            // Create four clients.
            BoggleClientModel client1 = new BoggleClientModel();
            BoggleClientModel client2 = new BoggleClientModel();
            BoggleClientModel client3 = new BoggleClientModel();
            BoggleClientModel client4 = new BoggleClientModel();

            // Connect the clients.
            client1.Connect("localhost", 2000, "PLAY Harry");
            client2.Connect("localhost", 2000, "PLAY Hermione");
            client3.Connect("localhost", 2000, "PLAY Ron");
            client4.Connect("localhost", 2000, "PLAY Crookshanks");
            Thread.Sleep(1000);

            // Send words.
            client2.SendGoMessage("WORD load");
            client3.SendGoMessage("WORD reads");
            client1.SendGoMessage("WORD invalid");
            client4.SendGoMessage("WORD read");
            client1.SendGoMessage("WORD loads");
            client3.SendGoMessage("WORD xxx");
            client4.SendGoMessage("WORD reads");

            // Check scores.
            Thread.Sleep(200);
            Assert.AreEqual("SCORE 1 1", client1.msgString);
            Assert.AreEqual("SCORE 1 1", client2.msgString);
            Assert.AreEqual("SCORE -1 1", client3.msgString);
            Assert.AreEqual("SCORE 1 -1", client4.msgString);

            // Make time run out, then check game summary messages.
            Thread.Sleep(6000);
            Assert.AreEqual("STOP 1 LOADS 1 LOAD 0 1 INVALID 0", client1.msgString);
            //Assert.AreEqual("STOP 1 LOAD 1 LOADS 0 0 1 INVALID", client2.msgString);
            Assert.AreEqual("STOP 0 1 READ 1 READS 1 XXX 0", client3.msgString);
            //Assert.AreEqual("STOP 1 READ 0 1 READS 0 1 XXX", client4.msgString);
        }
コード例 #16
0
ファイル: Form1.cs プロジェクト: jimibue/cs3505
 private void connect_clicked(object sender, EventArgs e)
 {
     model.Connect("localhost", 2000, textBox_connect.Text);
 }
コード例 #17
0
        public void InvalidConnection()
        {
            BoggleClientModel model = new BoggleClientModel();

            Assert.IsFalse(model.Connect("asdfsdaf", 2000, "hey"));
        }
コード例 #18
0
ファイル: BoggleClientTest.cs プロジェクト: rensk63/cs-3500
            public void run()
            {
                BoggleServer.BoggleServer server    = null;
                BoggleClientModel         clientOne = null;
                BoggleClientModel         clientTwo = null;

                try
                {
                    string[] args = { "20", "../../../Resources/dictionary.txt", "jimiergsatnesaps" };
                    server = new BoggleServer.BoggleServer(args);

                    // create player one connection
                    clientOne = new BoggleClientModel();
                    clientOne.Connect("localhost");

                    // create player two connection
                    clientTwo = new BoggleClientModel();
                    clientTwo.Connect("localhost");

                    mre1 = new ManualResetEvent(false);
                    mre2 = new ManualResetEvent(false);

                    // have player one join the boggle game
                    clientOne.SendPlayerName("Basil");
                    // have player two join the boggle game
                    clientTwo.SendPlayerName("Lance");

                    // waits for one second, expecting the callback to trigger the mre1 signal
                    Assert.IsTrue(mre1.WaitOne(1000));
                    Assert.AreEqual("JIMIERGSATNESAPS", clientOne.getBoard());
                    Assert.AreEqual("BASIL", clientOne.getPlayerName());

                    // waits for one second, expecting the callback to trigger the mre2 signal
                    Assert.IsTrue(mre2.WaitOne(1000));
                    Assert.AreEqual("JIMIERGSATNESAPS", clientTwo.getBoard());
                    Assert.AreEqual("LANCE", clientTwo.getPlayerName());

                    //Reset the mres
                    mre1.Reset();
                    mre2.Reset();


                    //Check that the timer is working correctly
                    for (int i = 0; i < 29; i++)
                    {
                        mre1.Reset();
                        mre2.Reset();
                    }

                    clientOne.SendWord("to");
                    clientOne.SendWord("sap");
                    clientOne.SendWord("seat");
                    clientOne.SendWord("sat");

                    Thread.Sleep(11000);

                    clientTwo.SendWord("to");
                    clientTwo.SendWord("sap");
                    clientTwo.SendWord("irta");
                    clientTwo.SendWord("rat");

                    //add one for to
                    messagesReceivedOne.Add("SCORE " + 1 + " " + 0);
                    messagesReceivedOne.Add("SCORE " + 0 + " " + 0);
                    messagesReceivedOne.Add("SCORE " + 1 + " " + 0);

                    //add one for to
                    messagesReceivedTwo.Add("SCORE " + 0 + " " + 0);
                    messagesReceivedTwo.Add("SCORE " + 0 + " " + 0);
                    messagesReceivedTwo.Add("SCORE " + 1 + " " + 0);

                    Thread.Sleep(11000);

                    ////Do asserts
                    //// waits for one second, expecting the callback to trigger the mre1 signal
                    //Assert.IsTrue(mre1.WaitOne(1000));
                    //Assert.AreEqual("STOP 1 sat 1 rat 1 sap 1 seat 1 irta", s1);

                    //// waits for one second, expecting the callback to trigger the mre2 signal
                    //Assert.IsTrue(mre2.WaitOne(1000));
                    //Assert.AreEqual("STOP 1 rat 1 sat 1 sap 1 irta 1 seat", s2);
                }
                finally
                {
                    server.Stop();
                    clientOne.Disconnect();
                    clientTwo.Disconnect();
                }
            }