Remove ODL_STREAM variable from usage in SxpLib.robot
[integration/test.git] / csit / libraries / CompareStream.robot
1 *** Settings ***
2 Documentation     This Resource contains list of Keywords Set_Variable_If_At_Least*, Set_Variable_If_At_Most,
3 ...               Run_Keyword_If_At_Least*, Run_Keyword_If_At_Most*,
4 ...               Run_Keyword_If_More_Than*, Run_Keyword_If_Less_Than*,
5 ...               for comparison ${ODL_STREAM} to the given ${lower_bound},
6 ...               in order to replace ad-hoc conditional execution in suites.
7 Library           Collections
8 Library           String
9
10 *** Variables ***
11 &{Stream_dict}    hydrogen=${1}    stable-helium=${2}    stable-lithium=${3}    beryllium=${4}    boron=${5}    carbon=${6}    nitrogen=${7}
12
13 *** Keywords ***
14 Set_Variable_If_At_Least
15     [Arguments]    ${lower_bound}    ${value_if_true}    ${value_if_false}
16     [Documentation]    Compare ${lower_bound} to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at least ${lower_bound},
17     ...    return ${value_if_false} otherwise.
18     BuiltIn.Run_Keyword_And_Return    BuiltIn.Set_Variable_If    &{Stream_dict}[${ODL_STREAM}] >= &{Stream_dict}[${lower_bound}]    ${value_if_true}    ${value_if_false}
19
20 Set_Variable_If_At_Most
21     [Arguments]    ${upper_bound}    ${value_if_true}    ${value_if_false}
22     [Documentation]    Compare ${upper_bound} to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at most ${upper_bound},
23     ...    return ${value_if_false} otherwise.
24     BuiltIn.Run_Keyword_And_Return    BuiltIn.Set_Variable_If    &{Stream_dict}[${ODL_STREAM}] <= &{Stream_dict}[${upper_bound}]    ${value_if_true}    ${value_if_false}
25
26 Set_Variable_If_At_Least_Helium
27     [Arguments]    ${value_if_true}    ${value_if_false}
28     [Documentation]    Compare stable-helium to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at least stable-helium,
29     ...    return ${value_if_false} otherwise.
30     BuiltIn.Run_Keyword_And_Return    Set_Variable_If_At_Least    stable-helium    ${value_if_true}    ${value_if_false}
31
32 Set_Variable_If_At_Least_Lithium
33     [Arguments]    ${value_if_true}    ${value_if_false}
34     [Documentation]    Compare stable-lithium to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at least stable-lithium,
35     ...    return ${value_if_false} otherwise.
36     BuiltIn.Run_Keyword_And_Return    Set_Variable_If_At_Least    stable-lithium    ${value_if_true}    ${value_if_false}
37
38 Set_Variable_If_At_Least_Beryllium
39     [Arguments]    ${value_if_true}    ${value_if_false}
40     [Documentation]    Compare beryllium to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at least beryllium,
41     ...    return ${value_if_false} otherwise.
42     BuiltIn.Run_Keyword_And_Return    Set_Variable_If_At_Least    beryllium    ${value_if_true}    ${value_if_false}
43
44 Set_Variable_If_At_Least_Boron
45     [Arguments]    ${value_if_true}    ${value_if_false}
46     [Documentation]    Compare boron to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at least boron,
47     ...    return ${value_if_false} otherwise.
48     BuiltIn.Run_Keyword_And_Return    Set_Variable_If_At_Least    boron    ${value_if_true}    ${value_if_false}
49
50 Set_Variable_If_At_Least_Carbon
51     [Arguments]    ${value_if_true}    ${value_if_false}
52     [Documentation]    Compare carbon to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at least carbon,
53     ...    return ${value_if_false} otherwise.
54     BuiltIn.Run_Keyword_And_Return    Set_Variable_If_At_Least    carbon    ${value_if_true}    ${value_if_false}
55
56 Set_Variable_If_At_Most_Helium
57     [Arguments]    ${value_if_true}    ${value_if_false}
58     [Documentation]    Compare stable-helium to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at most stable-helium,
59     ...    return ${value_if_false} otherwise.
60     BuiltIn.Run_Keyword_And_Return    Set_Variable_If_At_Most    stable-helium    ${value_if_true}    ${value_if_false}
61
62 Set_Variable_If_At_Most_Lithium
63     [Arguments]    ${value_if_true}    ${value_if_false}
64     [Documentation]    Compare stable-lithium to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at most stable-lithium,
65     ...    return ${value_if_false} otherwise.
66     BuiltIn.Run_Keyword_And_Return    Set_Variable_If_At_Most    stable-lithium    ${value_if_true}    ${value_if_false}
67
68 Set_Variable_If_At_Most_Beryllium
69     [Arguments]    ${value_if_true}    ${value_if_false}
70     [Documentation]    Compare beryllium to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at most beryllium,
71     ...    return ${value_if_false} otherwise.
72     BuiltIn.Run_Keyword_And_Return    Set_Variable_If_At_Most    beryllium    ${value_if_true}    ${value_if_false}
73
74 Set_Variable_If_At_Most_Boron
75     [Arguments]    ${value_if_true}    ${value_if_false}
76     [Documentation]    Compare boron to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at most boron,
77     ...    return ${value_if_false} otherwise.
78     BuiltIn.Run_Keyword_And_Return    Set_Variable_If_At_Most    boron    ${value_if_true}    ${value_if_false}
79
80 Set_Variable_If_At_Most_Carbon
81     [Arguments]    ${value_if_true}    ${value_if_false}
82     [Documentation]    Compare carbon to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at most carbon,
83     ...    return ${value_if_false} otherwise.
84     BuiltIn.Run_Keyword_And_Return    Set_Variable_If_At_Most    carbon    ${value_if_true}    ${value_if_false}
85
86 CompareStream__Convert_Input
87     [Arguments]    @{arguments}
88     [Documentation]    Splits arguments into args and kwargs is used in Run_Keyword_If_At_Least_Else and Run_Keyword_If_At_Most_Else.
89     ...    The problem is, when the string contains =, but it is not a named argument (name=value). There can be many values containing =, but
90     ...    for sure it is present in xmls. If the string starts with "<" it will be treated as it is xml and splitting for
91     ...    name and value will not be executed.
92     ...    If named argument is passed into this kw, only string data are supported e.g. name=string. Complex variables such as lists or dictionaries
93     ...    are not supported.
94     ${args}    BuiltIn.Create_List
95     ${kwargs}    BuiltIn.Create_Dictionary
96     : FOR    ${arg}    IN    @{arguments}
97     \    ${removed}    String.Remove_String    ${arg}    \n    ${Space}    \t
98     \    ...    \r
99     \    ${splitted}    BuiltIn.Run_Keyword_If    "${removed[0]}" == "<"    BuiltIn.Create List    ${arg}
100     \    ...    ELSE    String.Split_String    ${arg}    separator==    max_split=1
101     \    ${len}    BuiltIn.Get_Length    ${splitted}
102     \    Run Keyword If    ${len}==1    Collections.Append_To_List    ${args}    @{splitted}[0]
103     \    ...    ELSE    Collections.Set_To_Dictionary    ${kwargs}    @{splitted}
104     BuiltIn.Return_From_Keyword    ${args}    ${kwargs}
105
106 Run_Keyword_If_At_Least
107     [Arguments]    ${lower_bound}    ${kw_name}    @{varargs}    &{kwargs}
108     [Documentation]    Compare ${lower_bound} to ${ODL_STREAM} and in case ${ODL_STREAM} is at least ${lower_bound},
109     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
110     BuiltIn.Run_Keyword_And_Return_If    &{Stream_dict}[${ODL_STREAM}] >= &{Stream_dict}[${lower_bound}]    ${kw_name}    @{varargs}    &{kwargs}
111
112 Run_Keyword_If_At_Least_Else
113     [Arguments]    ${lower_bound}    @{varargs}
114     [Documentation]    Compare ${lower_bound} to ${ODL_STREAM} and in case ${ODL_STREAM} is at least ${lower_bound},
115     ...    run keyword defined before ELSE statement otherwise run keyword defined after ELSE statement and return its value.
116     ${position}    Collections.Get_Index_From_List    ${varargs}    \ELSE
117     BuiltIn.Run_Keyword_If    "${position}" == "-1"    BuiltIn.Fail    Missing else statement in defined expresion
118     ${varargs_if}    Collections.Get_Slice_From_List    ${varargs}    0    ${position}
119     ${varargs_else}    Collections.Get_Slice_From_List    ${varargs}    ${position+1}
120     ${args_if}    ${kwargs_if}    CompareStream__Convert_Input    @{varargs_if}
121     ${args_else}    ${kwargs_else}    CompareStream__Convert_Input    @{varargs_else}
122     ${resp}    BuiltIn.Run_Keyword_If    &{Stream_dict}[${ODL_STREAM}] >= &{Stream_dict}[${lower_bound}]    @{args_if}    &{kwargs_if}
123     ...    ELSE    @{args_else}    &{kwargs_else}
124     [Return]    ${resp}
125
126 Run_Keyword_If_At_Most
127     [Arguments]    ${upper_bound}    ${kw_name}    @{varargs}    &{kwargs}
128     [Documentation]    Compare ${upper_bound} to ${ODL_STREAM} and in case ${ODL_STREAM} is at most ${upper_bound},
129     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
130     BuiltIn.Run_Keyword_And_Return_If    &{Stream_dict}[${ODL_STREAM}] <= &{Stream_dict}[${upper_bound}]    ${kw_name}    @{varargs}    &{kwargs}
131
132 Run_Keyword_If_At_Most_Else
133     [Arguments]    ${upper_bound}    @{varargs}
134     [Documentation]    Compare ${upper_bound} to ${ODL_STREAM} and in case ${ODL_STREAM} is at most ${upper_bound},
135     ...    run keyword defined before ELSE statement otherwise run keyword defined after ELSE statement and return its value.
136     ${position}    Collections.Get_Index_From_List    ${varargs}    \ELSE
137     BuiltIn.Run_Keyword_If    "${position}" == "-1"    BuiltIn.Fail    Missing else statement in defined expresion
138     ${varargs_if}    Collections.Get_Slice_From_List    ${varargs}    0    ${position}
139     ${varargs_else}    Collections.Get_Slice_From_List    ${varargs}    ${position+1}
140     ${args_if}    ${kwargs_if}    CompareStream__Convert_Input    @{varargs_if}
141     ${args_else}    ${kwargs_else}    CompareStream__Convert_Input    @{varargs_else}
142     ${resp}    BuiltIn.Run_Keyword_If    &{Stream_dict}[${ODL_STREAM}] >= &{Stream_dict}[${lower_bound}]    @{args_if}    &{kwargs_if}
143     ...    ELSE    @{args_else}    &{kwargs_else}
144     [Return]    ${resp}
145
146 Run_Keyword_If_More_Than
147     [Arguments]    ${lower_bound}    ${kw_name}    @{varargs}    &{kwargs}
148     [Documentation]    Compare ${lower_bound} to ${ODL_STREAM} and in case ${ODL_STREAM} is more than ${lower_bound},
149     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
150     BuiltIn.Run_Keyword_And_Return_If    &{Stream_dict}[${ODL_STREAM}] > &{Stream_dict}[${lower_bound}]    ${kw_name}    @{varargs}    &{kwargs}
151
152 Run_Keyword_If_Equals
153     [Arguments]    ${stream}    ${kw_name}    @{varargs}    &{kwargs}
154     [Documentation]    Compare ${stream} to ${ODL_STREAM} and in case ${ODL_STREAM} equals ${stream},
155     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
156     BuiltIn.Run_Keyword_And_Return_If    &{Stream_dict}[${ODL_STREAM}] == &{Stream_dict}[${stream}]    ${kw_name}    @{varargs}    &{kwargs}
157
158 Run_Keyword_If_Less_Than
159     [Arguments]    ${lower_bound}    ${kw_name}    @{varargs}    &{kwargs}
160     [Documentation]    Compare ${lower_bound} to ${ODL_STREAM} and in case ${ODL_STREAM} is less than ${lower_bound},
161     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
162     BuiltIn.Run_Keyword_And_Return_If    &{Stream_dict}[${ODL_STREAM}] < &{Stream_dict}[${lower_bound}]    ${kw_name}    @{varargs}    &{kwargs}
163
164 Run_Keyword_If_At_Least_Helium
165     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
166     [Documentation]    Compare stable-helium to ${ODL_STREAM} and in case ${ODL_STREAM} is at least stable-helium,
167     ...    run ${kw_name} @{varargs} &{kwargs} and return its value
168     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_At_Least    stable-helium    ${kw_name}    @{varargs}    &{kwargs}
169
170 Run_Keyword_If_At_Least_Lithium
171     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
172     [Documentation]    Compare stable-lithium to ${ODL_STREAM} and in case ${ODL_STREAM} is at least stable-lithium,
173     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
174     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_At_Least    stable-lithium    ${kw_name}    @{varargs}    &{kwargs}
175
176 Run_Keyword_If_At_Least_Beryllium
177     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
178     [Documentation]    Compare beryllium to ${ODL_STREAM} and in case ${ODL_STREAM} is at least beryllium,
179     ...    run ${kw_name} @{varargs} &{kwargs} and return its value
180     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_At_Least    beryllium    ${kw_name}    @{varargs}    &{kwargs}
181
182 Run_Keyword_If_At_Least_Boron
183     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
184     [Documentation]    Compare boron to ${ODL_STREAM} and in case ${ODL_STREAM} is at least boron,
185     ...    run ${kw_name} @{varargs} &{kwargs} and return its value
186     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_At_Least    boron    ${kw_name}    @{varargs}    &{kwargs}
187
188 Run_Keyword_If_At_Least_Carbon
189     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
190     [Documentation]    Compare carbon to ${ODL_STREAM} and in case ${ODL_STREAM} is at least carbon,
191     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
192     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_At_Least    carbon    ${kw_name}    @{varargs}    &{kwargs}
193
194 Run_Keyword_If_At_Most_Helium
195     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
196     [Documentation]    Compare stable-helium to ${ODL_STREAM} and in case ${ODL_STREAM} is at most stable-helium,
197     ...    run ${kw_name} @{varargs} &{kwargs} and return its value
198     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_At_Most    stable-helium    ${kw_name}    @{varargs}    &{kwargs}
199
200 Run_Keyword_If_At_Most_Lithium
201     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
202     [Documentation]    Compare stable-lithium to ${ODL_STREAM} and in case ${ODL_STREAM} is at most stable-lithium,
203     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
204     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_At_Most    stable-lithium    ${kw_name}    @{varargs}    &{kwargs}
205
206 Run_Keyword_If_At_Most_Beryllium
207     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
208     [Documentation]    Compare beryllium to ${ODL_STREAM} and in case ${ODL_STREAM} is at most beryllium,
209     ...    run ${kw_name} @{varargs} &{kwargs} and return its value
210     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_At_Most    beryllium    ${kw_name}    @{varargs}    &{kwargs}
211
212 Run_Keyword_If_At_Most_Boron
213     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
214     [Documentation]    Compare boron to ${ODL_STREAM} and in case ${ODL_STREAM} is at most boron,
215     ...    run ${kw_name} @{varargs} &{kwargs} and return its value
216     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_At_Most    boron    ${kw_name}    @{varargs}    &{kwargs}
217
218 Run_Keyword_If_At_Most_Carbon
219     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
220     [Documentation]    Compare carbon to ${ODL_STREAM} and in case ${ODL_STREAM} is at most carbon,
221     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
222     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_At_Most    carbon    ${kw_name}    @{varargs}    &{kwargs}
223
224 Run_Keyword_If_More_Than_Helium
225     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
226     [Documentation]    Compare stable-helium to ${ODL_STREAM} and in case ${ODL_STREAM} is more than stable-helium,
227     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
228     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_More_Than    stable-helium    ${kw_name}    @{varargs}    &{kwargs}
229
230 Run_Keyword_If_Less_Than_Helium
231     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
232     [Documentation]    Compare stable-helium to ${ODL_STREAM} and in case ${ODL_STREAM} is less than stable-helium,
233     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
234     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_Less_Than    stable-helium    ${kw_name}    @{varargs}    &{kwargs}
235
236 Run_Keyword_If_More_Than_Lithium
237     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
238     [Documentation]    Compare stable-lithium to ${ODL_STREAM} and in case ${ODL_STREAM} is more than stable-lithium,
239     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
240     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_More_Than    stable-lithium    ${kw_name}    @{varargs}    &{kwargs}
241
242 Run_Keyword_If_Less_Than_Lithium
243     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
244     [Documentation]    Compare stable-lithium to ${ODL_STREAM} and in case ${ODL_STREAM} is less than stable-lithium,
245     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
246     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_Less_Than    stable-lithium    ${kw_name}    @{varargs}    &{kwargs}
247
248 Run_Keyword_If_More_Than_Beryllium
249     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
250     [Documentation]    Compare beryllium to ${ODL_STREAM} and in case ${ODL_STREAM} is more than beryllium,
251     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
252     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_More_Than    beryllium    ${kw_name}    @{varargs}    &{kwargs}
253
254 Run_Keyword_If_Less_Than_Beryllium
255     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
256     [Documentation]    Compare beryllium to ${ODL_STREAM} and in case ${ODL_STREAM} is less than beryllium,
257     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
258     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_Less_Than    beryllium    ${kw_name}    @{varargs}    &{kwargs}
259
260 Run_Keyword_If_More_Than_Boron
261     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
262     [Documentation]    Compare boron to ${ODL_STREAM} and in case ${ODL_STREAM} is more than boron,
263     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
264     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_More_Than    boron    ${kw_name}    @{varargs}    &{kwargs}
265
266 Run_Keyword_If_Less_Than_Boron
267     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
268     [Documentation]    Compare boron to ${ODL_STREAM} and in case ${ODL_STREAM} is less than boron,
269     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
270     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_Less_Than    boron    ${kw_name}    @{varargs}    &{kwargs}
271
272 Run_Keyword_If_More_Than_Carbon
273     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
274     [Documentation]    Compare carbon to ${ODL_STREAM} and in case ${ODL_STREAM} is more than carbon,
275     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
276     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_More_Than    carbon    ${kw_name}    @{varargs}    &{kwargs}
277
278 Run_Keyword_If_Less_Than_Carbon
279     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
280     [Documentation]    Compare carbon to ${ODL_STREAM} and in case ${ODL_STREAM} is less than carbon,
281     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
282     BuiltIn.Run_Keyword_And_Return    Run_Keyword_If_Less_Than    carbon    ${kw_name}    @{varargs}    &{kwargs}