コード例 #1
0
ファイル: Method.cs プロジェクト: jonaias/StateMachineTesting
        /// <summary>
        /// Generates TestSequences from a FiniteStateMachine.
        /// </summary>
        /// <param name="fsm">Given FiniteStateMachine.</param>
        /// <returns>A set of TestSequence.</returns>
        public TestSequence[] Do(FiniteStateMachine fsma)
        {
            this.fsm = fsma;
            fsm.RefreshData();

            //////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Implemente aqui seu método de geração de casos de testes ou a chamada externa do método implementado //
            //////////////////////////////////////////////////////////////////////////////////////////////////////////

            ///////////////////
            // BEGIN SAMPLE  //
            ///////////////////

            //define current work path
            string currentPath = Directory.GetCurrentDirectory()+ @"\";
            string machineFile = @"machine.txt";
            string outputFile = @"sequence.txt";

            //Add aliases to machine (stateNAme => s_0)
            Dictionary<string, string> aliases = new Dictionary<string,string>();
            AddMachineAliases(aliases);

            //Export fsm as text.
            this.WriteFsmToFile(fsm, currentPath + machineFile);

            Console.ForegroundColor = ConsoleColor.DarkRed;
            Process p = new Process();

            p.StartInfo.FileName = currentPath + @"statemachines.exe"; // start qt executable
            p.StartInfo.Arguments = machineFile + @" " + outputFile;
            p.StartInfo.UseShellExecute = false; //Should be enable to redirect output
            p.StartInfo.RedirectStandardOutput = true; //redirect java output to console window
            p.Start();
            p.WaitForExit();

            //print output
            TextReader reader = new StreamReader(currentPath + outputFile);
            string output = reader.ReadToEnd();
            reader.Close();
            Console.WriteLine(output);

            //restore console color
            Console.ForegroundColor = ConsoleColor.White;

            //returns a set of sequences.
            List<TestSequence> sequences = this.ReadSequencesFromFile(currentPath + outputFile);

            //rename machines
            foreach (TestSequence seq in sequences)
                seq.Name = fsm.Name;

            foreach (Transition t in fsm.Transitions)
                Console.WriteLine(t.ToString());

            sequences = RemoveAliases(sequences, aliases);

            foreach(TestSequence t in sequences){
                Console.WriteLine("");
                foreach (string s in t.Path)
                    Console.Write(s);
            }
            return sequences.ToArray();

            ////////////////
            // END SAMPLE //
            ////////////////
        }
コード例 #2
0
ファイル: Method.cs プロジェクト: jonaias/StateMachineTesting
        /// <summary>
        /// Writes FSM to textual file.
        /// </summary>
        /// <param name="fsm"></param>
        /// <param name="p"></param>
        private void WriteFsmToFile(FiniteStateMachine fsm, string p)
        {
            String textualMachine = "";

            foreach (Transition t in fsm.Transitions)
                textualMachine +=
                    t.SourceState.Name + " -- " +
                    t.Input.ToString() + " / " +
                    t.Output.ToString() + " -> " +
                    t.TargetState.Name + "\r\n";

            TextWriter writer = new StreamWriter(p);
            writer.Write(textualMachine);
            writer.Close();
        }