chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using System.IO;
using System.Linq;
using NUnit.Framework;
using OpenTap.Plugins.BasicSteps;
namespace OpenTap.UnitTests;
 
[TestFixture]
public class TestPlanReferenceTest
{
    [Test]
    public void RemovingParameterFromReferencedPlan()
    {
        // this unit test checks that a parameterization is automatically removed if
        // the parameter comes from a test plan reference which initially has the parameter
        // but later the referenced plan removes the parameter after which
        // the test plan is reloaded.
 
        var planWithoutParam = nameof(RemovingParameterFromReferencedPlan) + ".no-parameter.TapPlan";
        var planWithParam = nameof(RemovingParameterFromReferencedPlan) + ".parameter.TapPlan";
        try
        {
            {
                // create two test plans, one with the external parameter 'A' and one without.
                var plan = new TestPlan();
                var step = new DelayStep();
                plan.ChildTestSteps.Add(step);
                plan.Save(planWithoutParam);
                TypeData.GetTypeData(step).GetMember(nameof(step.DelaySecs)).Parameterize(plan, step, "A");
                plan.Save(planWithParam);
            }
 
            {
 
                var plan = new TestPlan();
                var tpr = new TestPlanReference();
 
                // first we load the test plan reference containing the parameter A and 
                // parameterize that onto the plan.
 
                tpr.Filepath.Text = planWithParam;
                plan.ChildTestSteps.Add(tpr);
                tpr.LoadTestPlan();
                var aMember = TypeData.GetTypeData(tpr).GetMember("A");
                aMember.Parameterize(plan, tpr, "B");
                var memberBPre = TypeData.GetTypeData(plan).GetMember("B");
 
                // now we select the test plan _without_ the parameter A
                // and load that with the parameter B still existing on the test plan.
 
                tpr.Filepath.Text = planWithoutParam;
                tpr.LoadTestPlan();
 
                var memberBPost = TypeData.GetTypeData(plan).GetMember("B");
 
                // if everything works, we should no longer be able to access 'B'.
                // it is automatically removed by the parameter sanitation algorithm, ParameterManager.checkParameterSanity.
 
                Assert.IsNotNull(memberBPre);
                Assert.IsNull(memberBPost);
            }
 
        }
        finally
        {
            File.Delete(planWithoutParam);
            File.Delete(planWithParam);
        }
    }
 
    /// <summary>
    /// tests various aspects of converting a test plan reference to a sequence.
    /// </summary>
    [Test]
    public void TestConvertToSequence()
    {
        string targetFile = "TestConvertToSequence.unittest.TapPlan";
        {
            File.Delete(targetFile);
            var referencedPlan = new TestPlan();
            var step = new DelayStep();
            referencedPlan.ChildTestSteps.Add(step);
            TypeData.GetTypeData(step).GetMember(nameof(step.DelaySecs)).Parameterize(referencedPlan, step, "A");
 
            var b1 = new TestNumberMixinBuilder()
            {
                Name = "Test",
                IsOutput = true
            };
            MixinFactory.LoadMixin(referencedPlan, b1);
            var member = TypeData.GetTypeData(referencedPlan).GetMember("Number.Test");
 
            var mv = member.GetValue(referencedPlan);
            Assert.IsNotNull(mv);
            member.SetValue(referencedPlan, 10);
 
            referencedPlan.Save(targetFile);
        }
        {
            var mixinTest = new MixinTestBuilder()
            {
                TestMember = "B"
            };
 
            var plan = new TestPlan();
            var testPlanReference = new TestPlanReference();
            MixinFactory.LoadMixin(testPlanReference, mixinTest);
            testPlanReference.Filepath.Text = targetFile;
            plan.ChildTestSteps.Add(testPlanReference);
            testPlanReference.LoadTestPlan();
 
            {
                var member = TypeData.GetTypeData(testPlanReference).GetMember("Number.Test");
                Assert.IsNotNull(member);
                var v = member.GetValue(testPlanReference);
                Assert.AreEqual(10.0, v);
            }
 
            // convert to sequence without showing a popup.
            using (Session.Create())
            {
                UserInput.SetInterface(null);
                testPlanReference.ConvertToSequence();
            }
 
            // loop twice to also try after serializing.
            for (int i = 0; i < 2; i++)
            {
 
                Assert.IsTrue(plan.ChildTestSteps[0] is SequenceStep);
                var seq = plan.ChildTestSteps[0] as SequenceStep;
                var members = TypeData.GetTypeData(seq).GetMembers();
 
                var member = members.FirstOrDefault(mem => mem.Name == "Number.Test");
                Assert.IsNotNull(member);
                var v = member.GetValue(seq);
                Assert.IsNotNull(v);
                var embeddedMembers = members.OfType<IEmbeddedMemberData>().ToArray();
                Assert.IsTrue(embeddedMembers.Length > 0);
                var delaymember = TypeData.GetTypeData(seq).GetMember("A");
                delaymember.SetValue(seq, 0.0);
 
                var run = plan.Execute();
                Assert.IsTrue(run.Verdict == Verdict.NotSet);
 
                // for the next iteration, lets try saving and loading it.
 
                plan.Save(targetFile);
                plan = TestPlan.Load(targetFile);
            }
        }
    }
}