using System;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;

namespace QC.CompareTestTree;

[Serializable]
public class TestProperties
{
	public const int TOOL = 0;

	public const int FOLDER_MUST_RUN = 1;

	public const int TREE_MUST_RUN = 2;

	private const int RUN_ONCE = 3;

	private const int SERIAL = 4;

	private const int CONCURRENT = 5;

	private const int PAUSE_ON_COMPLETION = 6;

	private const int TEST_MUST_RUN = 7;

	private const int LAST_UNUSED = 8;

	public const string TEST_PROPERTY = "TestProperty";

	protected string strRealName = "";

	private string strTestName;

	private StopOnErrorTypes typeStopOnError;

	private string desc = "";

	private bool ignoreEmptyParam;

	private string branchOnErrorName = "";

	private string branchOnErrorIndex = "";

	private ConditionMgr postConditionMgr;

	private ConditionMgr preConditionMgr;

	private bool bookKeeping;

	private int testTimeOut;

	protected string testErrorCode = "";

	protected string notes = "";

	private bool linkNode;

	protected ArrayList loopLinks = new ArrayList();

	private BitArray bAttributeArray = new BitArray(8, defaultValue: false);

	protected CheckState checkStateTest = CheckState.Checked;

	protected long nodeRID = -1L;

	protected int numberOfTests = 1;

	protected string descriptionName = "";

	protected ParameterCollection parameters = new ParameterCollection();

	protected string targetName = "This PC";

	protected bool expanded;

	protected bool testResultBasedOnLimits;

	protected bool dataLoggingOnlyOnFailure;

	private string testIndex;

	private int retryCount;

	protected LoopScenarioValues loopScenario;

	private bool enableLogging = true;

	private bool loopingInstance;

	[Browsable(false)]
	public bool Expanded
	{
		get
		{
			return expanded;
		}
		set
		{
			expanded = value;
		}
	}

	[Browsable(false)]
	[XmlIgnore]
	public string TestIndexCopy
	{
		get
		{
			return testIndex;
		}
		set
		{
			testIndex = value;
		}
	}

	[Description("Test name used for data collection and display.")]
	[Category("Settings")]
	public string TestName
	{
		get
		{
			return strTestName;
		}
		set
		{
			strTestName = value.Trim();
		}
	}

