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
//            Copyright Keysight Technologies 2012-2019
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at http://mozilla.org/MPL/2.0/.
using System;
using NUnit.Framework;
using System.Collections.Generic;
using System.Threading;
using OpenTap.Cli;
 
namespace OpenTap.Engine.UnitTests
{
    [TestFixture]
    public class TestPlanRunnerTests
    {
        [SetUp]
        public void AssemblyInit()
        {
            SessionLogs.Initialize(String.Format("UnitTestLog{0}.txt", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss")));
        }
 
        public class CliTestStep : TestStep
        {
            TraceSource _log =  OpenTap.Log.CreateSource("CliStep");
            public override void Run()
            {
                _log.Info("Test123");
            }
        }
 
        [Test]
        public void RunPlanTest()
        {
            PluginManager.SearchAsync();
            TestPlanRunner.SetSettingsDir("Default");
            TestPlan plan = new TestPlan();
            plan.Steps.Add(new CliTestStep());
            CancellationTokenSource cts = new CancellationTokenSource();
            TestPlanRunner.RunPlanForDut(plan, new List<ResultParameter>(), cts.Token);
        }
 
        [Test]
        public void SimpleVerdictStepTest()
        {
            var setVerdict = new OpenTap.Engine.UnitTests.TestTestSteps.VerdictStep();
            TestPlan plan = new TestPlan();
            plan.Steps.Add(setVerdict);
            plan.Save("verdictPlan.TapPlan");
            var proc = TapProcessContainer.StartFromArgs("run verdictPlan.TapPlan");
            proc.WaitForEnd();
            Assert.AreEqual(0, proc.TapProcess.ExitCode);
        }
        
        
        [Test]
        public void TestUnbrowsableCliActionsHidden()
        {
            var proc = TapProcessContainer.StartFromArgs("package check-updates -h");
            proc.WaitForEnd();
            // The --startup option is unbrowsable and should not show up in the help text
            StringAssert.DoesNotContain("--startup", proc.ConsoleOutput);
        }
 
        [Test]
        public void TestProcessContainer()
        {
            var proc = TapProcessContainer.StartFromArgs("package list", TimeSpan.FromSeconds(100));
            proc.WaitForEnd();
            
            Assert.AreEqual(0, proc.TapProcess.ExitCode);
        }
 
        private string CreateCsvTestFile(string[] names, object[] values)
        {
            var newfile = "cliTestPass.csv";
            var delimiter = ",";
            if (!System.IO.File.Exists(newfile))
            {
                System.IO.File.Create(newfile).Close();
            }
            using (System.IO.TextWriter writer = System.IO.File.CreateText(newfile))
            {
                writer.WriteLine(string.Join(delimiter, "External Name", "Value"));
                for(var index = 0; index < names.Length; index++)
                {
                    writer.WriteLine(string.Join(delimiter, names[index], values[index]));
                }
            }
 
            return newfile;
        }
 
        [Test]
        public void TestPlanRunWithNullArgument()
        {
            // As ExpectedException has been removed from nunit 3, I will have a try-catch block to catch the ArgumentNullException
            bool argumentNullExceptionCaught = false;
            try
            {
                TestPlanRun testPlanRun = new TestPlanRun(null, null, DateTime.Now, 0);
            }
            catch(ArgumentNullException ex)
            {
                Assert.IsTrue(ex.Message.Contains("Value cannot be null") && ex.Message.Contains("Parameter") && ex.Message.Contains("plan"));
                argumentNullExceptionCaught = true;
            }
            
            Assert.IsTrue(argumentNullExceptionCaught, "ArgumentNullException was not thrown");
        }
    }
}