1/** 2 * @brief Unittest for actions 3 * Move it into the ui ufo script directory (/base/ufos/ui/), run the game, and run the command "ui_push unittest_action" 4 * Every thing must be green and it must not print any text or warning into the console. 5 */ 6 7window test_action_eventtest { 8 { 9 invis true 10 } 11 12 func onWindowOpened { 13 *cvar:test = 4 14 cmd "ui_pop" 15 } 16} 17 18window test_action 19{ 20 { 21 pos "100 100" 22 size "340 400" 23 dragbutton true 24 closebutton true 25 string "_Unittest setter" 26 bgcolor "0 0 0 1" 27 } 28 29 string commonTitle { 30 pos "20 40" 31 string "common" 32 } 33 34 string testCommon1 { 35 pos "20 60" 36 string "t1" 37 } 38 39 string testCommon2 { 40 pos "20 80" 41 string "t2" 42 } 43 44 string testCommon3 { 45 pos "20 100" 46 string "t3" 47 } 48 49 string testCommon4 { 50 pos "20 120" 51 string "t4" 52 } 53 54 string testCommon5 { 55 pos "20 140" 56 string "t5" 57 } 58 59 string testCommon6 { 60 pos "20 160" 61 string "t6" 62 } 63 64 string testCommon7 { 65 pos "20 180" 66 string "t7" 67 } 68 69 string testCommon8 { 70 pos "20 200" 71 string "t8" 72 } 73 74 string testCommon9 { 75 pos "20 220" 76 string "t9" 77 } 78 79 string listenerTitle { 80 pos "80 40" 81 string "listener" 82 } 83 84 string testListener1 { 85 pos "80 60" 86 string "t1" 87 } 88 89 string testListener2 { 90 pos "80 80" 91 string "t2" 92 } 93 94 string testListener3 { 95 pos "80 100" 96 string "t3" 97 } 98 99 string testListener4 { 100 pos "80 120" 101 string "t4" 102 } 103 104 string testListener5 { 105 pos "80 140" 106 string "t5" 107 } 108 109 string testListener6 { 110 pos "80 160" 111 string "t6" 112 } 113 114 string testListener7 { 115 pos "80 180" 116 string "t7" 117 } 118 119 string testListener8 { 120 pos "80 200" 121 string "t8" 122 } 123 124 string testListener9 { 125 pos "80 220" 126 string "t9" 127 } 128 129 string testListener10 { 130 pos "80 240" 131 string "t10" 132 } 133 134 string lackTitle { 135 pos "140 40" 136 string "lack" 137 } 138 139 string testLack1 { 140 pos "140 60" 141 string "t1" 142 invis true /** @todo we know it dont work... we need to fix it */ 143 } 144 145 string testLack2 { 146 pos "140 80" 147 string "t2" 148 invis true /** @todo we know it dont work... we need to fix it */ 149 } 150 151 string testLack3 { 152 pos "140 100" 153 string "t3" 154 invis true /** @todo we know it dont work... we need to fix it */ 155 } 156 157 // 158 // Common tests 159 // 160 161 func set0 { 162 *cvar:test = 0 163 } 164 165 func set1 { 166 *cvar:test = 1 167 } 168 169 func set2 { 170 *cvar:test = 2 171 } 172 173 confunc unittest_action_inject { 174 *cvar:test = <1> 175 } 176 177 spinner testFoo { 178 current *cvar:test_nodefoo 179 min 0 180 max 16 181 invis true 182 disabled false 183 onChange { *cvar:test = 2 } 184 } 185 186 confunc testActionInjection { 187 if ( *cvar:test == 2 ) { *node:root.testCommon4@color = "0 1 0 1" } 188 else { *node:root.testCommon4@color = "1 0 0 1" } 189 } 190 191 confunc testActionEvent { 192 if ( *cvar:test == 4 ) { *node:root.testCommon5@color = "0 1 0 1" } 193 else { *node:root.testCommon5@color = "1 0 0 1" } 194 } 195 196 // 197 // Common tests 198 // 199 200 func testCommon { 201 202 // func 203 204 call *node:root.set0 205 if ( *cvar:test == 0 ) { *node:root.testCommon1@color = "0 1 0 1" } 206 else { *node:root.testCommon1@color = "1 0 0 1" } 207 call *node:root.set1 208 if ( *cvar:test == 1 ) { *node:root.testCommon2@color = "0 1 0 1" } 209 else { *node:root.testCommon2@color = "1 0 0 1" } 210 211 // confunc 212 213 *cvar:test = 0 214 cmd "unittest_action_inject 2" 215 if ( *cvar:test == 0 ) { *node:root.testCommon3@color = "0 1 0 1" } 216 else { *node:root.testCommon3@color = "1 0 0 1" } 217 cmd "testActionInjection" 218 219 // node event 220 221 *node:root.testCommon5@color = "1 0 0 1" 222 cmd "ui_push test_action_eventtest" 223 cmd "testActionEvent" 224 225 *node:root.testCommon6@color = "1 0 0 1" 226 *node:root.testCommon7@color = "1 0 0 1" 227 *node:root.testFoo@onClick = { *node:root.testCommon6@color = "0 1 0 1" } 228 call *node:root.testFoo@onClick 229 *node:root.testFoo@onClick = { *node:root.testCommon7@color = "0 1 0 1" } 230 call *node:root.testFoo@onClick 231 232 *cvar:test = 1 233 while ( *cvar:test == 1 ) { 234 if ( *cvar:test == 1 ) { *node:root.testCommon8@color = "0 1 0 1" } 235 else { *node:root.testCommon8@color = "1 0 0 1" } 236 *cvar:test = 0 237 } 238 239 *cvar:test = 0 240 while ( *cvar:test < 3 ) { 241 // we dont use expression, to have no problem with it 242 if ( *cvar:test == 0 ) { *cvar:test = 1 } 243 elif ( *cvar:test == 1 ) { *cvar:test = 2 } 244 elif ( *cvar:test == 2 ) { *cvar:test = 3 } 245 elif ( *cvar:test == 3 ) { *cvar:test = 4 } 246 } 247 if ( *cvar:test == 3 ) { *node:root.testCommon9@color = "0 1 0 1" } 248 else { *node:root.testCommon9@color = "1 0 0 1" } 249 } 250 251 // 252 // Listener tests 253 // 254 255 button sender1 { invis true onClick { *node:root.testListener1@color = "0 1 0 1" } } 256 func listener1 { *node:root.testListener2@color = "0 1 0 1" } 257 258 button sender2 { invis true onClick { *node:root.testListener3@color = "0 1 0 1" } } 259 func listener2 { *node:root.testListener4@color = "1 0 0 1" } 260 261 button sender3 { invis true onClick { *node:root.testListener5@color = "0 1 0 1" } } 262 func listener3_1 { *node:root.testListener6@color = "0 1 0 1" } 263 func listener3_2 { *node:root.testListener7@color = "0 1 0 1" } 264 265 button sender4 { invis true onClick { *node:root.testListener8@color = "0 1 0 1" } } 266 func listener4_1 { *node:root.testListener9@color = "1 0 0 1" } 267 func listener4_2 { *node:root.testListener10@color = "0 1 0 1" } 268 269 func testListenerSetUp { 270 // one listener 271 cmd "ui_addlistener <path:root>.sender1@onClick <path:root>.listener1" 272 273 // no listener 274 cmd "ui_addlistener <path:root>.sender2@onClick <path:root>.listener2" 275 cmd "ui_removelistener <path:root>.sender2@onClick <path:root>.listener2" 276 277 // two listener 278 cmd "ui_addlistener <path:root>.sender3@onClick <path:root>.listener3_1" 279 cmd "ui_addlistener <path:root>.sender3@onClick <path:root>.listener3_2" 280 281 // one listener 282 cmd "ui_addlistener <path:root>.sender4@onClick <path:root>.listener4_1" 283 cmd "ui_addlistener <path:root>.sender4@onClick <path:root>.listener4_2" 284 cmd "ui_removelistener <path:root>.sender4@onClick <path:root>.listener4_1" 285 } 286 287 confunc testListenerTest { 288 // one listener 289 call *node:root.sender1@onClick 290 291 // no listener 292 *node:root.testListener4@color = "0 1 0 1" 293 call *node:root.sender2@onClick 294 295 // two listener 296 call *node:root.sender3@onClick 297 298 // one listener 299 *node:root.testListener9@color = "0 1 0 1" 300 call *node:root.sender4@onClick 301 302 // clean up 303 cmd "testListenerTearDown" 304 } 305 306 confunc testListenerTearDown { 307 // one listener 308 cmd "ui_removelistener <path:root>.sender1@onClick <path:root>.listener1" 309 310 // no listener 311 312 // two listener 313 cmd "ui_removelistener <path:root>.sender3@onClick <path:root>.listener3_1" 314 cmd "ui_removelistener <path:root>.sender3@onClick <path:root>.listener3_2" 315 316 // one listener 317 cmd "ui_removelistener <path:root>.sender4@onClick <path:root>.listener4_2" 318 } 319 320 func testListener { 321 call *node:root.testListenerSetUp 322 cmd "testListenerTest" 323 } 324 325 // 326 // Lack tests 327 // thing dont work 328 // 329 330 func testLack { 331 // @todo 332 333 // 1) use mixture of anonymous setter and listener should not work 334 // (can be a right behaviour) 335 336 // 1-1) add a listener can change an already set anonymous function 337 *node:root.testLack1@color = "1 0 0 1" 338 339 // 1-2) set an anonymous function will remove an existing listener 340 *node:root.testLack2@color = "1 0 0 1" 341 342 // 2) listener into an inherited event should also change the super event 343 // (wrong behaviour) 344 *node:root.testLack3@color = "1 0 0 1" 345 } 346 347 // 348 // Main 349 // 350 351 func onWindowOpened { 352 call *node:root.testCommon 353 call *node:root.testListener 354 call *node:root.testLack 355 } 356 357} 358