changeset 118:9ac208b53582

Unittest for mde.gui.widget.layout.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sun, 28 Dec 2008 10:55:15 +0000
parents aba2dd815a1f
children d28aea50c6da
files mde/gui/widget/layout.d mde/mde.d
diffstat 2 files changed, 60 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mde/gui/widget/layout.d	Fri Dec 26 12:07:38 2008 +0000
+++ b/mde/gui/widget/layout.d	Sun Dec 28 10:55:15 2008 +0000
@@ -702,6 +702,65 @@
     static this () {
         instances = new HashMap!(widgetID,AlignColumns);
     }
+    
+    debug invariant()
+    {
+        if (setupWidths) {
+            assert (width.length == minWidth.length);
+            wdim x = 0;
+            foreach (i,w; width) {
+                assert (minWidth[i] <= w);	// even when "not sizable", cols may get enlarged
+                assert (x == pos[i]);
+                x += w + spacing;
+            }
+            assert (x - spacing == w);
+            x = spacing * cast(wdim)(minWidth.length - 1);
+            foreach (mw; minWidth)
+                x += mw;
+            assert (x == mw);
+        }
+    }
+    
+    debug (mdeUnitTest) unittest {
+        bool throws (void delegate() dg) {
+            bool r = false;
+            try {
+                dg();
+            } catch (Exception e) {
+                r = true;
+            }
+            return r;
+        }
+        
+        AlignColumns a, a2, b;
+        a = getInstance ("a", 2);
+        a2 = getInstance ("a", 2);
+        b = getInstance ("b", 5);
+        assert (a is a2);
+        assert (a !is b);
+        assert (throws ({ getInstance ("a", 4); }));
+        
+        a.setup (0, 3);
+        a.spacing = 6;
+        a.minWidth[0] = 50;
+        a.minWidth[1] = 6;
+        a.sizable[1] = true;
+        a.setWidths;
+        assert (a.w == 62);
+        
+        b.setup (0,3);
+        b.spacing = 2;
+        foreach (ref wd; b.minWidth)
+            wd = 10;
+        b.sizable[1] = b.sizable[3] = true;
+        b.setWidths;
+        assert (b.w == 58);
+        
+        assert (b.resizeWidth (60, -1) == 60);
+        assert (b.width[3] == 12);
+        
+        logger.info ("Unittest complete.");
+    }
 }
 
 // Index types. Note that in some cases they need to hold negative values.
--- a/mde/mde.d	Fri Dec 26 12:07:38 2008 +0000
+++ b/mde/mde.d	Sun Dec 28 10:55:15 2008 +0000
@@ -34,6 +34,7 @@
     import mde.file.ssi;
     import mde.file.mergetag.mdeUT;
     import mde.lookup.Translation;
+    import mde.gui.widget.layout;
 }
 
 //BEGIN A simple drawable to print a message in the window.