Browse Source

Adding lifetime test

Josh Engebretson 11 years ago
parent
commit
8cd25af4be

+ 55 - 0
UITests/Resources/Components/TestLifetime.js

@@ -0,0 +1,55 @@
+
+
+var windows = [];
+
+function loadUIWindows() {
+
+  for (var idx in windows) {
+
+    var window = windows[idx];
+
+    window.destroy();
+
+  }
+
+  windows = [];
+
+  var x = 5;
+
+  for (var i = 0; i < 10; i++, x += 260) {
+    var window = new Atomic.UIWindow();
+    window.load("UI/Test.ui.txt");
+    window.text = "Turbo Badger";
+    window.setSize(250, 630);
+    window.setPosition(x, 50);
+    windows.push(window);
+    TheView.addChild(window);
+  }
+
+}
+
+var deltaTime = 0;
+
+
+function start() {
+
+
+}
+
+function update(timeStep) {
+
+  deltaTime += timeStep;
+
+  if (deltaTime > .5) {
+
+    loadUIWindows();
+
+    MyAssert(Atomic.UI.debugGetWrappedWidgetCount() == 180);
+
+    // print ("# wrapped widgets ", Atomic.UI.debugGetWrappedWidgetCount());
+
+    deltaTime = 0;
+
+  }
+
+}

+ 7 - 1
UITests/Resources/Scripts/main.js

@@ -2,6 +2,9 @@
 
 require("AtomicGame");
 
+Atomic.script("utils.js");
+
+
 Atomic.game.init(start, update);
 
 // called at the start of play
@@ -12,8 +15,11 @@ function start() {
     // create a 2D scene
     game.createScene2D();
 
+    TheView = new Atomic.UIView();
+
     var uiNode = game.scene.createChild("UI");
-    uiNode.createJSComponent("UI");
+
+    uiNode.createJSComponent("TestLifetime");
 
 }
 

+ 6 - 0
UITests/Resources/Scripts/utils.js

@@ -0,0 +1,6 @@
+
+function MyAssert(value) {
+  if (!value) {
+    throw "Assert Failed";
+  }
+}