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
//            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 System.ComponentModel;
using System.IO;
using System.Threading;
using NUnit.Framework;
 
namespace OpenTap.Engine.UnitTests
{
    [TestFixture]
    public class UserInputTest : IUserInputInterface
    {
        public void RequestUserInput(object dataObject, TimeSpan Timeout, bool modal)
        {
            
        }
 
        public class TestObject
        {
            public int X { get; set; }
        }
        [Test]
        [Ignore("Intermitantly fails on CI runners")]
        public void TestValuesExtremes()
        {
            var prev = UserInput.GetInterface();
            try
            {
                CliUserInputInterface.Load();
                TestObject obj = new TestObject();
                var sem = new SemaphoreSlim(0);
                bool exceptionHappened = false;
                try
                {
                    UserInput.Request(obj, TimeSpan.Zero, true); // should return immediately.
                    Assert.Fail("Timeout exception should have been thrown");
                }
                catch (TimeoutException)
                {
 
                }
                var trd = TapThread.Start(() =>
                {
                    try
                    {
                        UserInput.Request(obj, TimeSpan.MaxValue, true);
                    }
                    catch(OperationCanceledException)
                    {
                        exceptionHappened = true;
                    }
 
                    sem.Release();                    
                });
                trd.Abort();
                if (!sem.Wait(1000) || exceptionHappened == false)
                    Assert.Fail("Should have been canceled by thread");
            }
            finally
            {
                UserInput.SetInterface(prev);
            }
        }
 
        [Test]
        public void TestUserInputOrder()
        {
            using (Session.Create())
            {
                CliUserInputInterface.Load();
                var request = new TestRequest();
                using (var writer = new StringWriter())
                {
                    var prevOut = Console.Out;
                    try
                    {
                        Console.SetOut(writer);
                        UserInput.Request(request);
 
                        var log = writer.ToString()
                            .Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i <= 6; i++)
                            Assert.IsTrue(log[i].EndsWith(i.ToString()));
                    }
                    finally
                    {
                        Console.SetOut(prevOut);
                    }
                }
            }
        }
    }
    
    public class TestRequest
    {
        [Display("g", Order: 2)]
        [Submit]
        [Browsable(true)]
        public string g { get; }
        
        [Display("e", Order: 2)]
        [Layout(LayoutMode.FloatBottom)]
        [Browsable(true)]
        public string e { get; }
        
        [Display("d", Order: 2)]
        [Browsable(true)]
        public string d { get; }
        
        [Display("c", Order: 3)]
        [Browsable(true)]
        public string c { get; }
        
        [Display("b", Order: 2)]
        [Browsable(true)]
        public string b { get; }
        
        [Display("a", Order: 1)]
        [Browsable(true)]
        public string a { get; }
 
        [Browsable(true)]
        public string f { get; }
        
        public TestRequest()
        {
            f = "0";
            a = "1";
            b = "2";
            d = "3";
            c = "4";
            e = "5";
            g = "6";
        }
    }
}