/// <summary> /// Displays a test sequence in the control. /// </summary> public void Initialize(TestSequence sequence) { ItemsLV.Items.Clear(); m_sequence = sequence; if (sequence != null) { foreach (TestCase testcase in sequence.TestCase) { AddItem(testcase); } } AdjustColumns(); }
/// <summary> /// Saves a test sequence to a stream. /// </summary> public static void Save(Stream ostrm, TestSequence sequence) { XmlTextWriter writer = new XmlTextWriter(ostrm, Encoding.UTF8); writer.Formatting = Formatting.Indented; try { XmlSerializer serializer = new XmlSerializer(typeof(TestSequence)); serializer.Serialize(writer, sequence); } finally { writer.Close(); } }
/// <summary> /// Checks if the specified test case is the last one to execute /// </summary> /// <param name="sequenceToExecute"></param> /// <param name="testCase">This parameter stores the test case related data.</param> /// <returns>True if the test case is the last test case.</returns> public static bool IsLastTestCase(TestSequence sequenceToExecute, TestCase testCase) { int lastTestCaseIndex = sequenceToExecute.TestCase.Length - 1; // Find the last testCase with skiptest attribute value as false ; while (lastTestCaseIndex >= 0 && sequenceToExecute.TestCase[lastTestCaseIndex].SkipTest == true) { lastTestCaseIndex--; } if (lastTestCaseIndex == -1) { // This case should never occur. return(true); } return(Object.ReferenceEquals(sequenceToExecute.TestCase[lastTestCaseIndex], testCase)); }
/// <summary> /// This method loads the test configuration from the specified file path. /// </summary> /// <param name="testFilePath">Test case file path.</param> public void LoadTestConfiguration(string testFilePath) { // (re)load the test configuration file. TestConfiguration configuration = TestConfiguration.Load("Opc.Ua.StackTest"); m_testFilePath = configuration.TestFilePath; if (!String.IsNullOrEmpty(testFilePath)) { m_testFilePath = testFilePath; } // load sequence to execute. m_sequenceToExecute = TestSequence.Load(m_testFilePath); m_randomFilePath = configuration.RandomFilePath; // TODO: How to handle multiple channels. Where will all those channels write to same log. m_logFilePath = configuration.LogFilePath; }
/// <summary> /// This method loads the test configuration. /// </summary> /// <param name="testFilePath">Test case file path.</param> private void LoadTestConfiguration(string testFilePath) { // (re)load the test configuration file. m_configuration = TestConfiguration.Load("Opc.Ua.StackTest"); if (!String.IsNullOrEmpty(testFilePath)) { m_configuration.TestFilePath = testFilePath; } // incorporate the server id into the log file path. int index = m_configuration.LogFilePath.LastIndexOf('.'); if (index != -1) { string path = m_configuration.LogFilePath; int subindex = path.LastIndexOf('_'); if (subindex < 0) { subindex = index; } m_configuration.LogFilePath = Utils.Format( "{0}_{1}{2}", path.Substring(0, subindex), m_serverId, path.Substring(index)); } // load sequence to execute. m_sequenceToExecute = TestSequence.Load(m_configuration.TestFilePath); // load random number file. m_random = new PseudoRandom(m_configuration.RandomFilePath); // open log file. m_logger = new Logger(m_configuration.LogFilePath, (TestLogDetailMasks)m_sequenceToExecute.LogDetailLevel); }
/// <summary> /// Loads a test sequence from a stream. /// </summary> public static TestSequence Load(Stream istrm) { XmlTextReader reader = new XmlTextReader(istrm); try { XmlSerializer serializer = new XmlSerializer(typeof(TestSequence)); TestSequence sequence = serializer.Deserialize(reader) as TestSequence; uint lastId = 1; foreach (TestCase testcase in sequence.TestCase) { if (testcase.TestId == 0) { testcase.TestId = lastId++; } else { if (testcase.TestId < lastId) { testcase.TestId = lastId++; } else { lastId = testcase.TestId + 1; } } } return(sequence); } finally { reader.Close(); } }
/// <summary> /// Saves a test sequence to a file. /// </summary> public static void Save(string filepath, TestSequence sequence) { Save(File.Open(filepath, FileMode.Create), sequence); }
/// <summary> /// Checks if the specified test case is the last one to execute /// </summary> /// <param name="sequenceToExecute"></param> /// <param name="testCase">This parameter stores the test case related data.</param> /// <returns>True if the test case is the last test case.</returns> public static bool IsLastTestCase(TestSequence sequenceToExecute, TestCase testCase) { int lastTestCaseIndex = sequenceToExecute.TestCase.Length - 1; // Find the last testCase with skiptest attribute value as false ; while (lastTestCaseIndex >= 0 && sequenceToExecute.TestCase[lastTestCaseIndex].SkipTest == true) { lastTestCaseIndex--; } if (lastTestCaseIndex == -1) { // This case should never occur. return true; } return Object.ReferenceEquals(sequenceToExecute.TestCase[lastTestCaseIndex], testCase); }