1 | /* |
---|
2 | Copyright (C) 2011-2013 Modelon AB |
---|
3 | |
---|
4 | This program is free software: you can redistribute it and/or modify |
---|
5 | it under the terms of the GNU General Public License as published by |
---|
6 | the Free Software Foundation, version 3 of the License. |
---|
7 | |
---|
8 | This program is distributed in the hope that it will be useful, |
---|
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 | GNU General Public License for more details. |
---|
12 | |
---|
13 | You should have received a copy of the GNU General Public License |
---|
14 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
15 | */ |
---|
16 | |
---|
17 | package CheckTests |
---|
18 | |
---|
19 | model InnerOuter1 |
---|
20 | partial model A |
---|
21 | Real x; |
---|
22 | end A; |
---|
23 | |
---|
24 | outer A a; |
---|
25 | equation |
---|
26 | a.x = true; // To generate another error to show up in an error check |
---|
27 | |
---|
28 | annotation(__JModelica(UnitTesting(tests={ |
---|
29 | ErrorTestCase( |
---|
30 | name="InnerOuter1", |
---|
31 | description="Check that error is not generated for partial outer without inner in check mode", |
---|
32 | checkType=check, |
---|
33 | errorMessage=" |
---|
34 | 1 errors found: |
---|
35 | |
---|
36 | Error at line 8, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', TYPE_MISMATCH_IN_EQUATION: |
---|
37 | The right and left expression types of equation are not compatible, type of left-hand side is Real, and type of right-hand side is Boolean |
---|
38 | ")}))); |
---|
39 | end InnerOuter1; |
---|
40 | |
---|
41 | |
---|
42 | model InnerOuter2 |
---|
43 | partial model A |
---|
44 | function f |
---|
45 | input Real x; |
---|
46 | output Real y; |
---|
47 | algorithm |
---|
48 | y := x + 1; |
---|
49 | end f; |
---|
50 | end A; |
---|
51 | |
---|
52 | outer A a; |
---|
53 | Real z = a.f(time); |
---|
54 | Real w = true; // To generate another error to show up in an error check |
---|
55 | |
---|
56 | annotation(__JModelica(UnitTesting(tests={ |
---|
57 | ErrorTestCase( |
---|
58 | name="InnerOuter2", |
---|
59 | description="Check that no extra errors are generated for function called through outer withour inner", |
---|
60 | checkType=check, |
---|
61 | errorMessage=" |
---|
62 | 1 errors found: |
---|
63 | |
---|
64 | Error at line 13, column 14, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH: |
---|
65 | The binding expression of the variable w does not match the declared type of the variable |
---|
66 | ")}))); |
---|
67 | end InnerOuter2; |
---|
68 | |
---|
69 | |
---|
70 | model InnerOuter3 |
---|
71 | model A |
---|
72 | outer Real x; |
---|
73 | end A; |
---|
74 | |
---|
75 | Real x; |
---|
76 | A a; |
---|
77 | Real w = true; // To generate another error to show up in an error check |
---|
78 | |
---|
79 | annotation(__JModelica(UnitTesting(tests={ |
---|
80 | ErrorTestCase( |
---|
81 | name="InnerOuter3", |
---|
82 | description="Check that error is not generated in check mode for outer without inner and component on top level with same name", |
---|
83 | checkType=check, |
---|
84 | errorMessage=" |
---|
85 | 1 errors found: |
---|
86 | |
---|
87 | Error at line 8, column 14, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH: |
---|
88 | The binding expression of the variable w does not match the declared type of the variable |
---|
89 | ")}))); |
---|
90 | end InnerOuter3; |
---|
91 | |
---|
92 | |
---|
93 | model InnerOuter4 |
---|
94 | model A |
---|
95 | outer Real x; |
---|
96 | end A; |
---|
97 | |
---|
98 | model B |
---|
99 | outer Integer x; |
---|
100 | end B; |
---|
101 | |
---|
102 | A a; |
---|
103 | B b; |
---|
104 | Real w = true; // To generate another error to show up in an error check |
---|
105 | |
---|
106 | annotation(__JModelica(UnitTesting(tests={ |
---|
107 | ErrorTestCase( |
---|
108 | name="InnerOuter4", |
---|
109 | description="Check that error is not generated for multiple outers without inner with same name but different types in check mode", |
---|
110 | checkType=check, |
---|
111 | errorMessage=" |
---|
112 | 1 errors found: |
---|
113 | |
---|
114 | Error at line 12, column 14, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH: |
---|
115 | The binding expression of the variable w does not match the declared type of the variable |
---|
116 | ")}))); |
---|
117 | end InnerOuter4; |
---|
118 | |
---|
119 | |
---|
120 | model InnerOuter5 |
---|
121 | model A |
---|
122 | outer Real x; |
---|
123 | equation |
---|
124 | x = time; |
---|
125 | end A; |
---|
126 | |
---|
127 | A a; |
---|
128 | parameter Real w; // To generate another warning to show up in an error check |
---|
129 | |
---|
130 | annotation(__JModelica(UnitTesting(tests={ |
---|
131 | WarningTestCase( |
---|
132 | name="InnerOuter5", |
---|
133 | description="Check that warning is not generated for outer without inner in check mode", |
---|
134 | checkType=check, |
---|
135 | errorMessage=" |
---|
136 | 1 errors found: |
---|
137 | |
---|
138 | Warning at line 9, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', PARAMETER_MISSING_BINDING_EXPRESSION: |
---|
139 | The parameter w does not have a binding expression |
---|
140 | ")}))); |
---|
141 | end InnerOuter5; |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | model ConditionalError1 |
---|
146 | model A |
---|
147 | Real x = true; |
---|
148 | end A; |
---|
149 | |
---|
150 | A a if b; |
---|
151 | parameter Boolean b = false; |
---|
152 | |
---|
153 | annotation(__JModelica(UnitTesting(tests={ |
---|
154 | ErrorTestCase( |
---|
155 | name="ConditionalError1", |
---|
156 | description="Check that errors in conditional components are found in check mode", |
---|
157 | checkType=check, |
---|
158 | errorMessage=" |
---|
159 | 1 errors found: |
---|
160 | |
---|
161 | Error at line 3, column 12, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH, |
---|
162 | In component a: |
---|
163 | The binding expression of the variable x does not match the declared type of the variable |
---|
164 | ")}))); |
---|
165 | end ConditionalError1; |
---|
166 | |
---|
167 | |
---|
168 | model ConditionalError2 |
---|
169 | model A |
---|
170 | Real x = true; |
---|
171 | end A; |
---|
172 | |
---|
173 | A a if b; |
---|
174 | parameter Boolean b = false; |
---|
175 | |
---|
176 | annotation(__JModelica(UnitTesting(tests={ |
---|
177 | FlatteningTestCase( |
---|
178 | name="ConditionalError2", |
---|
179 | description="Check that inactive conditional components aren't error checked in compile mode", |
---|
180 | flatModel=" |
---|
181 | fclass CheckTests.ConditionalError2 |
---|
182 | structural parameter Boolean b = false /* false */; |
---|
183 | end CheckTests.ConditionalError2; |
---|
184 | ")}))); |
---|
185 | end ConditionalError2; |
---|
186 | |
---|
187 | |
---|
188 | model ConditionalError3 |
---|
189 | type B = enumeration(c, d); |
---|
190 | |
---|
191 | function f |
---|
192 | input Real x; |
---|
193 | output Real y; |
---|
194 | algorithm |
---|
195 | y := x * x; |
---|
196 | end f; |
---|
197 | |
---|
198 | model A |
---|
199 | B x = if f(time) > 2 then B.c else B.d; |
---|
200 | end A; |
---|
201 | |
---|
202 | A a if b; |
---|
203 | parameter Boolean b = false; |
---|
204 | |
---|
205 | annotation(__JModelica(UnitTesting(tests={ |
---|
206 | FlatteningTestCase( |
---|
207 | name="ConditionalError3", |
---|
208 | description="Check that inactive conditional components aren't searched for used functions and enums when flattening in compile mode", |
---|
209 | flatModel=" |
---|
210 | fclass CheckTests.ConditionalError3 |
---|
211 | structural parameter Boolean b = false /* false */; |
---|
212 | end CheckTests.ConditionalError3; |
---|
213 | ")}))); |
---|
214 | end ConditionalError3; |
---|
215 | |
---|
216 | |
---|
217 | model ConditionalError4 |
---|
218 | model A |
---|
219 | Real x = true; |
---|
220 | end A; |
---|
221 | |
---|
222 | A a if b; |
---|
223 | parameter Boolean b = false; |
---|
224 | |
---|
225 | annotation(__JModelica(UnitTesting(tests={ |
---|
226 | ErrorTestCase( |
---|
227 | name="ConditionalError4", |
---|
228 | description="Check that errors in conditional components are found in compile mode when using the check_inactive_contitionals option", |
---|
229 | check_inactive_contitionals=true, |
---|
230 | errorMessage=" |
---|
231 | 1 errors found: |
---|
232 | |
---|
233 | Error at line 3, column 18, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH, |
---|
234 | In component a: |
---|
235 | The binding expression of the variable x does not match the declared type of the variable |
---|
236 | ")}))); |
---|
237 | end ConditionalError4; |
---|
238 | |
---|
239 | |
---|
240 | model ConditionalError5 |
---|
241 | model A |
---|
242 | parameter Integer n = 1; |
---|
243 | Real x[n] = (1:n) * time; |
---|
244 | Real y = x[1] + 1; |
---|
245 | end A; |
---|
246 | |
---|
247 | parameter Integer n = 0; |
---|
248 | A a(n=n) if n > 0; |
---|
249 | |
---|
250 | annotation(__JModelica(UnitTesting(tests={ |
---|
251 | FlatteningTestCase( |
---|
252 | name="ConditionalError5", |
---|
253 | description="Check that array bounds errors are allowed in disabled conditionals in check mode", |
---|
254 | checkType=check, |
---|
255 | flatModel=" |
---|
256 | fclass CheckTests.ConditionalError5 |
---|
257 | structural parameter Integer n = 0 /* 0 */; |
---|
258 | end CheckTests.ConditionalError5; |
---|
259 | ")}))); |
---|
260 | end ConditionalError5; |
---|
261 | |
---|
262 | model ConditionalError6 |
---|
263 | model A |
---|
264 | outer Real x; |
---|
265 | equation |
---|
266 | x = time; |
---|
267 | end A; |
---|
268 | |
---|
269 | A a; |
---|
270 | inner Real x if p; |
---|
271 | parameter Boolean p = false; |
---|
272 | |
---|
273 | annotation(__JModelica(UnitTesting(tests={ |
---|
274 | FlatteningTestCase( |
---|
275 | name="ConditionalError6", |
---|
276 | description="Conditional inner. This should probably give an error. See #4631.", |
---|
277 | checkType=check, |
---|
278 | flatModel=" |
---|
279 | fclass CheckTests.ConditionalError6 |
---|
280 | structural parameter Boolean p = false /* false */; |
---|
281 | equation |
---|
282 | x = time; |
---|
283 | end CheckTests.ConditionalError6; |
---|
284 | ")}))); |
---|
285 | end ConditionalError6; |
---|
286 | |
---|
287 | |
---|
288 | model ParamBinding1 |
---|
289 | type B = enumeration(a,b,c); |
---|
290 | model A |
---|
291 | parameter B b; |
---|
292 | Real x; |
---|
293 | parameter Real z[if b == B.b then 2 else 1] = ones(size(z,1)); |
---|
294 | equation |
---|
295 | if b == B.b then |
---|
296 | x = z[2]; |
---|
297 | else |
---|
298 | x = time; |
---|
299 | end if; |
---|
300 | end A; |
---|
301 | |
---|
302 | parameter B b2; |
---|
303 | A a(b = b2); |
---|
304 | Integer y = 1.2; // Generate an error to be able to use error test case |
---|
305 | |
---|
306 | annotation(__JModelica(UnitTesting(tests={ |
---|
307 | ComplianceErrorTestCase( |
---|
308 | name="ParamBinding1", |
---|
309 | description="Check that no error messages are generated for structural parameters without binding expression in check mode", |
---|
310 | checkType=check, |
---|
311 | errorMessage=" |
---|
312 | 1 errors found: |
---|
313 | |
---|
314 | Error at line 17, column 14, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH: |
---|
315 | The binding expression of the variable y does not match the declared type of the variable |
---|
316 | ")}))); |
---|
317 | end ParamBinding1; |
---|
318 | |
---|
319 | |
---|
320 | model ParamBinding2 |
---|
321 | replaceable function f |
---|
322 | input Real x; |
---|
323 | output real y; |
---|
324 | end f; |
---|
325 | |
---|
326 | constant Real p = f(1); |
---|
327 | Integer y = 1.2; // Generate an error to be able to use error test case |
---|
328 | |
---|
329 | annotation(__JModelica(UnitTesting(tests={ |
---|
330 | ComplianceErrorTestCase( |
---|
331 | name="ParamBinding2", |
---|
332 | description="Check that no error messages are generated for structural parameters that can't be evaluated in check mode", |
---|
333 | checkType=check, |
---|
334 | errorMessage=" |
---|
335 | 1 errors found: |
---|
336 | |
---|
337 | Error at line 8, column 17, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH: |
---|
338 | The binding expression of the variable y does not match the declared type of the variable |
---|
339 | ")}))); |
---|
340 | end ParamBinding2; |
---|
341 | |
---|
342 | |
---|
343 | model ArraySize1 |
---|
344 | parameter Integer n = size(x, 1); |
---|
345 | Real x[:]; |
---|
346 | Real y[n]; |
---|
347 | Real z[size(x, 1)]; |
---|
348 | |
---|
349 | Integer e = 1.2; // Generate an error to be able to use error test case |
---|
350 | |
---|
351 | annotation(__JModelica(UnitTesting(tests={ |
---|
352 | ComplianceErrorTestCase( |
---|
353 | name="ArraySize1", |
---|
354 | description="Check that no error message is generated for incomplete array size in check mode", |
---|
355 | checkType=check, |
---|
356 | errorMessage=" |
---|
357 | 1 errors found: |
---|
358 | |
---|
359 | Error at line 7, column 17, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH: |
---|
360 | The binding expression of the variable e does not match the declared type of the variable |
---|
361 | ")}))); |
---|
362 | end ArraySize1; |
---|
363 | |
---|
364 | model ArraySize2 |
---|
365 | function f |
---|
366 | input Integer n; |
---|
367 | input Integer[n] x; |
---|
368 | output Integer[n] y; |
---|
369 | algorithm |
---|
370 | for k in 1:n loop |
---|
371 | y[1:k] := y[1:k] + fill(x[k],k); |
---|
372 | end for; |
---|
373 | end f; |
---|
374 | model M |
---|
375 | constant Integer n = sum(f(1, {1})); |
---|
376 | constant Real[:] y1 = 1:n; |
---|
377 | end M; |
---|
378 | constant Real[:] c = m.y1; |
---|
379 | M m; |
---|
380 | annotation(__JModelica(UnitTesting(tests={ |
---|
381 | FlatteningTestCase( |
---|
382 | name="ArraySize2", |
---|
383 | description="Check that functions is error checked before evaluation", |
---|
384 | flatModel=" |
---|
385 | fclass CheckTests.ArraySize2 |
---|
386 | constant Real c[1] = {1}; |
---|
387 | constant Integer m.n = 1; |
---|
388 | constant Real m.y1[1] = {1}; |
---|
389 | |
---|
390 | public |
---|
391 | function CheckTests.ArraySize2.f |
---|
392 | input Integer n; |
---|
393 | input Integer[:] x; |
---|
394 | output Integer[:] y; |
---|
395 | algorithm |
---|
396 | assert(n == size(x, 1), \"Mismatching sizes in function 'CheckTests.ArraySize2.f', component 'x', dimension '1'\"); |
---|
397 | init y as Integer[n]; |
---|
398 | for k in 1:n loop |
---|
399 | y[1:k] := y[1:k] + fill(x[k], k); |
---|
400 | end for; |
---|
401 | return; |
---|
402 | end CheckTests.ArraySize2.f; |
---|
403 | |
---|
404 | end CheckTests.ArraySize2; |
---|
405 | ")}))); |
---|
406 | end ArraySize2; |
---|
407 | |
---|
408 | model FunctionNoAlgorithm1 |
---|
409 | replaceable function f |
---|
410 | input Real x; |
---|
411 | output Real y; |
---|
412 | end f; |
---|
413 | |
---|
414 | Real z = f(time); |
---|
415 | Integer y = 1.2; // Generate an error to be able to use error test case |
---|
416 | |
---|
417 | annotation(__JModelica(UnitTesting(tests={ |
---|
418 | ComplianceErrorTestCase( |
---|
419 | name="FunctionNoAlgorithm1", |
---|
420 | description="Check that no error message is generated replaceable incomplete function in check mode", |
---|
421 | checkType=check, |
---|
422 | errorMessage=" |
---|
423 | 1 errors found: |
---|
424 | |
---|
425 | Error at line 8, column 17, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH: |
---|
426 | The binding expression of the variable y does not match the declared type of the variable |
---|
427 | ")}))); |
---|
428 | end FunctionNoAlgorithm1; |
---|
429 | |
---|
430 | |
---|
431 | model FunctionNoAlgorithm2 |
---|
432 | replaceable package A |
---|
433 | function f |
---|
434 | input Real x; |
---|
435 | output Real y; |
---|
436 | end f; |
---|
437 | end A; |
---|
438 | |
---|
439 | Real z = A.f(time); |
---|
440 | Integer y = 1.2; // Generate an error to be able to use error test case |
---|
441 | |
---|
442 | annotation(__JModelica(UnitTesting(tests={ |
---|
443 | ComplianceErrorTestCase( |
---|
444 | name="FunctionNoAlgorithm2", |
---|
445 | description="Check that no error message is generated incomplete function in replaceable package in check mode", |
---|
446 | checkType=check, |
---|
447 | errorMessage=" |
---|
448 | 1 errors found: |
---|
449 | |
---|
450 | Error at line 10, column 17, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH: |
---|
451 | The binding expression of the variable y does not match the declared type of the variable |
---|
452 | ")}))); |
---|
453 | end FunctionNoAlgorithm2; |
---|
454 | |
---|
455 | |
---|
456 | model FunctionNoAlgorithm3 |
---|
457 | function f |
---|
458 | input Real x; |
---|
459 | output Real y; |
---|
460 | end f; |
---|
461 | |
---|
462 | Real z = f(time); |
---|
463 | |
---|
464 | annotation(__JModelica(UnitTesting(tests={ |
---|
465 | ComplianceErrorTestCase( |
---|
466 | name="FunctionNoAlgorithm3", |
---|
467 | description="Check that errors are generated for use of incomplete non-replaceable function in check mode", |
---|
468 | checkType=check, |
---|
469 | errorMessage=" |
---|
470 | 1 errors found: |
---|
471 | |
---|
472 | Error at line 7, column 14, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
473 | Calling function f(): can only call functions that have one algorithm section or external function specification |
---|
474 | ")}))); |
---|
475 | end FunctionNoAlgorithm3; |
---|
476 | |
---|
477 | |
---|
478 | model FunctionNoAlgorithm4 |
---|
479 | function f |
---|
480 | input Real x; |
---|
481 | output Real y; |
---|
482 | end f; |
---|
483 | |
---|
484 | function f2 = f3; |
---|
485 | |
---|
486 | replaceable function f3 = f; |
---|
487 | |
---|
488 | Real z = f2(time); |
---|
489 | Integer y = 1.2; // Generate an error to be able to use error test case |
---|
490 | |
---|
491 | annotation(__JModelica(UnitTesting(tests={ |
---|
492 | ErrorTestCase( |
---|
493 | name="FunctionNoAlgorithm4", |
---|
494 | description="", |
---|
495 | checkType=check, |
---|
496 | errorMessage=" |
---|
497 | 1 errors found: |
---|
498 | |
---|
499 | Error at line 12, column 17, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH: |
---|
500 | The binding expression of the variable y does not match the declared type of the variable |
---|
501 | ")}))); |
---|
502 | end FunctionNoAlgorithm4; |
---|
503 | |
---|
504 | |
---|
505 | model FunctionNoAlgorithm5 |
---|
506 | function f |
---|
507 | input Real x; |
---|
508 | output Real y; |
---|
509 | end f; |
---|
510 | |
---|
511 | model A |
---|
512 | replaceable function f2 = f; |
---|
513 | Real z = f2(time); |
---|
514 | end A; |
---|
515 | |
---|
516 | replaceable function f3 = f; |
---|
517 | |
---|
518 | A a(redeclare function f2 = f3); |
---|
519 | Integer y = 1.2; // Generate an error to be able to use error test case |
---|
520 | |
---|
521 | annotation(__JModelica(UnitTesting(tests={ |
---|
522 | ErrorTestCase( |
---|
523 | name="FunctionNoAlgorithm5", |
---|
524 | description="", |
---|
525 | checkType=check, |
---|
526 | errorMessage=" |
---|
527 | 1 errors found: |
---|
528 | |
---|
529 | Error at line 15, column 17, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH: |
---|
530 | The binding expression of the variable y does not match the declared type of the variable |
---|
531 | ")}))); |
---|
532 | end FunctionNoAlgorithm5; |
---|
533 | |
---|
534 | |
---|
535 | |
---|
536 | model IfEquationElse1 |
---|
537 | Real x; |
---|
538 | equation |
---|
539 | der(x) = time; |
---|
540 | if time > 1 then |
---|
541 | assert(time > 2, "msg"); |
---|
542 | else |
---|
543 | end if; |
---|
544 | when time > 2 then |
---|
545 | if time > 1 then |
---|
546 | reinit(x,1); |
---|
547 | else |
---|
548 | end if; |
---|
549 | end when; |
---|
550 | annotation(__JModelica(UnitTesting(tests={ |
---|
551 | TransformCanonicalTestCase( |
---|
552 | name="IfEquationElse1", |
---|
553 | description="Test empty else", |
---|
554 | flatModel=" |
---|
555 | fclass CheckTests.IfEquationElse1 |
---|
556 | Real x(stateSelect = StateSelect.always); |
---|
557 | discrete Boolean temp_1; |
---|
558 | initial equation |
---|
559 | x = 0.0; |
---|
560 | pre(temp_1) = false; |
---|
561 | equation |
---|
562 | der(x) = time; |
---|
563 | if time > 1 then |
---|
564 | assert(time > 2, \"msg\"); |
---|
565 | end if; |
---|
566 | temp_1 = time > 2; |
---|
567 | if temp_1 and not pre(temp_1) then |
---|
568 | if time > 1 then |
---|
569 | reinit(x, 1); |
---|
570 | end if; |
---|
571 | end if; |
---|
572 | |
---|
573 | public |
---|
574 | type StateSelect = enumeration(never \"Do not use as state at all.\", avoid \"Use as state, if it cannot be avoided (but only if variable appears differentiated and no other potential state with attribute default, prefer, or always can be selected).\", default \"Use as state if appropriate, but only if variable appears differentiated.\", prefer \"Prefer it as state over those having the default value (also variables can be selected, which do not appear differentiated).\", always \"Do use it as a state.\"); |
---|
575 | |
---|
576 | end CheckTests.IfEquationElse1; |
---|
577 | ")}))); |
---|
578 | end IfEquationElse1; |
---|
579 | |
---|
580 | model IfEquationElse2 |
---|
581 | Real x; |
---|
582 | equation |
---|
583 | der(x) = time; |
---|
584 | if time > 1 then |
---|
585 | assert(time > 2, "msg"); |
---|
586 | end if; |
---|
587 | when time > 2 then |
---|
588 | if time > 1 then |
---|
589 | reinit(x,1); |
---|
590 | end if; |
---|
591 | end when; |
---|
592 | annotation(__JModelica(UnitTesting(tests={ |
---|
593 | TransformCanonicalTestCase( |
---|
594 | name="IfEquationElse2", |
---|
595 | description="Test no else", |
---|
596 | flatModel=" |
---|
597 | fclass CheckTests.IfEquationElse2 |
---|
598 | Real x(stateSelect = StateSelect.always); |
---|
599 | discrete Boolean temp_1; |
---|
600 | initial equation |
---|
601 | x = 0.0; |
---|
602 | pre(temp_1) = false; |
---|
603 | equation |
---|
604 | der(x) = time; |
---|
605 | if time > 1 then |
---|
606 | assert(time > 2, \"msg\"); |
---|
607 | end if; |
---|
608 | temp_1 = time > 2; |
---|
609 | if temp_1 and not pre(temp_1) then |
---|
610 | if time > 1 then |
---|
611 | reinit(x, 1); |
---|
612 | end if; |
---|
613 | end if; |
---|
614 | |
---|
615 | public |
---|
616 | type StateSelect = enumeration(never \"Do not use as state at all.\", avoid \"Use as state, if it cannot be avoided (but only if variable appears differentiated and no other potential state with attribute default, prefer, or always can be selected).\", default \"Use as state if appropriate, but only if variable appears differentiated.\", prefer \"Prefer it as state over those having the default value (also variables can be selected, which do not appear differentiated).\", always \"Do use it as a state.\"); |
---|
617 | |
---|
618 | end CheckTests.IfEquationElse2; |
---|
619 | ")}))); |
---|
620 | end IfEquationElse2; |
---|
621 | |
---|
622 | model IfEquationElse3 |
---|
623 | Real x; |
---|
624 | equation |
---|
625 | if time > 2 then |
---|
626 | else |
---|
627 | assert(time < 2, "msg"); |
---|
628 | x = 1; |
---|
629 | end if; |
---|
630 | x = 2; |
---|
631 | |
---|
632 | annotation(__JModelica(UnitTesting(tests={ |
---|
633 | ErrorTestCase( |
---|
634 | name="IfEquationElse3", |
---|
635 | description="Check error for imbalanced else clause with empty if clause.", |
---|
636 | errorMessage=" |
---|
637 | 1 errors found: |
---|
638 | |
---|
639 | Error at line 4, column 3, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
640 | All branches in if equation with non-parameter tests must have the same number of equations |
---|
641 | ")}))); |
---|
642 | end IfEquationElse3; |
---|
643 | |
---|
644 | model BreakWithoutLoop |
---|
645 | Real[2] x; |
---|
646 | algorithm |
---|
647 | for i in 1:2 loop |
---|
648 | break; |
---|
649 | x[i] := i; |
---|
650 | end for; |
---|
651 | break; |
---|
652 | |
---|
653 | annotation(__JModelica(UnitTesting(tests={ |
---|
654 | ErrorTestCase( |
---|
655 | name="BreakWithoutLoop", |
---|
656 | description="Test errors for break statement without enclosing loop", |
---|
657 | errorMessage=" |
---|
658 | 1 errors found: |
---|
659 | |
---|
660 | Error at line 8, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
661 | Break statement must be inside while- or for-statement |
---|
662 | ")}))); |
---|
663 | end BreakWithoutLoop; |
---|
664 | |
---|
665 | model ComponentNameError1 |
---|
666 | model A |
---|
667 | Real x = true; |
---|
668 | end A; |
---|
669 | |
---|
670 | A a; |
---|
671 | |
---|
672 | annotation(__JModelica(UnitTesting(tests={ |
---|
673 | ErrorTestCase( |
---|
674 | name="ComponentNameError1", |
---|
675 | description="Check so that the option component_names_in_errors shows components names in errors", |
---|
676 | component_names_in_errors=true, |
---|
677 | errorMessage=" |
---|
678 | 1 errors found: |
---|
679 | |
---|
680 | Error at line 3, column 18, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH, |
---|
681 | In component a: |
---|
682 | The binding expression of the variable x does not match the declared type of the variable |
---|
683 | ")}))); |
---|
684 | end ComponentNameError1; |
---|
685 | |
---|
686 | model ComponentNameError2 |
---|
687 | model A |
---|
688 | Real x = true; |
---|
689 | end A; |
---|
690 | |
---|
691 | A a1; |
---|
692 | A a2; |
---|
693 | |
---|
694 | annotation(__JModelica(UnitTesting(tests={ |
---|
695 | ErrorTestCase( |
---|
696 | name="ComponentNameError2", |
---|
697 | description="Check so that the option component_names_in_errors shows components names in errors", |
---|
698 | component_names_in_errors=true, |
---|
699 | errorMessage=" |
---|
700 | 1 errors found: |
---|
701 | |
---|
702 | Error at line 3, column 18, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH, |
---|
703 | In components: |
---|
704 | a1 |
---|
705 | a2 |
---|
706 | The binding expression of the variable x does not match the declared type of the variable |
---|
707 | ")}))); |
---|
708 | end ComponentNameError2; |
---|
709 | |
---|
710 | model FilterWarnings1 |
---|
711 | parameter String s1; |
---|
712 | |
---|
713 | annotation(__JModelica(UnitTesting(tests={ |
---|
714 | WarningTestCase( |
---|
715 | name="FilterWarnings1", |
---|
716 | description="Check so that filtering of warnings works", |
---|
717 | filter_warnings="PARAMETER_MISSING_BINDING_EXPRESSION", |
---|
718 | errorMessage=" |
---|
719 | 1 warnings found: |
---|
720 | |
---|
721 | Warning in flattened model: |
---|
722 | 1 warning(s) has been ignored due to the 'filter_warnings' option |
---|
723 | ")}))); |
---|
724 | end FilterWarnings1; |
---|
725 | |
---|
726 | model FilterWarnings2 |
---|
727 | model A |
---|
728 | Real x(start=1) = 1; |
---|
729 | end A; |
---|
730 | |
---|
731 | model B |
---|
732 | extends A; |
---|
733 | Real x = 1; |
---|
734 | end B; |
---|
735 | |
---|
736 | B b; |
---|
737 | parameter String s1; |
---|
738 | |
---|
739 | annotation(__JModelica(UnitTesting(tests={ |
---|
740 | WarningTestCase( |
---|
741 | name="FilterWarnings2", |
---|
742 | description="Check so that filtering of multiple types of warnings works", |
---|
743 | filter_warnings="PARAMETER_MISSING_BINDING_EXPRESSION,UNABLE_TO_INFER_EQUALITY_FOR_DUPLICATES", |
---|
744 | errorMessage=" |
---|
745 | 1 warnings found: |
---|
746 | |
---|
747 | Warning in flattened model: |
---|
748 | 2 warning(s) has been ignored due to the 'filter_warnings' option |
---|
749 | ")}))); |
---|
750 | end FilterWarnings2; |
---|
751 | |
---|
752 | package ExtObj |
---|
753 | |
---|
754 | model ExtObjConstructor |
---|
755 | model EO |
---|
756 | extends ExternalObject; |
---|
757 | function constructor |
---|
758 | output EO o; |
---|
759 | external; |
---|
760 | end constructor; |
---|
761 | |
---|
762 | function destructor |
---|
763 | input EO o; |
---|
764 | external; |
---|
765 | end destructor; |
---|
766 | end EO; |
---|
767 | |
---|
768 | function wrap |
---|
769 | input EO eo1 = EO(); // EO default input not allowed |
---|
770 | output EO eo2 = EO(); // EO output not allowed |
---|
771 | protected |
---|
772 | EO eo3 = EO(); // Ok |
---|
773 | Real x1 = use(eo3); // Ok |
---|
774 | Real x2 = use(EO()); // Non-bound constructor not allowed |
---|
775 | algorithm |
---|
776 | end wrap; |
---|
777 | |
---|
778 | function use |
---|
779 | input EO eo; // Ok |
---|
780 | output Real x = 1; |
---|
781 | algorithm |
---|
782 | end use; |
---|
783 | |
---|
784 | EO eo1 = EO(); // Ok |
---|
785 | EO eo2 = wrap(); // Type error or error generated in wrap |
---|
786 | |
---|
787 | Real x1 = use(eo1); // Ok |
---|
788 | Real x2 = use(EO()); // Non-bound constructor not allowed |
---|
789 | |
---|
790 | annotation(__JModelica(UnitTesting(tests={ |
---|
791 | ErrorTestCase( |
---|
792 | name="ExtObjConstructor", |
---|
793 | description="Check that external object constructor is only allowed as binding expression", |
---|
794 | checkType="check", |
---|
795 | errorMessage=" |
---|
796 | 2 errors found: |
---|
797 | |
---|
798 | Error at line 21, column 21, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
799 | Constructors for external objects can only be used as binding expressions |
---|
800 | |
---|
801 | Error at line 35, column 17, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
802 | Constructors for external objects can only be used as binding expressions |
---|
803 | ")}))); |
---|
804 | end ExtObjConstructor; |
---|
805 | |
---|
806 | model ExtObjConstructor2 |
---|
807 | model X |
---|
808 | extends ExternalObject; |
---|
809 | function constructor |
---|
810 | output X x; |
---|
811 | external "C"; |
---|
812 | end constructor; |
---|
813 | function destructor |
---|
814 | input X x; |
---|
815 | external "C"; |
---|
816 | end destructor; |
---|
817 | end X; |
---|
818 | |
---|
819 | model X1 |
---|
820 | extends X; |
---|
821 | extends ExternalObject; |
---|
822 | end X1; |
---|
823 | |
---|
824 | parameter X x; |
---|
825 | |
---|
826 | annotation(__JModelica(UnitTesting(tests={ |
---|
827 | ErrorTestCase( |
---|
828 | name="ExtObjConstructor2", |
---|
829 | description="No external object binding expression", |
---|
830 | errorMessage=" |
---|
831 | 1 errors found: |
---|
832 | |
---|
833 | Error at line 19, column 5, in file '...', EXTERNAL_OBJECT_MISSING_BINDING_EXPRESSION: |
---|
834 | The external object 'x' does not have a binding expression |
---|
835 | ")}))); |
---|
836 | end ExtObjConstructor2; |
---|
837 | |
---|
838 | model ExtObjConstructor3 |
---|
839 | model X |
---|
840 | extends ExternalObject; |
---|
841 | function constructor |
---|
842 | output X x; |
---|
843 | external "C"; |
---|
844 | end constructor; |
---|
845 | function destructor |
---|
846 | input X x; |
---|
847 | external "C"; |
---|
848 | end destructor; |
---|
849 | end X; |
---|
850 | |
---|
851 | parameter X x; |
---|
852 | |
---|
853 | annotation(__JModelica(UnitTesting(tests={ |
---|
854 | WarningTestCase( |
---|
855 | name="ExtObjConstructor3", |
---|
856 | description="No external object binding expression, no error with check target", |
---|
857 | checkType="check", |
---|
858 | errorMessage=" |
---|
859 | Warning at line 14, column 5, in file '...', PARAMETER_MISSING_BINDING_EXPRESSION: |
---|
860 | The parameter x does not have a binding expression |
---|
861 | ")}))); |
---|
862 | end ExtObjConstructor3; |
---|
863 | |
---|
864 | end ExtObj; |
---|
865 | |
---|
866 | package Functional |
---|
867 | |
---|
868 | model PartialCall1 |
---|
869 | partial function partFunc |
---|
870 | input Real x; |
---|
871 | output Real y; |
---|
872 | end partFunc; |
---|
873 | |
---|
874 | function fullFunc |
---|
875 | extends partFunc; |
---|
876 | output Real y2; |
---|
877 | algorithm |
---|
878 | y := x*x; |
---|
879 | end fullFunc; |
---|
880 | |
---|
881 | function usePartFunc |
---|
882 | input partFunc pf; |
---|
883 | input Real x; |
---|
884 | output Real y; |
---|
885 | algorithm |
---|
886 | y := pf(x); |
---|
887 | end usePartFunc; |
---|
888 | |
---|
889 | Real y1 = usePartFunc(fullFunc(), time); |
---|
890 | |
---|
891 | annotation(__JModelica(UnitTesting(tests={ |
---|
892 | ErrorTestCase( |
---|
893 | name="Functional_PartialCall1", |
---|
894 | description="Check error when leaving out function key word", |
---|
895 | errorMessage=" |
---|
896 | 2 errors found: |
---|
897 | |
---|
898 | Error at line 22, column 27, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
899 | Calling function fullFunc(): missing argument for required input x |
---|
900 | |
---|
901 | Error at line 22, column 27, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
902 | Calling function usePartFunc(): types of positional argument 1 and input pf are not compatible |
---|
903 | type of 'fullFunc()' is Real |
---|
904 | expected type is ((Real y) = CheckTests.Functional.PartialCall1.partFunc(Real x)) |
---|
905 | ")}))); |
---|
906 | end PartialCall1; |
---|
907 | |
---|
908 | model PartialCall2 |
---|
909 | partial function partFunc |
---|
910 | input Real x; |
---|
911 | output Real y; |
---|
912 | end partFunc; |
---|
913 | |
---|
914 | function fullFunc |
---|
915 | extends partFunc; |
---|
916 | output Real y2; |
---|
917 | algorithm |
---|
918 | y := x*x; |
---|
919 | end fullFunc; |
---|
920 | |
---|
921 | function usePartFunc |
---|
922 | input partFunc pf; |
---|
923 | input Real x; |
---|
924 | output Real y; |
---|
925 | algorithm |
---|
926 | y := partFunc(x); |
---|
927 | end usePartFunc; |
---|
928 | |
---|
929 | Real y1 = usePartFunc(function fullFunc(), time) + partFunc(time); |
---|
930 | |
---|
931 | annotation(__JModelica(UnitTesting(tests={ |
---|
932 | ErrorTestCase( |
---|
933 | name="Functional_PartialCall2", |
---|
934 | description="Check error when calling partial function declaration directly", |
---|
935 | errorMessage=" |
---|
936 | 2 errors found: |
---|
937 | |
---|
938 | Error at line 19, column 14, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
939 | Calling function partFunc(): can only call functions that have one algorithm section or external function specification |
---|
940 | |
---|
941 | Error at line 22, column 56, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
942 | Calling function partFunc(): can only call functions that have one algorithm section or external function specification |
---|
943 | ")}))); |
---|
944 | end PartialCall2; |
---|
945 | |
---|
946 | model NumArgs1 |
---|
947 | partial function partFunc |
---|
948 | input Real x; |
---|
949 | output Real y; |
---|
950 | end partFunc; |
---|
951 | |
---|
952 | function fullFunc |
---|
953 | extends partFunc; |
---|
954 | input Real x2; |
---|
955 | output Real y2; |
---|
956 | algorithm |
---|
957 | y := x*x2; |
---|
958 | end fullFunc; |
---|
959 | |
---|
960 | function usePartFunc |
---|
961 | input partFunc pf; |
---|
962 | input Real x; |
---|
963 | output Real y; |
---|
964 | algorithm |
---|
965 | y := pf(x,x) + pf(); |
---|
966 | end usePartFunc; |
---|
967 | |
---|
968 | Real y1 = usePartFunc(function fullFunc(), time); |
---|
969 | Real y2 = usePartFunc(function fullFunc(x=y1,x2=y1), y1); |
---|
970 | |
---|
971 | annotation(__JModelica(UnitTesting(tests={ |
---|
972 | ErrorTestCase( |
---|
973 | name="Functional_NumArgs1", |
---|
974 | description="Check missing and extra arguments for functional inputs", |
---|
975 | errorMessage=" |
---|
976 | 4 errors found: |
---|
977 | |
---|
978 | Error at line 20, column 19, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
979 | Calling function pf(): too many positional arguments |
---|
980 | |
---|
981 | Error at line 20, column 24, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
982 | Calling function pf(): missing argument for required input x |
---|
983 | |
---|
984 | Error at line 23, column 27, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
985 | Creating functional input argument fullFunc(): missing argument for required input x2 |
---|
986 | |
---|
987 | Error at line 24, column 45, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
988 | Creating functional input argument fullFunc(): no input matching named argument x found |
---|
989 | ")}))); |
---|
990 | end NumArgs1; |
---|
991 | |
---|
992 | model Array1 |
---|
993 | partial function partFunc |
---|
994 | input Real x; |
---|
995 | output Real y; |
---|
996 | end partFunc; |
---|
997 | |
---|
998 | function fullFunc |
---|
999 | extends partFunc; |
---|
1000 | output Real y2; |
---|
1001 | algorithm |
---|
1002 | y := x*x; |
---|
1003 | end fullFunc; |
---|
1004 | |
---|
1005 | function usePartFunc |
---|
1006 | input partFunc[1] pf; |
---|
1007 | input Real x; |
---|
1008 | output Real y; |
---|
1009 | algorithm |
---|
1010 | y := pf(x); |
---|
1011 | end usePartFunc; |
---|
1012 | |
---|
1013 | Real y1 = usePartFunc({function fullFunc()}, time); |
---|
1014 | |
---|
1015 | annotation(__JModelica(UnitTesting(tests={ |
---|
1016 | ComplianceErrorTestCase( |
---|
1017 | name="Functional_Array1", |
---|
1018 | description="Check error when declaring as array", |
---|
1019 | errorMessage=" |
---|
1020 | 1 errors found: |
---|
1021 | |
---|
1022 | Compliance error at line 15, column 9, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', UNSUPPORTED_FUNCTIONAL_ARRAY_INPUT: |
---|
1023 | Arrays of functional input arguments is currently not supported |
---|
1024 | ")}))); |
---|
1025 | end Array1; |
---|
1026 | |
---|
1027 | model Bind1 |
---|
1028 | partial function partFunc |
---|
1029 | input Real x = 3; |
---|
1030 | output Real y; |
---|
1031 | end partFunc; |
---|
1032 | |
---|
1033 | function fullFunc |
---|
1034 | extends partFunc; |
---|
1035 | output Real y2; |
---|
1036 | algorithm |
---|
1037 | y := x*x; |
---|
1038 | end fullFunc; |
---|
1039 | |
---|
1040 | function usePartFunc |
---|
1041 | input partFunc pf; |
---|
1042 | input Real x; |
---|
1043 | output Real y; |
---|
1044 | algorithm |
---|
1045 | y := pf(x); |
---|
1046 | end usePartFunc; |
---|
1047 | |
---|
1048 | Real y1 = usePartFunc(function fullFunc(), time); |
---|
1049 | |
---|
1050 | annotation(__JModelica(UnitTesting(tests={ |
---|
1051 | ComplianceErrorTestCase( |
---|
1052 | name="Functional_Bind1", |
---|
1053 | description="Check error when having input default value", |
---|
1054 | errorMessage=" |
---|
1055 | 1 errors found: |
---|
1056 | |
---|
1057 | Compliance error at line 15, column 9, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', UNSUPPORTED_FUNCTIONAL_INPUT_FROM_FUNCTION_DEFAULT: |
---|
1058 | Creating functional input arguments from functions with default input arguments is currently not supported |
---|
1059 | ")}))); |
---|
1060 | end Bind1; |
---|
1061 | |
---|
1062 | model Bind2 |
---|
1063 | partial function partFunc |
---|
1064 | input Real x; |
---|
1065 | output Real y; |
---|
1066 | end partFunc; |
---|
1067 | |
---|
1068 | function fullFunc |
---|
1069 | extends partFunc; |
---|
1070 | output Real y2; |
---|
1071 | algorithm |
---|
1072 | y := x*x; |
---|
1073 | end fullFunc; |
---|
1074 | |
---|
1075 | function usePartFunc |
---|
1076 | input partFunc pf1 = 3; |
---|
1077 | input partFunc pf2 = fullFunc; |
---|
1078 | input partFunc pf3 = fullFunc; |
---|
1079 | input Real x; |
---|
1080 | output Real y; |
---|
1081 | algorithm |
---|
1082 | y := pf1(x); |
---|
1083 | end usePartFunc; |
---|
1084 | |
---|
1085 | Real y1 = usePartFunc(function fullFunc(), function fullFunc(), x=time); |
---|
1086 | |
---|
1087 | annotation(__JModelica(UnitTesting(tests={ |
---|
1088 | ComplianceErrorTestCase( |
---|
1089 | name="Functional_Bind2", |
---|
1090 | description="Check error when having input default value", |
---|
1091 | errorMessage=" |
---|
1092 | 6 errors found: |
---|
1093 | |
---|
1094 | Compliance error at line 15, column 9, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', UNSUPPORTED_FUNCTIONAL_INPUT_DEFAULT: |
---|
1095 | Default values of functional input arguments is currently not supported |
---|
1096 | |
---|
1097 | Error at line 15, column 30, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', BINDING_EXPRESSION_TYPE_MISMATCH: |
---|
1098 | The binding expression of the variable pf1 does not match the declared type of the variable |
---|
1099 | |
---|
1100 | Compliance error at line 16, column 9, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', UNSUPPORTED_FUNCTIONAL_INPUT_DEFAULT: |
---|
1101 | Default values of functional input arguments is currently not supported |
---|
1102 | |
---|
1103 | Error at line 16, column 30, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
1104 | Illegal access to class in expression: fullFunc |
---|
1105 | |
---|
1106 | Compliance error at line 17, column 9, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', UNSUPPORTED_FUNCTIONAL_INPUT_DEFAULT: |
---|
1107 | Default values of functional input arguments is currently not supported |
---|
1108 | |
---|
1109 | Error at line 17, column 30, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
1110 | Illegal access to class in expression: fullFunc |
---|
1111 | ")}))); |
---|
1112 | end Bind2; |
---|
1113 | |
---|
1114 | model Bind3 |
---|
1115 | record R |
---|
1116 | Real a; |
---|
1117 | end R; |
---|
1118 | |
---|
1119 | partial function partFunc |
---|
1120 | input R x1; |
---|
1121 | output Real y; |
---|
1122 | end partFunc; |
---|
1123 | |
---|
1124 | partial function partFunc2 |
---|
1125 | input Real[1] x1; |
---|
1126 | output Real y; |
---|
1127 | end partFunc2; |
---|
1128 | |
---|
1129 | function fullFunc |
---|
1130 | extends partFunc; |
---|
1131 | algorithm |
---|
1132 | y := x1.a; |
---|
1133 | end fullFunc; |
---|
1134 | |
---|
1135 | function fullFunc2 |
---|
1136 | extends partFunc2; |
---|
1137 | algorithm |
---|
1138 | y := x1[1]; |
---|
1139 | end fullFunc2; |
---|
1140 | |
---|
1141 | function usePartFunc |
---|
1142 | input partFunc pf; |
---|
1143 | input partFunc2 pf2; |
---|
1144 | output Real y; |
---|
1145 | algorithm |
---|
1146 | y := pf(R(1)) + pf2({1}); |
---|
1147 | end usePartFunc; |
---|
1148 | |
---|
1149 | Real y1 = usePartFunc(function fullFunc(),function fullFunc2()); |
---|
1150 | |
---|
1151 | annotation(__JModelica(UnitTesting(tests={ |
---|
1152 | ComplianceErrorTestCase( |
---|
1153 | name="Functional_Bind3", |
---|
1154 | description="Check error when having record or array input/output", |
---|
1155 | errorMessage=" |
---|
1156 | 2 errors found: |
---|
1157 | |
---|
1158 | Compliance error at line 29, column 9, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', UNSUPPORTED_FUNCTIONAL_INPUT_COMPOSITE: |
---|
1159 | Functional input arguments with record/array inputs/outputs is currently not supported |
---|
1160 | |
---|
1161 | Compliance error at line 30, column 9, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', UNSUPPORTED_FUNCTIONAL_INPUT_COMPOSITE: |
---|
1162 | Functional input arguments with record/array inputs/outputs is currently not supported |
---|
1163 | ")}))); |
---|
1164 | end Bind3; |
---|
1165 | |
---|
1166 | model Duplicate1 |
---|
1167 | partial function partFunc |
---|
1168 | output Real y; |
---|
1169 | end partFunc; |
---|
1170 | |
---|
1171 | function fullFunc |
---|
1172 | extends partFunc; |
---|
1173 | input Real x1; |
---|
1174 | input Real x1; |
---|
1175 | algorithm |
---|
1176 | y := x1; |
---|
1177 | end fullFunc; |
---|
1178 | |
---|
1179 | function usePartFunc |
---|
1180 | input partFunc pf; |
---|
1181 | output Real y; |
---|
1182 | algorithm |
---|
1183 | y := pf(); |
---|
1184 | end usePartFunc; |
---|
1185 | |
---|
1186 | Real y = usePartFunc(function fullFunc(x1=1, x1=2)); |
---|
1187 | |
---|
1188 | annotation(__JModelica(UnitTesting(tests={ |
---|
1189 | ComplianceErrorTestCase( |
---|
1190 | name="Functional_Duplicate1", |
---|
1191 | description="Check error with duplicates", |
---|
1192 | errorMessage=" |
---|
1193 | 2 errors found: |
---|
1194 | |
---|
1195 | Error at line 9, column 9, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
1196 | Duplicate component in same class: input Real x1 |
---|
1197 | |
---|
1198 | Error at line 21, column 26, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
1199 | Creating functional input argument fullFunc(): multiple arguments matches input x1 |
---|
1200 | ")}))); |
---|
1201 | end Duplicate1; |
---|
1202 | |
---|
1203 | model Vectorized1 |
---|
1204 | partial function partFunc |
---|
1205 | output Real y; |
---|
1206 | end partFunc; |
---|
1207 | |
---|
1208 | function fullFunc |
---|
1209 | extends partFunc; |
---|
1210 | input Real x1; |
---|
1211 | algorithm |
---|
1212 | y := x1; |
---|
1213 | end fullFunc; |
---|
1214 | |
---|
1215 | function usePartFunc |
---|
1216 | input partFunc pf; |
---|
1217 | output Real y; |
---|
1218 | algorithm |
---|
1219 | y := pf(); |
---|
1220 | end usePartFunc; |
---|
1221 | |
---|
1222 | Real[1] y = usePartFunc(function fullFunc(x1={1})); |
---|
1223 | |
---|
1224 | annotation(__JModelica(UnitTesting(tests={ |
---|
1225 | ComplianceErrorTestCase( |
---|
1226 | name="Functional_Vectorized1", |
---|
1227 | description="Check error with vectorized", |
---|
1228 | errorMessage=" |
---|
1229 | 1 errors found: |
---|
1230 | |
---|
1231 | Error at line 20, column 29, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
1232 | Calling function usePartFunc(): types of positional argument 1 and input pf are not compatible |
---|
1233 | type of 'fullFunc(x1={1})' is Real[1] |
---|
1234 | expected type is ((Real y) = CheckTests.Functional.Vectorized1.partFunc()) |
---|
1235 | ")}))); |
---|
1236 | end Vectorized1; |
---|
1237 | |
---|
1238 | end Functional; |
---|
1239 | |
---|
1240 | model FortranStrings |
---|
1241 | function f |
---|
1242 | input String sx; |
---|
1243 | input Real t; |
---|
1244 | output Real y; |
---|
1245 | external "FORTRAN 77"; |
---|
1246 | end f; |
---|
1247 | Real y; |
---|
1248 | Real[1] a; |
---|
1249 | equation |
---|
1250 | y = f("str",time); |
---|
1251 | a = Modelica.Math.Matrices.LAPACK.dgeev({{1}}); |
---|
1252 | |
---|
1253 | annotation(__JModelica(UnitTesting(tests={ |
---|
1254 | ErrorTestCase( |
---|
1255 | name="FortranStrings", |
---|
1256 | description="Check error for strings to fortran. Should not trigger for MSL lapack functions", |
---|
1257 | errorMessage=" |
---|
1258 | 1 errors found: |
---|
1259 | |
---|
1260 | Error at line 2, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
1261 | Passing strings to external fortran functions is not allowed |
---|
1262 | ")}))); |
---|
1263 | end FortranStrings; |
---|
1264 | |
---|
1265 | |
---|
1266 | model SpatialDist1 |
---|
1267 | Real x1,x2,x3,x4,x5,x6,x7; |
---|
1268 | equation |
---|
1269 | x1 = spatialDistribution(1, 2, 3, true, {9,9}); |
---|
1270 | x2 = spatialDistribution(1, 2, 3, true, initialPoints={9,9}); |
---|
1271 | x3 = spatialDistribution(1, 2, 3, true, initialValues={9,9}); |
---|
1272 | x4 = spatialDistribution(1, 2, 3, true, {9,9}, {9,9}); |
---|
1273 | x5 = spatialDistribution(1, 2, 3, true, {9,9}, initialValues={9,9}); |
---|
1274 | x6 = spatialDistribution(1, 2, 3, true, initialPoints={9,9}, initialValues={9,9}); |
---|
1275 | x7 = spatialDistribution(1, 2, 3, initialPoints={1,2}, initialValues={3,4}); |
---|
1276 | |
---|
1277 | annotation(__JModelica(UnitTesting(tests={ |
---|
1278 | ErrorTestCase( |
---|
1279 | name="SpatialDist1", |
---|
1280 | description="Check named arguments for spatialDistribution().", |
---|
1281 | errorMessage=" |
---|
1282 | 1 errors found: |
---|
1283 | |
---|
1284 | Error at line 10, column 10, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
1285 | Calling function spatialDistribution(): missing argument for required input positiveVelocity |
---|
1286 | ")}))); |
---|
1287 | end SpatialDist1; |
---|
1288 | |
---|
1289 | model FixedFalseIfEquTest1 |
---|
1290 | Real x; |
---|
1291 | parameter Boolean b(fixed=false); |
---|
1292 | initial equation |
---|
1293 | b = true; |
---|
1294 | equation |
---|
1295 | if b then |
---|
1296 | x = time; |
---|
1297 | else |
---|
1298 | x = 0; |
---|
1299 | end if; |
---|
1300 | |
---|
1301 | annotation(__JModelica(UnitTesting(tests={ |
---|
1302 | TransformCanonicalTestCase( |
---|
1303 | name="FixedFalseIfEquTest1", |
---|
1304 | description="Test that fixed false parameter if test in if equation is not marked as structural.", |
---|
1305 | flatModel=" |
---|
1306 | fclass CheckTests.FixedFalseIfEquTest1 |
---|
1307 | Real x; |
---|
1308 | initial parameter Boolean b(fixed = false); |
---|
1309 | initial equation |
---|
1310 | b = true; |
---|
1311 | equation |
---|
1312 | x = if b then time else 0; |
---|
1313 | end CheckTests.FixedFalseIfEquTest1; |
---|
1314 | |
---|
1315 | ")}))); |
---|
1316 | end FixedFalseIfEquTest1; |
---|
1317 | |
---|
1318 | model FixedFalseIndex1 |
---|
1319 | parameter Integer p(fixed=false); |
---|
1320 | Real xp; |
---|
1321 | Real[:] x = 1:2; |
---|
1322 | initial equation |
---|
1323 | p = 1; |
---|
1324 | equation |
---|
1325 | xp = x[p]; |
---|
1326 | |
---|
1327 | annotation(__JModelica(UnitTesting(tests={ |
---|
1328 | TransformCanonicalTestCase( |
---|
1329 | name="FixedFalseIndex1", |
---|
1330 | description="Test that fixed false parameter index is handled correctly", |
---|
1331 | flatModel=" |
---|
1332 | fclass CheckTests.FixedFalseIndex1 |
---|
1333 | initial parameter Integer p(fixed = false); |
---|
1334 | initial parameter Real xp; |
---|
1335 | constant Real x[1] = 1; |
---|
1336 | constant Real x[2] = 2; |
---|
1337 | initial equation |
---|
1338 | p = 1; |
---|
1339 | xp = ({1.0, 2.0})[p]; |
---|
1340 | end CheckTests.FixedFalseIndex1; |
---|
1341 | ")}))); |
---|
1342 | end FixedFalseIndex1; |
---|
1343 | |
---|
1344 | |
---|
1345 | model SizeInDisabled1 |
---|
1346 | parameter Integer n; |
---|
1347 | Real z[n] = 1:2 if n == 2; |
---|
1348 | |
---|
1349 | annotation(__JModelica(UnitTesting(tests={ |
---|
1350 | WarningTestCase( |
---|
1351 | name="SizeInDisabled1", |
---|
1352 | description="Test that check mode only gives warning for array length mismatch in declaration of disabled conditional", |
---|
1353 | checkType=check, |
---|
1354 | errorMessage=" |
---|
1355 | 2 errors found: |
---|
1356 | |
---|
1357 | Warning at line 2, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', PARAMETER_MISSING_BINDING_EXPRESSION: |
---|
1358 | The parameter n does not have a binding expression |
---|
1359 | |
---|
1360 | Warning at line 3, column 17, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', ARRAY_SIZE_MISMATCH_IN_DECLARATION: |
---|
1361 | Found error in disabled conditional: |
---|
1362 | Array size mismatch in declaration of z, size of declaration is [0] and size of binding expression is [2] |
---|
1363 | ")}))); |
---|
1364 | end SizeInDisabled1; |
---|
1365 | |
---|
1366 | |
---|
1367 | model SizeInDisabled2 |
---|
1368 | parameter Integer n; |
---|
1369 | Real z[n] = {1:2,3:4} if n == 2; |
---|
1370 | |
---|
1371 | annotation(__JModelica(UnitTesting(tests={ |
---|
1372 | WarningTestCase( |
---|
1373 | name="SizeInDisabled2", |
---|
1374 | description="Test that check mode gives error for mismatch in number of array dimensions in declaration of disabled conditional", |
---|
1375 | checkType=check, |
---|
1376 | errorMessage=" |
---|
1377 | 2 errors found: |
---|
1378 | |
---|
1379 | Error at line 3, column 17, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', ARRAY_SIZE_MISMATCH_IN_DECLARATION: |
---|
1380 | Array size mismatch in declaration of z, size of declaration is [0] and size of binding expression is [2, 2] |
---|
1381 | |
---|
1382 | Warning at line 2, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', PARAMETER_MISSING_BINDING_EXPRESSION: |
---|
1383 | The parameter n does not have a binding expression |
---|
1384 | ")}))); |
---|
1385 | end SizeInDisabled2; |
---|
1386 | |
---|
1387 | |
---|
1388 | model SizeInDisabled3 |
---|
1389 | model A |
---|
1390 | parameter Integer n; |
---|
1391 | Real x[n]; |
---|
1392 | Real y[n]; |
---|
1393 | equation |
---|
1394 | y = cat(1, {x[1]}, x[2:end] .- 1) .* x; |
---|
1395 | end A; |
---|
1396 | |
---|
1397 | parameter Integer n; |
---|
1398 | A a(n = n) if n > 0; |
---|
1399 | |
---|
1400 | annotation(__JModelica(UnitTesting(tests={ |
---|
1401 | WarningTestCase( |
---|
1402 | name="SizeInDisabled3", |
---|
1403 | description="Test that check mode only gives warning for mismatch in number of array dimensions inside disabled conditional", |
---|
1404 | checkType=check, |
---|
1405 | errorMessage=" |
---|
1406 | 2 errors found: |
---|
1407 | |
---|
1408 | Warning at line 7, column 13, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', TYPE_MISMATCH_IN_EXPRESSION, |
---|
1409 | In component a: |
---|
1410 | Found error in disabled conditional: |
---|
1411 | Type error in expression: cat(1, {x[1]}, x[2:end] .- 1) .* x |
---|
1412 | type of 'cat(1, {x[1]}, x[2:end] .- 1)' is Real[1] |
---|
1413 | type of 'x' is Real[0] |
---|
1414 | |
---|
1415 | Warning at line 10, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', PARAMETER_MISSING_BINDING_EXPRESSION: |
---|
1416 | The parameter n does not have a binding expression |
---|
1417 | ")}))); |
---|
1418 | end SizeInDisabled3; |
---|
1419 | |
---|
1420 | |
---|
1421 | model SizeInDisabled4 |
---|
1422 | model A |
---|
1423 | parameter Integer n; |
---|
1424 | Real x[n]; |
---|
1425 | Real y[n]; |
---|
1426 | equation |
---|
1427 | y = cat(1, {x[1]}, x[2:end] .- 1) .* { x, x }; |
---|
1428 | end A; |
---|
1429 | |
---|
1430 | parameter Integer n; |
---|
1431 | A a(n = n) if n > 0; |
---|
1432 | |
---|
1433 | annotation(__JModelica(UnitTesting(tests={ |
---|
1434 | WarningTestCase( |
---|
1435 | name="SizeInDisabled4", |
---|
1436 | description="Test that check mode gives error for mismatch in number of array dimensions inside disabled conditional", |
---|
1437 | checkType=check, |
---|
1438 | errorMessage=" |
---|
1439 | 2 errors found: |
---|
1440 | |
---|
1441 | Error at line 7, column 13, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', TYPE_MISMATCH_IN_EXPRESSION, |
---|
1442 | In component a: |
---|
1443 | Type error in expression: cat(1, {x[1]}, x[2:end] .- 1) .* {x, x} |
---|
1444 | type of 'cat(1, {x[1]}, x[2:end] .- 1)' is Real[1] |
---|
1445 | type of '{x, x}' is Real[2, 0] |
---|
1446 | |
---|
1447 | Warning at line 10, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', PARAMETER_MISSING_BINDING_EXPRESSION: |
---|
1448 | The parameter n does not have a binding expression |
---|
1449 | ")}))); |
---|
1450 | end SizeInDisabled4; |
---|
1451 | |
---|
1452 | model FortranRecord |
---|
1453 | record R |
---|
1454 | Real x; |
---|
1455 | end R; |
---|
1456 | |
---|
1457 | function f1 |
---|
1458 | input R r; |
---|
1459 | output R y; |
---|
1460 | external "FORTRAN 77"; |
---|
1461 | end f1; |
---|
1462 | |
---|
1463 | function f2 |
---|
1464 | input R r; |
---|
1465 | output R y; |
---|
1466 | external "FORTRAN 77" y = f2(r); |
---|
1467 | end f2; |
---|
1468 | |
---|
1469 | R r1 = f1(R(time)); |
---|
1470 | R r2 = f2(R(time)); |
---|
1471 | |
---|
1472 | annotation(__JModelica(UnitTesting(tests={ |
---|
1473 | WarningTestCase( |
---|
1474 | name="FortranRecord", |
---|
1475 | description="Error for record in fortran call", |
---|
1476 | checkType=check, |
---|
1477 | errorMessage=" |
---|
1478 | 2 errors found: |
---|
1479 | |
---|
1480 | Error at line 6, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
1481 | Passing records to external fortran functions is not allowed |
---|
1482 | |
---|
1483 | Error at line 12, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
1484 | Passing records to external fortran functions is not allowed |
---|
1485 | ")}))); |
---|
1486 | end FortranRecord; |
---|
1487 | |
---|
1488 | model ExternalRecordArray1 |
---|
1489 | record R1 |
---|
1490 | Real[1] x; |
---|
1491 | end R1; |
---|
1492 | |
---|
1493 | record R2 |
---|
1494 | R1 r; |
---|
1495 | end R2; |
---|
1496 | |
---|
1497 | function f2 |
---|
1498 | input R2 r; |
---|
1499 | output R2 y; |
---|
1500 | external "C" y = f2(r); |
---|
1501 | end f2; |
---|
1502 | |
---|
1503 | R2 r2 = f2(R2(R1({time}))); |
---|
1504 | |
---|
1505 | annotation(__JModelica(UnitTesting(tests={ |
---|
1506 | WarningTestCase( |
---|
1507 | name="ExternalRecordArray1", |
---|
1508 | description="Error for array in record in C call", |
---|
1509 | checkType=check, |
---|
1510 | errorMessage=" |
---|
1511 | 1 errors found: |
---|
1512 | |
---|
1513 | Error at line 10, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
1514 | Record type used as input or output to external function can only contain scalar record or scalar simple types |
---|
1515 | |
---|
1516 | Compliance error at line 10, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', UNSUPPORTED_EXTERNAL_FUNCTION_RECORD_RETURN_VALUE: |
---|
1517 | Using records as return value from external functions is not supported |
---|
1518 | |
---|
1519 | ")}))); |
---|
1520 | end ExternalRecordArray1; |
---|
1521 | |
---|
1522 | model ExternalRecordArray2 |
---|
1523 | record R |
---|
1524 | Real x; |
---|
1525 | end R; |
---|
1526 | |
---|
1527 | function f2 |
---|
1528 | input R[1] r; |
---|
1529 | output R[1] y; |
---|
1530 | external; |
---|
1531 | end f2; |
---|
1532 | |
---|
1533 | R[1] r = f2({R(time)}); |
---|
1534 | |
---|
1535 | annotation(__JModelica(UnitTesting(tests={ |
---|
1536 | WarningTestCase( |
---|
1537 | name="ExternalRecordArray2", |
---|
1538 | description="Error for record array in C call", |
---|
1539 | checkType=check, |
---|
1540 | errorMessage=" |
---|
1541 | 1 errors found: |
---|
1542 | |
---|
1543 | Error at line 6, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo': |
---|
1544 | Record type used as input or output to external function can only contain scalar record or scalar simple types |
---|
1545 | ")}))); |
---|
1546 | end ExternalRecordArray2; |
---|
1547 | |
---|
1548 | model NegativeFill1 |
---|
1549 | Real[2] y = cat(1,{1,2,3,4},fill(0.0, 2 - 4)); |
---|
1550 | |
---|
1551 | |
---|
1552 | annotation(__JModelica(UnitTesting(tests={ |
---|
1553 | ErrorTestCase( |
---|
1554 | name="NegativeFill1", |
---|
1555 | description="", |
---|
1556 | errorMessage=" |
---|
1557 | 1 errors found: |
---|
1558 | |
---|
1559 | Error at line 2, column 43, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', NEGATIVE_SIZE_FILL: |
---|
1560 | The dimension arguments of the fill() operator may not be negative |
---|
1561 | |
---|
1562 | ")}))); |
---|
1563 | end NegativeFill1; |
---|
1564 | |
---|
1565 | model NegativeFill2 |
---|
1566 | parameter Integer n = 2; |
---|
1567 | Real[n] y; |
---|
1568 | equation |
---|
1569 | if n > 1 then |
---|
1570 | y = cat(1,{time,time},fill(0.0, n - 2)); |
---|
1571 | elseif n == 1 then |
---|
1572 | y = {time}; |
---|
1573 | end if; |
---|
1574 | annotation(__JModelica(UnitTesting(tests={ |
---|
1575 | FlatteningTestCase( |
---|
1576 | name="NegativeFill2", |
---|
1577 | description="", |
---|
1578 | flatModel=" |
---|
1579 | fclass CheckTests.NegativeFill2 |
---|
1580 | structural parameter Integer n = 2 /* 2 */; |
---|
1581 | Real y[2]; |
---|
1582 | equation |
---|
1583 | if 2 > 1 then |
---|
1584 | y[1:2] = cat(1, {time, time}, fill(0.0, 2 - 2)); |
---|
1585 | elseif 2 == 1 then |
---|
1586 | y[1:2] = {time}; |
---|
1587 | end if; |
---|
1588 | end CheckTests.NegativeFill2; |
---|
1589 | ")}))); |
---|
1590 | end NegativeFill2; |
---|
1591 | |
---|
1592 | model FunctionOutputSize1 |
---|
1593 | function f |
---|
1594 | input Integer x; |
---|
1595 | output Integer[x] y1 = 1:x; |
---|
1596 | output Integer[x] y2 = 1:x; |
---|
1597 | algorithm |
---|
1598 | end f; |
---|
1599 | parameter Integer[:] x; |
---|
1600 | Real[1] y1; |
---|
1601 | Real[1] y2; |
---|
1602 | equation |
---|
1603 | (y1,y2) = f(size(x,1)); |
---|
1604 | annotation(__JModelica(UnitTesting(tests={ |
---|
1605 | WarningTestCase( |
---|
1606 | name="FunctionOutputSize1", |
---|
1607 | description="Check that error for function outputs does not trigger in inactive branch", |
---|
1608 | checkType=check, |
---|
1609 | errorMessage=" |
---|
1610 | 1 warnings found: |
---|
1611 | |
---|
1612 | Warning at line 8, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', PARAMETER_MISSING_BINDING_EXPRESSION: |
---|
1613 | The parameter x does not have a binding expression |
---|
1614 | |
---|
1615 | ")}))); |
---|
1616 | end FunctionOutputSize1; |
---|
1617 | |
---|
1618 | model UnknownSizeArrayIndexBounds1 |
---|
1619 | parameter Real[:] x; |
---|
1620 | Real y = x[1]; |
---|
1621 | annotation(__JModelica(UnitTesting(tests={ |
---|
1622 | WarningTestCase( |
---|
1623 | name="UnknownSizeArrayIndexBounds1", |
---|
1624 | description="", |
---|
1625 | checkType=check, |
---|
1626 | errorMessage=" |
---|
1627 | 1 warnings found: |
---|
1628 | |
---|
1629 | Warning at line 2, column 5, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', PARAMETER_MISSING_BINDING_EXPRESSION: |
---|
1630 | The parameter x does not have a binding expression |
---|
1631 | |
---|
1632 | ")}))); |
---|
1633 | end UnknownSizeArrayIndexBounds1; |
---|
1634 | |
---|
1635 | model ExternalFunctionAnnotation1 |
---|
1636 | function f |
---|
1637 | input Real x; |
---|
1638 | output Real y; |
---|
1639 | external "C" y = f(x); |
---|
1640 | annotation(Include="", IncludeDirectory="", Library="", LibraryDirectory="", LegalAnnotation=""); |
---|
1641 | end f; |
---|
1642 | |
---|
1643 | Real y = f(time); |
---|
1644 | annotation(__JModelica(UnitTesting(tests={ |
---|
1645 | WarningTestCase( |
---|
1646 | name="ExternalFunctionAnnotation1", |
---|
1647 | description="", |
---|
1648 | checkType=check, |
---|
1649 | errorMessage=" |
---|
1650 | 4 errors found: |
---|
1651 | |
---|
1652 | Error at line 6, column 20, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', EXTERNAL_FUNCTION_ANNOTATION: |
---|
1653 | External function annotations only allowed on external statement annotations. This annotation is attached to a class. There might be a semicolon you want to remove. |
---|
1654 | |
---|
1655 | Error at line 6, column 32, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', EXTERNAL_FUNCTION_ANNOTATION: |
---|
1656 | External function annotations only allowed on external statement annotations. This annotation is attached to a class. There might be a semicolon you want to remove. |
---|
1657 | |
---|
1658 | Error at line 6, column 53, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', EXTERNAL_FUNCTION_ANNOTATION: |
---|
1659 | External function annotations only allowed on external statement annotations. This annotation is attached to a class. There might be a semicolon you want to remove. |
---|
1660 | |
---|
1661 | Error at line 6, column 65, in file 'Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo', EXTERNAL_FUNCTION_ANNOTATION: |
---|
1662 | External function annotations only allowed on external statement annotations. This annotation is attached to a class. There might be a semicolon you want to remove. |
---|
1663 | |
---|
1664 | ")}))); |
---|
1665 | end ExternalFunctionAnnotation1; |
---|
1666 | |
---|
1667 | model NoAlgorithmEvaluation1 |
---|
1668 | partial function f |
---|
1669 | input Integer x; |
---|
1670 | output Integer y; |
---|
1671 | end f; |
---|
1672 | |
---|
1673 | parameter Integer n = f(1); |
---|
1674 | Real[n] x = 1:n; |
---|
1675 | annotation(__JModelica(UnitTesting(tests={ |
---|
1676 | WarningTestCase( |
---|
1677 | name="NoAlgorithmEvaluation1", |
---|
1678 | description="Test for null pointer in evaluation of partial function", |
---|
1679 | checkType=check, |
---|
1680 | errorMessage=" |
---|
1681 | Error at line 7, column 27, in file '...': |
---|
1682 | Calling function f(): can only call functions that have one algorithm section or external function specification |
---|
1683 | ")}))); |
---|
1684 | end NoAlgorithmEvaluation1; |
---|
1685 | |
---|
1686 | model FixedFalseString1 |
---|
1687 | parameter String s(fixed=false); |
---|
1688 | annotation(__JModelica(UnitTesting(tests={ |
---|
1689 | ErrorTestCase( |
---|
1690 | name="FixedFalseString1", |
---|
1691 | description="", |
---|
1692 | checkType=check, |
---|
1693 | errorMessage=" |
---|
1694 | Error at line 2, column 24, in file '...': |
---|
1695 | Cannot find component declaration for fixed |
---|
1696 | ")}))); |
---|
1697 | end FixedFalseString1; |
---|
1698 | |
---|
1699 | model SampleVariability1 |
---|
1700 | Integer i = integer(time); |
---|
1701 | equation |
---|
1702 | when (sample(i,0.1)) then |
---|
1703 | assert(i > 0, ""); |
---|
1704 | end when; |
---|
1705 | annotation(__JModelica(UnitTesting(tests={ |
---|
1706 | ErrorTestCase( |
---|
1707 | name="SampleVariability1", |
---|
1708 | description="", |
---|
1709 | checkType=check, |
---|
1710 | errorMessage=" |
---|
1711 | Error at line 4, column 22, in file '...', NON_PARAMETER_SAMPLE_ARGUMENTS: |
---|
1712 | Sample arguments need to be parameter expressions |
---|
1713 | ")}))); |
---|
1714 | end SampleVariability1; |
---|
1715 | |
---|
1716 | model SampleType1 |
---|
1717 | |
---|
1718 | equation |
---|
1719 | when (sample(true,0.1)) then |
---|
1720 | assert(1 > 0, ""); |
---|
1721 | end when; |
---|
1722 | annotation(__JModelica(UnitTesting(tests={ |
---|
1723 | ErrorTestCase( |
---|
1724 | name="SampleType1", |
---|
1725 | description="", |
---|
1726 | checkType=check, |
---|
1727 | errorMessage=" |
---|
1728 | Error at line 4, column 22, in file '...': |
---|
1729 | Calling function sample(): types of positional argument 1 and input start are not compatible |
---|
1730 | type of 'true' is Boolean |
---|
1731 | expected type is Real |
---|
1732 | ")}))); |
---|
1733 | end SampleType1; |
---|
1734 | |
---|
1735 | model SampleType2 |
---|
1736 | equation |
---|
1737 | when (sample({1.},0.1)) then |
---|
1738 | assert(1 > 0, ""); |
---|
1739 | end when; |
---|
1740 | annotation(__JModelica(UnitTesting(tests={ |
---|
1741 | ErrorTestCase( |
---|
1742 | name="SampleType2", |
---|
1743 | description="", |
---|
1744 | checkType=check, |
---|
1745 | errorMessage=" |
---|
1746 | Error at line 3, column 22, in file '...': |
---|
1747 | Calling function sample(): types of positional argument 1 and input start are not compatible |
---|
1748 | type of '{1.0}' is Real[1] |
---|
1749 | expected type is Real |
---|
1750 | ")}))); |
---|
1751 | end SampleType2; |
---|
1752 | |
---|
1753 | end CheckTests; |
---|