static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Environment
            env = new SimulationEnvironment.SimulationEnvironment();

            // TrackModel
            TrackModel.TrackModel trackModel = new TrackModel.TrackModel(env);
            env.TrackModel = trackModel;
            TrackModel.TrackModelGUI trackModelGui = new TrackModelGUI(env, trackModel);

            // CTCOffice
            CTCOffice.CTCOffice ctcOffice = new CTCOffice.CTCOffice(env, env.PrimaryTrackControllerRed, env.PrimaryTrackControllerGreen);
            env.CTCOffice = ctcOffice;
            CTCOffice.CTCOfficeGUI ctcOfficeGui = new CTCOfficeGUI(env, ctcOffice);
            ctcOfficeGui.ShowTrain += new EventHandler<ShowTrainEventArgs>(ctcOfficeGui_ShowTrain);
            ctcOfficeGui.ShowSchedule += new EventHandler<EventArgs>(ctcOfficeGui_ShowSchedule);

            // Scheduler
            SystemScheduler.SystemScheduler scheduler = new SystemScheduler.SystemScheduler(env, ctcOffice);
            env.SystemScheduler = scheduler;
            SystemScheduler.SystemSchedulerGUI schedulerGui = new SystemScheduler.SystemSchedulerGUI(env, scheduler, ctcOffice);

            // train model form
            TrainModel.TrainGUI trainGui = new TrainGUI(env);

            // Track Controllers
            if (env.PrimaryTrackControllerRed != null)
            {
                TrackController.TrackController red = (TrackController.TrackController)env.PrimaryTrackControllerRed;
                TrackControllerUi redTcGui = new TrackControllerUi(env, red);
                trackControllerRedForm = new Form() { Controls = { redTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Red" };
            }

            if (env.PrimaryTrackControllerGreen != null)
            {
                TrackController.TrackController green = (TrackController.TrackController)env.PrimaryTrackControllerGreen;
                TrackControllerUi greenTcGui = new TrackControllerUi(env, green);
                trackControllerGreenForm = new Form() { Controls = { greenTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Green" };
            }

            ctcForm = new Form() { Controls = { ctcOfficeGui }, AutoSize = true, Text="Terminal Velocity - CTC Office"};
            schedulerForm = new Form() { Controls = { schedulerGui }, TopLevel = true, AutoSize = true, Parent = null, Text="Terminal Velocity - System Scheduler" };
            trackModelForm = new Form() { Controls = { trackModelGui }, TopLevel = true, AutoSize = true, Parent = null, Text="Terminal Velocity - Track Model"};
            trainModelForm = new Form() { Controls = { trainGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Trains" };

            //TODO
            /*
             * Train Controller Form(s)
             * Train Model Form
            */

            ctcForm.Shown += new EventHandler(ctcForm_Shown);

            Application.Run(ctcForm);
        }
Beispiel #2
0
        public bool DoTest(out int pass, out int fail, out List <string> message)
        {
            //local
            pass    = 0;
            fail    = 0;
            message = new List <string>();

            //global for events
            _pass    = 0;
            _fail    = 0;
            _message = new List <string>();

            redRequests = new bool[7] {
                false, false, false, false, false, false, false
            };
            greenRequests = new bool[7] {
                false, false, false, false, false, false, false
            };


            //create environment instance
            _env = new SimulationEnvironment.SimulationEnvironment();

            //create testing track model
            _trackMod = new TestingTrackModel(_env);

            //creating testing track controllers
            _red   = new TestingTrackController(0, _trackMod, _env, false);
            _green = new TestingTrackController(1, _trackMod, _env, false);

            //hook to environment
            _env.PrimaryTrackControllerRed   = _red;
            _red.TransferRequest            += new EventHandler <EventArgs>(_red_TransferRequest);
            _env.PrimaryTrackControllerGreen = _green;
            _green.TransferRequest          += new EventHandler <EventArgs>(_green_TransferRequest);
            _env.TrackModel = _trackMod;

            //creating office instance
            _ctc = new CTCOffice.CTCOffice(_env, _red, _green);
            if (_ctc != null)
            {
                pass++;
                message.Add("CTC Object Secessfully Created");
            }
            else
            {
                fail++;
                message.Add("CTC Object Not Secessfully Created");
            }

            _env.CTCOffice        = _ctc;
            _ctc.StartAutomation += new EventHandler <EventArgs>(_ctc_StartAutomation);
            _ctc.StopAutomation  += new EventHandler <EventArgs>(_ctc_StopAutomation);
            _ctc.LoadData        += new EventHandler <EventArgs>(_ctc_LoadData);
            _ctc.MessagesReady   += new EventHandler <EventArgs>(_ctc_MessagesReady);
            _ctc.UnlockLogin     += new EventHandler <EventArgs>(_ctc_UnlockLogin);
            _ctc.UpdatedData     += new EventHandler <EventArgs>(_ctc_UpdatedData);
            _env.StartTick();

            _trackMod.ThrowTrackChanged();



            if (_env.CTCOffice != null)
            {
                pass++;
                message.Add("CTC Office Added to Environment");

                #region Login Testing
                //Test Improper Login
                if (!_ctc.Login("me", "42"))
                {
                    pass++;
                    message.Add("PASS: Operator has invalid credentials");
                }
                else
                {
                    fail--;
                    message.Add("FAIL: Operator has invlaid credentials");
                }

                //Test Operator Auth (invalid creds)
                if (!_ctc.IsAuth())
                {
                    pass++;
                    message.Add("PASS: Op Auth (Lockout)");
                }
                else
                {
                    fail++;
                    message.Add("FAIL: Op Auth (Lockout)");
                }

                //Test Proper Login
                if (_ctc.Login("root", "admin"))
                {
                    pass++;
                    message.Add("PASS: Operator Login");
                }
                else
                {
                    fail--;
                    message.Add("FAIL: Operator Login");
                }

                //Test Operator Auth (invalid creds)
                if (_ctc.IsAuth())
                {
                    pass++;
                    message.Add("PASS: Op Auth");
                }
                else
                {
                    fail++;
                    message.Add("FAIL: Op Auth");
                }

                //Logout
                //Always returns true
                pass++;
                message.Add("PASS: Logout (always true)");

                #endregion

                //Populate Track -> void function.. always passes unit test
                pass++;
                message.Add("PASS: PopulateTrack() (always true unless exception is generated)");

                //call for start scheduling
                _ctc.StartScheduling();
                _ctc.StopScheduling();

                #region Test Get Line
                if (_ctc.GetLine(0) != null)
                {
                    pass++;
                    message.Add("PASS: GetLine(0) -> Red.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(0) -> Red.");
                }

                if (_ctc.GetLine(1) != null)
                {
                    pass++;
                    message.Add("PASS: GetLine(1) -> Green.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(1) -> Green.");
                }

                if (_ctc.GetLine(2) == null)
                {
                    pass++;
                    message.Add("PASS: GetLine(2) -> null.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(0) -> null.");
                }
                #endregion

                //Cannot test private functions (including Line ID functions)

                //RequestTypes.AssignTrainRoute
                //RequestTypes.SetTrainAuthority
                //RequestTypes.SetTrainOOS
                //RequestTypes.SetTrainSpeed
                ////RequestTypes.TrackControllerData
                //RequestTypes.TrackMaintenanceClose
                //RequestTypes.TrackMaintenanceOpen

                TestingBlock redBlock   = new TestingBlock("Red", 0, 0, 0, null, true, false, false, false, false, false, StateEnum.Healthy);
                TestingBlock greenBlock = new TestingBlock("Green", 0, 0, 0, null, true, false, false, false, false, false, StateEnum.Healthy);

                _ctc.assignTrainRouteRequest(1, 0, null, redBlock);
                _ctc.setTrainAuthorityRequest(1, 0, 50, redBlock);
                _ctc.setTrainOutOfServiceRequest(1, 0, redBlock);
                _ctc.setTrainSpeedRequest(1, 0, 50, redBlock);
                _ctc.closeTrackBlockRequest(0, redBlock);
                _ctc.openTrackBlockRequest(0, redBlock);

                _ctc.assignTrainRouteRequest(1, 1, null, greenBlock);
                _ctc.setTrainAuthorityRequest(1, 1, 50, greenBlock);
                _ctc.setTrainOutOfServiceRequest(1, 1, greenBlock);
                _ctc.setTrainSpeedRequest(1, 1, 50, greenBlock);
                _ctc.closeTrackBlockRequest(1, greenBlock);
                _ctc.openTrackBlockRequest(1, greenBlock);

                //dispatch train handled in GUI Tester

                //cannot test handleResponse.  No actual case to test
            }
            else
            {
                fail++;
                message.Add("CTC Office Not Added to Environment");
            }



            //add event handler tests
            pass = pass + _pass;
            fail = fail + _fail;
            message.AddRange(_message);
            return(true);
        }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Environment
            env = new SimulationEnvironment.SimulationEnvironment();

            // TrackModel
            TrackModel.TrackModel trackModel = new TrackModel.TrackModel(env);
            env.TrackModel = trackModel;
            TrackModel.TrackModelGUI trackModelGui = new TrackModelGUI(env, trackModel);

            // CTCOffice
            CTCOffice.CTCOffice ctcOffice = new CTCOffice.CTCOffice(env, env.PrimaryTrackControllerRed, env.PrimaryTrackControllerGreen);
            env.CTCOffice = ctcOffice;
            CTCOffice.CTCOfficeGUI ctcOfficeGui = new CTCOfficeGUI(env, ctcOffice);
            ctcOfficeGui.ShowTrain    += new EventHandler <ShowTrainEventArgs>(ctcOfficeGui_ShowTrain);
            ctcOfficeGui.ShowSchedule += new EventHandler <EventArgs>(ctcOfficeGui_ShowSchedule);


            // Scheduler
            SystemScheduler.SystemScheduler scheduler = new SystemScheduler.SystemScheduler(env, ctcOffice);
            env.SystemScheduler = scheduler;
            SystemScheduler.SystemSchedulerGUI schedulerGui = new SystemScheduler.SystemSchedulerGUI(env, scheduler, ctcOffice);

            // train model form
            TrainModel.TrainGUI trainGui = new TrainGUI(env);

            // Track Controllers
            if (env.PrimaryTrackControllerRed != null)
            {
                TrackController.TrackController red = (TrackController.TrackController)env.PrimaryTrackControllerRed;
                TrackControllerUi redTcGui          = new TrackControllerUi(env, red);
                trackControllerRedForm = new Form()
                {
                    Controls = { redTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Red"
                };
            }

            if (env.PrimaryTrackControllerGreen != null)
            {
                TrackController.TrackController green = (TrackController.TrackController)env.PrimaryTrackControllerGreen;
                TrackControllerUi greenTcGui          = new TrackControllerUi(env, green);
                trackControllerGreenForm = new Form()
                {
                    Controls = { greenTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Green"
                };
            }

            ctcForm = new Form()
            {
                Controls = { ctcOfficeGui }, AutoSize = true, Text = "Terminal Velocity - CTC Office"
            };
            schedulerForm = new Form()
            {
                Controls = { schedulerGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - System Scheduler"
            };
            trackModelForm = new Form()
            {
                Controls = { trackModelGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Model"
            };
            trainModelForm = new Form()
            {
                Controls = { trainGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Trains"
            };


            //TODO

            /*
             * Train Controller Form(s)
             * Train Model Form
             */

            ctcForm.Shown += new EventHandler(ctcForm_Shown);

            Application.Run(ctcForm);
        }
        public bool DoTest(out int pass, out int fail, out List<string> message)
        {
            //local
            pass = 0;
            fail = 0;
            message = new List<string>();

            //global for events
            _pass = 0;
            _fail = 0;
            _message = new List<string>();

            redRequests = new bool[7] { false, false, false, false, false, false, false };
            greenRequests = new bool[7] { false, false, false, false, false, false, false };

            //create environment instance
            _env = new SimulationEnvironment.SimulationEnvironment();

            //create testing track model
            _trackMod = new TestingTrackModel(_env);

            //creating testing track controllers
            _red = new TestingTrackController(0, _trackMod, _env, false);
            _green = new TestingTrackController(1, _trackMod, _env, false);

            //hook to environment
            _env.PrimaryTrackControllerRed = _red;
            _red.TransferRequest += new EventHandler<EventArgs>(_red_TransferRequest);
            _env.PrimaryTrackControllerGreen = _green;
            _green.TransferRequest += new EventHandler<EventArgs>(_green_TransferRequest);
            _env.TrackModel = _trackMod;

            //creating office instance
            _ctc = new CTCOffice.CTCOffice(_env, _red, _green);
            if (_ctc != null)
            {
                pass++;
                message.Add("CTC Object Secessfully Created");
            }
            else
            {
                fail++;
                message.Add("CTC Object Not Secessfully Created");
            }

            _env.CTCOffice = _ctc;
            _ctc.StartAutomation += new EventHandler<EventArgs>(_ctc_StartAutomation);
            _ctc.StopAutomation += new EventHandler<EventArgs>(_ctc_StopAutomation);
            _ctc.LoadData += new EventHandler<EventArgs>(_ctc_LoadData);
            _ctc.MessagesReady += new EventHandler<EventArgs>(_ctc_MessagesReady);
            _ctc.UnlockLogin += new EventHandler<EventArgs>(_ctc_UnlockLogin);
            _ctc.UpdatedData += new EventHandler<EventArgs>(_ctc_UpdatedData);
            _env.StartTick();

            _trackMod.ThrowTrackChanged();

            if (_env.CTCOffice != null)
            {
                pass++;
                message.Add("CTC Office Added to Environment");

                #region Login Testing
                //Test Improper Login
                if (!_ctc.Login("me", "42"))
                {
                    pass++;
                    message.Add("PASS: Operator has invalid credentials");
                }
                else
                {
                    fail--;
                    message.Add("FAIL: Operator has invlaid credentials");
                }

                //Test Operator Auth (invalid creds)
                if (!_ctc.IsAuth())
                {
                    pass++;
                    message.Add("PASS: Op Auth (Lockout)");
                }
                else
                {
                    fail++;
                    message.Add("FAIL: Op Auth (Lockout)");
                }

                //Test Proper Login
                if (_ctc.Login("root", "admin"))
                {
                    pass++;
                    message.Add("PASS: Operator Login");
                }
                else
                {
                    fail--;
                    message.Add("FAIL: Operator Login");
                }

                //Test Operator Auth (invalid creds)
                if (_ctc.IsAuth())
                {
                    pass++;
                    message.Add("PASS: Op Auth");
                }
                else
                {
                    fail++;
                    message.Add("FAIL: Op Auth");
                }

                //Logout
                //Always returns true
                pass++;
                message.Add("PASS: Logout (always true)");

                #endregion

                //Populate Track -> void function.. always passes unit test
                pass++;
                message.Add("PASS: PopulateTrack() (always true unless exception is generated)");

                //call for start scheduling
                _ctc.StartScheduling();
                _ctc.StopScheduling();

                #region Test Get Line
                if (_ctc.GetLine(0) != null)
                {
                    pass++;
                    message.Add("PASS: GetLine(0) -> Red.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(0) -> Red.");
                }

                if (_ctc.GetLine(1) != null)
                {
                    pass++;
                    message.Add("PASS: GetLine(1) -> Green.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(1) -> Green.");
                }

                if (_ctc.GetLine(2) == null)
                {
                    pass++;
                    message.Add("PASS: GetLine(2) -> null.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(0) -> null.");
                }
                #endregion

                //Cannot test private functions (including Line ID functions)

                //RequestTypes.AssignTrainRoute
                //RequestTypes.SetTrainAuthority
                //RequestTypes.SetTrainOOS
                //RequestTypes.SetTrainSpeed
                ////RequestTypes.TrackControllerData
                //RequestTypes.TrackMaintenanceClose
                //RequestTypes.TrackMaintenanceOpen

                TestingBlock redBlock = new TestingBlock("Red", 0, 0, 0, null, true, false, false, false, false, false, StateEnum.Healthy);
                TestingBlock greenBlock = new TestingBlock("Green", 0, 0, 0, null, true, false, false, false, false, false, StateEnum.Healthy);

                _ctc.assignTrainRouteRequest(1, 0, null, redBlock);
                _ctc.setTrainAuthorityRequest(1, 0, 50, redBlock);
                _ctc.setTrainOutOfServiceRequest(1, 0, redBlock);
                _ctc.setTrainSpeedRequest(1, 0, 50, redBlock);
                _ctc.closeTrackBlockRequest(0, redBlock);
                _ctc.openTrackBlockRequest(0, redBlock);

                _ctc.assignTrainRouteRequest(1, 1, null, greenBlock);
                _ctc.setTrainAuthorityRequest(1, 1, 50, greenBlock);
                _ctc.setTrainOutOfServiceRequest(1, 1, greenBlock);
                _ctc.setTrainSpeedRequest(1, 1, 50, greenBlock);
                _ctc.closeTrackBlockRequest(1, greenBlock);
                _ctc.openTrackBlockRequest(1, greenBlock);

                //dispatch train handled in GUI Tester

                //cannot test handleResponse.  No actual case to test
            }
            else
            {
                fail++;
                message.Add("CTC Office Not Added to Environment");
            }

            //add event handler tests
            pass = pass + _pass;
            fail = fail + _fail;
            message.AddRange(_message);
            return true;
        }