Browse Source

Adding some button tests

Josh Engebretson 10 years ago
parent
commit
d42b400d86

+ 76 - 0
UITests/Resources/Components/TestButtons.js

@@ -0,0 +1,76 @@
+
+
+var deltaTime = 0;
+
+var buttonClicked = null;
+var widgetClicked = false;
+
+
+function start() {
+
+  // will go out of scope,  however will be held while the
+  // button is in a UI heirarchy
+
+  var widget = new Atomic.UIWidget();
+  widget.setSize(256, 256);
+  TheView.addChild(widget);
+
+  var button = new Atomic.UIButton();
+  button.text = "Click Me To Destroy";
+  button.setSize(256, 256);
+  widget.addChild(button);
+
+  widget.onClick = function() {
+    widgetClicked = true;
+    print ("Error: Widget on Click!");
+  }
+
+
+  button.onClick = function() {
+
+    print ("Button on Click!");
+
+    // can't destroy the button in it's own callback
+    buttonClicked = button;
+
+    // returning true signals the event was handled and  stops event bubble
+    // so parent widget should not get event
+    return true;
+  }
+
+}
+
+function update(timeStep) {
+
+  if (buttonClicked) {
+
+    buttonClicked.parent.destroy();
+
+    try {
+
+      // widget onClicked handler should not have been called
+      MyAssert(!widgetClicked);
+
+      // just the view should be alive
+      MyAssert(Atomic.UI.debugGetWrappedWidgetCount() == 1);
+      MyAssert(Atomic.UI.debugGetUIKeepAliveCount() == Atomic.UI.debugGetWrappedWidgetCount());
+
+    } catch (e) {
+
+      print (e);
+
+    }
+
+    buttonClicked = null;
+
+  }
+
+  deltaTime += timeStep;
+
+  if (deltaTime > .5) {
+
+    deltaTime = 0;
+
+  }
+
+}

+ 12 - 4
UITests/Resources/Components/TestLifetime.js

@@ -17,12 +17,13 @@ function loadUIWindows() {
   var x = 5;
 
   for (var i = 0; i < 10; i++, x += 260) {
+
     var window = new Atomic.UIWindow();
-    window.load("UI/Test.ui.txt");
+    windows.push(window);
+    window.load("UI/TestLifetime.ui.txt");
     window.text = "Turbo Badger";
     window.setSize(250, 630);
     window.setPosition(x, 50);
-    windows.push(window);
     TheView.addChild(window);
   }
 
@@ -44,9 +45,16 @@ function update(timeStep) {
 
     loadUIWindows();
 
-    MyAssert(Atomic.UI.debugGetWrappedWidgetCount() == 180);
+    try {
+
+      MyAssert(Atomic.UI.debugGetWrappedWidgetCount() == 191);
+      MyAssert(Atomic.UI.debugGetUIKeepAliveCount() == Atomic.UI.debugGetWrappedWidgetCount());
+
+    } catch (e) {
+
+      print (e);
 
-    // print ("# wrapped widgets ", Atomic.UI.debugGetWrappedWidgetCount());
+    }
 
     deltaTime = 0;
 

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

@@ -19,7 +19,7 @@ function start() {
 
     var uiNode = game.scene.createChild("UI");
 
-    uiNode.createJSComponent("TestLifetime");
+    uiNode.createJSComponent("TestButtons");
 
 }
 

+ 53 - 0
UITests/Resources/UI/TestLifetime.ui.txt

@@ -0,0 +1,53 @@
+TBLayout: axis: y, distribution-position: "left top", distribution: "available"
+
+	TBSection: value: 1, text: "Misc features"
+		TBLayout: axis: y, spacing: 0, size: available
+			TBButton: skin: "TBButton.flat", text: "Radiobutton & Checkbox"
+				id: "test-layout"
+				data: "test_radio_checkbox.tb.txt"
+			TBButton: skin: "TBButton.flat", text: "TBSelectList", id: "test-list"
+			TBButton: skin: "TBButton.flat", text: "ScrollContainer & misc.", id: "test-scroll-container"
+			TBButton: skin: "TBButton.flat", text: "TBWidgetValue connections", id: "test-connections"
+			TBButton: skin: "TBButton.flat", text: "TBImage", id: "test-image"
+			TBButton: skin: "TBButton.flat", text: "TBScrollerSnapListener", id: "test-page"
+			TBButton: skin: "TBButton.flat", text: "Animations", id: "test-animations"
+			TBButton: skin: "TBButton.flat", text: "Skin conditions", id: "test-skin-conditions"
+			TBButton: skin: "TBButton.flat", text: "TBToggleContainer"
+				id: "test-layout"
+				data: "test_toggle_containers.tb.txt"
+			TBButton: skin: "TBButton.flat", text: "Close with dim & alert", id: "TBWindow.close"
+			TBButton: skin: "TBButton.flat", text: "ResourceEditWindow", id: "test-resource-edit"
+
+	TBSection: value: 0, text: "Layout tests"
+		TBLayout: axis: y, spacing: 0, size: available
+			TBButton: skin: "TBButton.flat", text: "Size, gravity, position"
+				id: "test-layout"
+				data: "test_layout01.tb.txt"
+			TBButton: skin: "TBButton.flat", text: "Distribution"
+				id: "test-layout"
+				data: "test_layout02.tb.txt"
+			TBButton: skin: "TBButton.flat", text: "TBWidget default"
+				id: "test-layout"
+				data: "test_layout03.tb.txt"
+
+	TBSection: value: 0, text: "Graphics tests"
+		TBLayout: axis: y, spacing: 0, size: available
+			TBClickLabel: text: "Continous repaint"
+				lp: max-width: 0
+				TBCheckBox: connection: continous-repaint
+			TBButton: skin: "TBButton.flat", text: "Reload skin bitmaps", id: "reload skin bitmaps"
+			TBButton: skin: "TBButton.flat", text: "Context lost & restore", id: "test context lost"
+
+	TBSection: value: 0, text: "Message tests"
+		TBLayout: axis: y, spacing: 0, size: available
+			TBButton: skin: "TBButton.flat", text: "PostMessage", id: "msg"
+			TBButton: skin: "TBButton.flat", text: "PostMessageDelayed", id: "delayedmsg"
+			TBClickLabel: text: "Busy message loop"
+				lp: max-width: 0
+				TBCheckBox: id: "busymsg"
+
+	# We want the debug button at the bottom if there is space over,
+	# so use an trailing layout which may expand a lot.
+	TBLayout: axis: y, distribution-position: bottom
+		lp: max-height: 10000
+		TBButton: id: "debug settings", text: "Runtime debug settings..."