	[Category("Attributes")]
	[Description("Notifies scheduler what action to be taken when test fails.")]
	public virtual StopOnErrorTypes StopOnError
	{
		get
		{
			return typeStopOnError;
		}
		set
		{
			if (BranchOnError.Trim() == "" || value == StopOnErrorTypes.None)
			{
				typeStopOnError = value;
				return;
			}
			DialogResult dialogResult = MessageBox.Show("A test cannot have branch on error and stop on error set at the same time.\nBranch On Error will be modified for " + TestName, "QTM - Message Center", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
			if (dialogResult == DialogResult.OK)
			{
				branchOnErrorIndex = "";
				branchOnErrorName = "";
				typeStopOnError = value;
			}
		}
	}

	[Category("Settings")]
	[ReadOnly(true)]
	[Description("Original name of the test when it was created.")]
	public virtual string RealName
	{
		get
		{
			return strRealName;
		}
		set
		{
			strRealName = value;
		}
	}

	[Description("Target name of the test.")]
	[Category("Target")]
	[ReadOnly(true)]
	public virtual string TargetName
	{
		get
		{
			return targetName;
		}
		set
		{
			targetName = value;
		}
	}

	[Category("Settings")]
	[Description("Additional description about the test.")]
	public virtual string Description
	{
		get
		{
			return desc;
		}
		set
		{
			desc = value;
		}
	}

	[Category("Settings")]
	[Description("Specifies the number of times to rerun the test before it passes.")]
	public int RetryCount
	{
		get
		{
			return retryCount;
		}
		set
		{
			retryCount = value;
		}
	}

	[Browsable(false)]
	public LoopScenarioValues Scenarios
	{
		get
		{
			return loopScenario;
		}
		set
		{
			loopScenario = value;
		}
	}

	public virtual string LoopSetup
	{
		get
		{
			if (Scenarios != null)
			{
				return "True";
			}
			return "False";
		}
		set
		{
		}
	}

	[Browsable(false)]
	public string BranchOnErrorName
	{
		get
		{
			return branchOnErrorName;
		}
		set
		{
			branchOnErrorName = value;
		}
	}

	[Browsable(false)]
	public string BranchOnErrorIndex
	{
		get
		{
			return branchOnErrorIndex;
		}
		set
		{
			branchOnErrorIndex = value;
		}
	}

	[Browsable(false)]
	public CheckState CheckStateTest
	{
		get
		{
			return checkStateTest;
		}
		set
		{
			checkStateTest = value;
		}
	}

	[Browsable(false)]
	[XmlIgnore]
	public bool LinkNode
	{
		get
		{
			return linkNode;
		}
		set
		{
			linkNode = value;
		}
	}

	public virtual string BranchOnError
	{
		get
		{
			return branchOnErrorName;
		}
		set
		{
			branchOnErrorName = value;
		}
	}

	[XmlIgnore]
	public virtual string PostConditionAction
	{
		get
		{
			if (postConditionMgr != null)
			{
				return postConditionMgr.Action.ToString();
			}
			return "None";
		}
		set
		{
		}
	}

	[Browsable(false)]
	public virtual ConditionMgr PostCondition
	{
		get
		{
			return postConditionMgr;
		}
		set
		{
			postConditionMgr = value;
		}
	}

	public virtual string PreConditionEnabled
	{
		get
		{
			if (preConditionMgr != null)
			{
				return preConditionMgr.IsValid.ToString();
			}
			return "False";
		}
		set
		{
		}
	}

	public virtual ConditionMgr PreCondition
	{
		get
		{
			return preConditionMgr;
		}
		set
		{
			preConditionMgr = value;
		}
	}

	[Category("Settings")]
	[Description("Always return true as test result")]
	public virtual bool BookKeeping
	{
		get
		{
			return bookKeeping;
		}
		set
		{
			bookKeeping = value;
		}
	}

	[Description("When true, Empty string parameters will not be logged in data collection")]
	[Category("Attributes")]
	public bool IgnoreEmptyStringParameters
	{
		get
		{
			return ignoreEmptyParam;
		}
		set
		{
			ignoreEmptyParam = value;
		}
	}

	[Browsable(false)]
	[XmlElement(Type = typeof(string))]
	public ArrayList LoopLinks
	{
		get
		{
			return loopLinks;
		}
		set
		{
			loopLinks = value;
		}
	}

	[Description("Test runs only from context menu or if branch on error is set on it.")]
	[Category("Attributes")]
	public virtual bool ToolTest
	{
		get
		{
			return bAttributeArray[0];
		}
		set
		{
			if ((!bAttributeArray[2] && !bAttributeArray[1]) || !value)
			{
				bAttributeArray[0] = value;
				return;
			}
			DialogResult dialogResult = MessageBox.Show("A test cannot be must run and tool process at the same time.\nMustRun will be modified for " + TestName, "QTM - Message Center", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
			if (dialogResult == DialogResult.OK)
			{
				bAttributeArray[2] = false;
				bAttributeArray[1] = false;
				bAttributeArray[0] = value;
			}
		}
	}

	[Category("Attributes")]
	[Description("Test runs if any test in the tree runs.")]
	public virtual bool TreeMustRun
	{
		get
		{
			return bAttributeArray[2];
		}
		set
		{
			if (!bAttributeArray[0] || !value)
			{
				bAttributeArray[2] = value;
				return;
			}
			DialogResult dialogResult = MessageBox.Show("A test cannot be must run and tool process at the same time.\nTool property will be modified for " + TestName, "QTM - Message Center", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
			if (dialogResult == DialogResult.OK)
			{
				bAttributeArray[0] = false;
				bAttributeArray[2] = value;
			}
		}
	}

	[Description("Test Must Always Run, even if not selected as well as for each Rerun iteration.")]
	[Category("Attributes")]
	public virtual bool MustRunTest
	{
		get
		{
			return bAttributeArray[7];
		}
		set
		{
			if (!bAttributeArray[0] || !value)
			{
				bAttributeArray[7] = value;
				return;
			}
			DialogResult dialogResult = MessageBox.Show("A test cannot be must run and tool process at the same time.\nTool property will be modified for " + TestName, "QTM - Message Center", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
			if (dialogResult == DialogResult.OK)
			{
				bAttributeArray[0] = false;
				bAttributeArray[7] = value;
			}
		}
	}

	[Category("Settings")]
	[Description("The error code string will be set when the test fails. The GoNoGo result will reflect the first error code set during the GoNoGo")]
	public string TestErrorCode
	{
		get
		{
			return testErrorCode;
		}
		set
		{
			testErrorCode = value;
		}
	}

	[Category("Settings")]
	public virtual string Notes
	{
		get
		{
			return notes;
		}
		set
		{
			notes = value;
		}
	}

	[Category("Debug")]
	[Description("If enabled, debug messages for this test will be logged.")]
	public bool LoggingEnabled
	{
		get
		{
			return enableLogging;
		}
		set
		{
			enableLogging = value;
		}
	}

	[Description("If TRUE, the Pass result is verified with the Upper and Lower Limits.")]
	[Category("Attributes")]
	public virtual bool TestResultBasedOnLimits
	{
		get
		{
			return testResultBasedOnLimits;
		}
		set
		{
			testResultBasedOnLimits = value;
		}
	}

	[Category("Attributes")]
	[Description("If TRUE, data is collected only if test FAILs.")]
	public virtual bool DataLoggingOnlyOnFailure
	{
		get
		{
			return dataLoggingOnlyOnFailure;
		}
		set
		{
			dataLoggingOnlyOnFailure = value;
		}
	}

	[Description("Specifies the length of time in seconds before test times out and is stopped.\nA zero value indicates that test will not time out.")]
	[Category("Settings")]
	public virtual int TestTimeOut
	{
		get
		{
			return testTimeOut;
		}
		set
		{
			testTimeOut = value;
		}
	}

	[Browsable(false)]
	public virtual long NodeRID
	{
		get
		{
			return nodeRID;
		}
		set
		{
			nodeRID = value;
		}
	}

	[Browsable(false)]
	public virtual int NumberOfTests
	{
		get
		{
			return numberOfTests;
		}
		set
		{
			numberOfTests = value;
		}
	}

	[Description("Test runs if any test in its parent folder runs.")]
	[Category("Attributes")]
	public virtual bool FolderMustRun
	{
		get
		{
			return bAttributeArray[1];
		}
		set
		{
			if (!bAttributeArray[0] || !value)
			{
				bAttributeArray[1] = value;
				return;
			}
			DialogResult dialogResult = MessageBox.Show("A test cannot be must run and tool process at the same time.\nTool property will be modified for " + TestName, "QTM - Message Center", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
			if (dialogResult == DialogResult.OK)
			{
				bAttributeArray[0] = false;
				bAttributeArray[1] = value;
			}
		}
	}

	[Category("Attributes")]
	[Description("Pause Tree On Completion Of Test.")]
	public virtual bool PauseTreeOnCompletion
	{
		get
		{
			return bAttributeArray[6];
		}
		set
		{
			bAttributeArray[6] = value;
		}
	}

	[XmlIgnore]
	[Browsable(false)]
	public virtual string DescriptionName
	{
		get
		{
			return descriptionName;
		}
		set
		{
			descriptionName = value;
		}
	}

	[XmlElement("Parameters")]
	public virtual ParameterCollection Parameters
	{
		get
		{
			return parameters;
		}
		set
		{
			parameters = value;
		}
	}

	[Browsable(false)]
	[XmlAttribute("NodeType")]
	public virtual string NodeType
	{
		get
		{
			return "TestProperty";
		}
		set
		{
		}
	}

	[Browsable(false)]
	public bool LoopingInstance
	{
		get
		{
			return loopingInstance;
		}
		set
		{
			loopingInstance = value;
		}
	}

	public TestProperties()
	{
		typeStopOnError = StopOnErrorTypes.None;
	}

	public void CompareProperties(TestProperties baseProperties, string overrideAttrib, ref XmlDocument xmlDoc, ref XmlElement parentNode)
	{
		CommonFunctions.RootDoc = xmlDoc;
		CommonFunctions.ParentNode = parentNode;
		CommonFunctions.AddElement("TestName", TestName, baseProperties.TestName, overrideAttrib);
		CommonFunctions.AddElement("BranchOnError", BranchOnError, baseProperties.BranchOnError, overrideAttrib);
		CommonFunctions.AddElement("FolderMustRun", FolderMustRun, baseProperties.FolderMustRun, overrideAttrib);
		CommonFunctions.AddElement("PauseTreeOnCompletion", PauseTreeOnCompletion, baseProperties.PauseTreeOnCompletion, overrideAttrib);
		CommonFunctions.AddElement("DataLoggingOnlyOnFailure", DataLoggingOnlyOnFailure, baseProperties.DataLoggingOnlyOnFailure, overrideAttrib);
		CommonFunctions.AddElement("IgnoreEmptyStringParameters", IgnoreEmptyStringParameters, baseProperties.IgnoreEmptyStringParameters, overrideAttrib);
		CommonFunctions.AddElement("StopOnError", StopOnError.ToString(), baseProperties.StopOnError.ToString(), overrideAttrib);
		CommonFunctions.AddElement("TestErrorCode", TestErrorCode, baseProperties.TestErrorCode, overrideAttrib);
		CommonFunctions.AddElement("TestResultBasedOnLimits", TestResultBasedOnLimits, baseProperties.TestResultBasedOnLimits, overrideAttrib);
		CommonFunctions.AddElement("ToolTest", ToolTest, baseProperties.ToolTest, overrideAttrib);
		CommonFunctions.AddElement("TreeMustRun", TreeMustRun, baseProperties.TreeMustRun, overrideAttrib);
		CommonFunctions.AddElement("MustRunTest", MustRunTest, baseProperties.MustRunTest, overrideAttrib);
		CommonFunctions.AddElement("BookKeeping", BookKeeping, baseProperties.BookKeeping, overrideAttrib);
		CommonFunctions.AddElement("Description", Description, baseProperties.Description, overrideAttrib);
		CommonFunctions.AddElement("Notes", Notes, baseProperties.Notes, overrideAttrib);
		CommonFunctions.AddElement("LoopSetup", LoopSetup, baseProperties.LoopSetup, overrideAttrib);
		CommonFunctions.AddElement("TestTimeOut", TestTimeOut, baseProperties.TestTimeOut, overrideAttrib);
		CommonFunctions.AddElement("RetryCount", RetryCount, baseProperties.RetryCount, overrideAttrib);
		CommonFunctions.AddElement("PreConditionEnabled", PreConditionEnabled, baseProperties.PreConditionEnabled, overrideAttrib);
		CommonFunctions.AddElement("PostConditionAction", PostConditionAction, baseProperties.PostConditionAction, overrideAttrib);
		CommonFunctions.AddElement("CheckStateTest", CheckStateTest.ToString(), baseProperties.CheckStateTest.ToString(), overrideAttrib);
		CommonFunctions.AddElement("LoggingEnabled", LoggingEnabled.ToString(), baseProperties.LoggingEnabled.ToString(), overrideAttrib);
		LoopScenarioValues scenarios = Scenarios;
		LoopScenarioValues scenarios2 = baseProperties.Scenarios;
		if (scenarios != null || scenarios2 != null)
		{
			if (scenarios == null)
			{
				scenarios2.CompareLoopScenario("Scenarios", scenarios2, "Remove", ref xmlDoc, ref parentNode);
			}
			else if (scenarios2 == null)
			{
				scenarios.CompareLoopScenario("Scenarios", scenarios, "Add", ref xmlDoc, ref parentNode);
			}
			else
			{
				scenarios.CompareLoopScenario("Scenarios", scenarios2, overrideAttrib, ref xmlDoc, ref parentNode);
			}
		}
	}
}
