示例#1
0
        public void TestStaticCreation()
        {
			NSArray constraints;
			NSDictionary views;
			
			NSView view = new NSView(new NSRect(0, 0, 512, 512));
			NSButton button1 = new NSButton(new NSRect(0, 0, 128, 48));
			view.AddSubview(button1);
			button1.Release();
			NSButton button2 = new NSButton(new NSRect(0, 0, 128, 48));
			view.AddSubview(button2);
			button2.Release();
			
			views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", button2, (NSString)"button2", null);
            constraints = NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("[button1]-[button2]", 0, null, views);
            Check(constraints);
			
			view.Release();
        }
示例#2
0
        public void TestPriority()
        {
			NSLayoutConstraint constraint;
			NSArray constraints;
			NSDictionary views;
			NSLayoutPriority priority;
			
			NSView view = new NSView(new NSRect(0, 0, 512, 512));
			NSButton button1 = new NSButton(new NSRect(0, 0, 128, 48));
			view.AddSubview(button1);
			button1.Release();
			NSButton button2 = new NSButton(new NSRect(0, 0, 128, 48));
			view.AddSubview(button2);
			button2.Release();
			
			views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", button2, (NSString)"button2", null);
            constraints = NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("[button1]-[button2]", 0, null, views);
            Check(constraints);

			constraint = constraints.LastObject.CastTo<NSLayoutConstraint>();
            Check(constraint);
			
			constraint.Priority = NSLayoutPriority.NSLayoutPriorityRequired;
			priority = constraint.Priority;
			Assert.AreEqual(NSLayoutPriority.NSLayoutPriorityRequired, priority, "Priorities should be equal");
			
			constraint.Priority = (NSLayoutPriority) ((double)NSLayoutPriority.NSLayoutPriorityDefaultLow + 1.5);
			priority = constraint.Priority;
			Assert.AreEqual(NSLayoutPriority.NSLayoutPriorityDefaultLow + 1, priority, "Priorities should be equal");
			
			constraint.Priority = (NSLayoutPriority) ((double)NSLayoutPriority.NSLayoutPriorityDefaultLow + 45.23);
			priority = constraint.Priority;
			Assert.AreEqual(NSLayoutPriority.NSLayoutPriorityDefaultLow + 45, priority, "Priorities should be equal");
			
			constraint.Priority = (NSLayoutPriority) ((double)NSLayoutPriority.NSLayoutPriorityDefaultLow + 45.75);
			priority = constraint.Priority;
			Assert.AreEqual(NSLayoutPriority.NSLayoutPriorityDefaultLow + 45, priority, "Priorities should be equal");
			
			view.Release();
        }
示例#3
0
        public void TestExceptions()
        {
			NSDictionary views;
			
			NSView view = new NSView(new NSRect(0, 0, 512, 512));
			NSButton button1 = new NSButton(new NSRect(0, 0, 128, 48));
			view.AddSubview(button1);
			button1.Release();
			NSButton button2 = new NSButton(new NSRect(0, 0, 128, 48));
			view.AddSubview(button2);
			button2.Release();
			
            Assert.Throws<ObjectiveCMessagingException>(() =>
			{
				NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("[button1]-[button2]", 0, null, null);
			});
            Assert.Throws<ObjectiveCMessagingException>(() =>
			{
				views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", null);
				NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("[button1]-[button2]", 0, null, views);
			});
            Assert.Throws<ObjectiveCMessagingException>(() =>
			{
				views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", button2, (NSString)"dummy", null);
				NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("V|[button1]-[button2]|", 0, null, views);
			});
            Assert.Throws<ObjectiveCMessagingException>(() =>
			{
				views = NSDictionary.DictionaryWithObjectsAndKeys(button1, (NSString)"button1", button2, (NSString)"dummy", null);
				NSLayoutConstraint.ConstraintsWithVisualFormatOptionsMetricsViews("V:|[button1(>30)]|", 0, null, views);
			});
			
			view.Release();
        }