public void BasicFunctionalTest()
            {
                // This will create a MockEngineProcess when invoked by the UCIChessEngine
                Trace.WriteLine("Creating Mock Loader...");
                MockEngineProcessLoader mockLoader = new MockEngineProcessLoader();

                // prevents the test from exiting until all events are accounted for
                testDone = new AutoResetEvent(false);

                // Create a real engine object using the mock loader (and mock process by extension)
                Trace.WriteLine("Creating Real Engine passing Mock Loader...");
                UCIChessEngine engine = new UCIChessEngine(mockLoader);

                engine.OnChessEngineResponseReceived      += ChessEngineResponseReceivedEventHandler;
                engine.OnChessEngineVerboseOutputReceived += ChessEngineVerboseResponseReceivedEventHandler;

                // This will force the loader to get invoked, it's required to init the engine
                // but the path is ingored by the mock loader, so pass anything
                Trace.WriteLine("Telling the engine to load...");
                engine.LoadEngine("x:\\foo\\bar\\myeng.exe");

                // At this point, the UCIChessEngine should think it's good to go.
                // We can issue commands as normal here, and the mock process will
                // respond to UCIChessEngine in a way to finish the cycle (e.g.
                // if it gets 'isready' it will respond with 'readyok'.  The actual
                // moves don't matter at all, just the response.  There are no
                // chess game rules applied here (we're below ChessGame)

                // Responses go to ChessEngineResponseReceivedEventHandler below
                Trace.WriteLine("Starting UCI protocol...");
                engine.InitializeUciProtocol();
                Trace.WriteLine("Setting option...");
                engine.SetOption("foo", "bar");
                Trace.WriteLine("Setting option...");
                engine.SetOption("foo1", "bar1");
                Trace.WriteLine("Resetting board...");
                engine.ResetBoard();
                Trace.WriteLine("Getting move...");
                engine.GetMoveForCurrentPosition("1000");
                Trace.WriteLine("Setting position...");
                engine.SetPosition("foobar");
                Trace.WriteLine("Getting move...");
                engine.GetMoveForCurrentPosition("1000");
                Trace.WriteLine("Setting position...");
                engine.SetPosition("foobar");
                Trace.WriteLine("Getting move...");
                engine.GetMoveForCurrentPosition("1000");
                Trace.WriteLine("Setting position...");
                engine.SetPosition("foobar");
                Trace.WriteLine("Getting move...");
                engine.GetMoveForCurrentPosition("1000");
                Trace.WriteLine("Setting position...");
                engine.SetPosition("foobar");
                Trace.WriteLine("Waiting for last response...");
                Assert.IsTrue(testDone.WaitOne(30000));
                // There are no extraneous responses in the mock (like info)
                // so these should match in count.
                Assert.IsTrue(verboseCount == commandCount);
            }
Exemplo n.º 2
0
            public void BasicInitTest()
            {
                MockEngineProcessLoader mockLoader = new MockEngineProcessLoader();
                MockChessBoardView      mockView   = new MockChessBoardView();
                string mockPath = @"x:\Foo\Bar\MyEngine.exe";

                // More or less base tests the mocks, just make sure this doesn't
                // crash/compiles
                Trace.WriteLine("Creating ChessGame object with mocks injected");
                ChessGame chessGame = new ChessGame(
                    mockView,   // View
                    mockPath,   // Path
                    mockLoader, // Loader
                    false,      // Reduce ELO
                    Thread.CurrentThread.CurrentUICulture);

                chessGame.NewGame(PieceColor.White, 5000);
            }