| 1 |
# AltitudeTrigger unit tests |
| 2 |
# |
| 3 |
# Copyright (C) 2014 Anton Gomez Alvedro |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or |
| 6 |
# modify it under the terms of the GNU General Public License as |
| 7 |
# published by the Free Software Foundation; either version 2 of the |
| 8 |
# License, or (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
# General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program; if not, write to the Free Software |
| 17 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 |
|
| 19 |
io.include("Aircraft/Generic/Systems/Tests/test.nas"); |
| 20 |
io.include("Aircraft/Generic/Systems/failures.nas"); |
| 21 |
|
| 22 |
var TestFailureMode = { |
| 23 |
|
| 24 |
parents: [TestSuite], |
| 25 |
|
| 26 |
setup: func { |
| 27 |
props.globals.initNode("/test"); |
| 28 |
}, |
| 29 |
|
| 30 |
cleanup: func { |
| 31 |
me.mode = nil; |
| 32 |
props.globals.getNode("/test").remove(); |
| 33 |
}, |
| 34 |
|
| 35 |
test_binding: func { |
| 36 |
var actuator = { parents: [FailureMgr.FailureActuator] }; |
| 37 |
setprop("/test/foreign-property", 25); |
| 38 |
|
| 39 |
me.mode = FailureMgr.FailureMode.new( |
| 40 |
id: "instruments/compass", |
| 41 |
description: "a description", |
| 42 |
actuator: actuator); |
| 43 |
|
| 44 |
me.mode.bind("/test/"); |
| 45 |
assert_prop_exists("/test/instruments/compass/failure-level"); |
| 46 |
|
| 47 |
me.mode.unbind(); |
| 48 |
fail_if_prop_exists("/test/instruments/compass/failure-level"); |
| 49 |
fail_if_prop_exists("/test/instruments/compass"); |
| 50 |
assert_prop_exists("/test/foreign-property"); |
| 51 |
}, |
| 52 |
|
| 53 |
test_set_failure_level_calls_actuator: func { |
| 54 |
var level = 0; |
| 55 |
var actuator = { |
| 56 |
parents: [FailureMgr.FailureActuator], |
| 57 |
set_failure_level: func (l) { level = l }, |
| 58 |
}; |
| 59 |
|
| 60 |
me.mode = FailureMgr.FailureMode.new( |
| 61 |
id: "instruments/compass", |
| 62 |
description: "a description", |
| 63 |
actuator: actuator); |
| 64 |
me.mode.bind("/test/"); |
| 65 |
|
| 66 |
me.mode.set_failure_level(1); |
| 67 |
assert(level == 1); |
| 68 |
}, |
| 69 |
|
| 70 |
test_actuator_gets_called_from_prop: func { |
| 71 |
var level = 0; |
| 72 |
var actuator = { |
| 73 |
parents: [FailureMgr.FailureActuator], |
| 74 |
set_failure_level: func (l) { level = l }, |
| 75 |
}; |
| 76 |
|
| 77 |
me.mode = FailureMgr.FailureMode.new( |
| 78 |
id: "instruments/compass", |
| 79 |
description: "a description", |
| 80 |
actuator: actuator); |
| 81 |
|
| 82 |
me.mode.bind("/test/"); |
| 83 |
setprop("/test/instruments/compass/failure-level", 1); |
| 84 |
assert(level == 1); |
| 85 |
}, |
| 86 |
|
| 87 |
test_setting_level_from_nasal_is_shown_in_prop: func { |
| 88 |
var level = 0; |
| 89 |
var actuator = { |
| 90 |
parents: [FailureMgr.FailureActuator], |
| 91 |
set_failure_level: func (l) { level = l }, |
| 92 |
}; |
| 93 |
|
| 94 |
me.mode = FailureMgr.FailureMode.new( |
| 95 |
id: "instruments/compass", |
| 96 |
description: "a description", |
| 97 |
actuator: actuator); |
| 98 |
|
| 99 |
me.mode.bind("/test/"); |
| 100 |
|
| 101 |
me.mode.set_failure_level(1); |
| 102 |
assert(level == 1); |
| 103 |
|
| 104 |
var prop_value = getprop("/test/instruments/compass/failure-level"); |
| 105 |
assert(prop_value == 1); |
| 106 |
|
| 107 |
me.mode.set_failure_level(0.5); |
| 108 |
assert(level == 0.5); |
| 109 |
|
| 110 |
prop_value = getprop("/test/instruments/compass/failure-level"); |
| 111 |
assert(prop_value == 0.5); |
| 112 |
} |
| 113 |
}; |