EventTests.cs :  » GUI » SharpVectorGraphics » SharpVectors » UnitTests » Events » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » SharpVectorGraphics 
SharpVectorGraphics » SharpVectors » UnitTests » Events » EventTests.cs
using System;
using NUnit.Framework;
using SharpVectors.Dom.Events;
using SharpVectors.Dom.Svg;

namespace SharpVectors.UnitTests.Events{
  [TestFixture]
  public class EventTests
  {
    SvgDocument doc;
    SvgRectElement rect;
    SvgGElement g;
    int eventStatus = 0;

    [SetUp]
    public void SetUp()
    {
      if(doc == null)
      {
        SvgWindow wnd = new SvgWindow(100, 100, null);
        doc = new SvgDocument(wnd);
        doc.Load("events_01.svg");
        rect = (SvgRectElement)doc.SelectSingleNode("//*[local-name()='rect']");
        g = (SvgGElement)doc.SelectSingleNode("//*[local-name()='g']");
      }
      eventStatus = 0;
    }

    [Test]
    public void EventTarget()
    {
      IEventTarget targ = rect as IEventTarget;
      Assert.IsNotNull(targ);
    }

    [Test]
    public void TestConstructor()
    {
      Event e = new Event("mousemove", true, false);
      Assert.AreEqual("mousemove", e.Type);
      Assert.AreEqual(true, e.Bubbles);
      Assert.AreEqual(false, e.Cancelable);

      e = new Event("dummy", false, true);
      Assert.AreEqual("dummy", e.Type);
      Assert.AreEqual(false, e.Bubbles);
      Assert.AreEqual(true, e.Cancelable);
    }

    [Test]
    public void TestConstructorEmptyType()
    {
      Event e = new Event("", true, false);
    }
    
    [Test]
    public void TestConstructorNullType()
    {
      Event e = new Event(null, true, false);
    }

    private void PropagateHandlerAtTarget(IEvent e)
    {
      Assert.AreSame(rect, e.CurrentTarget);
      Assert.AreEqual(rect, e.Target);
      Assert.AreEqual(EventPhase.AtTarget, e.EventPhase);
      eventStatus = 1;
    }

    private void PropagateHandlerAtG(IEvent e)
    {
      Assert.AreSame(g, e.CurrentTarget);
      Assert.AreEqual(rect, e.Target);
      if(e.EventPhase == EventPhase.CapturingPhase || 
        (e.EventPhase == EventPhase.BubblingPhase && eventStatus == 1))
      {
      }
      else
      {
        Assert.Fail();
      }
      eventStatus = 2;
    }

    [Test]
    public void TestPropagate1()
    {
      ((IEventTarget)rect).AddEventListener("mousemove", new EventListener(PropagateHandlerAtTarget), false);
      ((IEventTarget)rect).DispatchEvent(new Event("mousemove", true, true));
      Assert.AreEqual(1, eventStatus);
      ((IEventTarget)rect).RemoveEventListener("mousemove", new EventListener(PropagateHandlerAtTarget), false);
    }

    [Test]
    public void TestPropagate2()
    {
      ((IEventTarget)g).AddEventListener("mousemove", new EventListener(PropagateHandlerAtG), false);
      ((IEventTarget)rect).AddEventListener("mousemove", new EventListener(PropagateHandlerAtTarget), false);
      ((IEventTarget)rect).DispatchEvent(new Event("mousemove", true, true));
      Assert.AreEqual(2, eventStatus);
      ((IEventTarget)rect).RemoveEventListener("mousemove", new EventListener(PropagateHandlerAtTarget), false);
      ((IEventTarget)g).RemoveEventListener("mousemove", new EventListener(PropagateHandlerAtG), false);
    }

    [Test]
    public void TestMouseMove()
    {
      ((IEventTarget)rect).AddEventListener("mousemove", new EventListener(PropagateHandlerAtTarget), false);
      ((IEventTarget)rect).DispatchEvent(new Event("mousemove", true, true));
      Assert.AreEqual(1, eventStatus);
      ((IEventTarget)rect).RemoveEventListener("mousemove", new EventListener(PropagateHandlerAtTarget), false);
    }

    [Test]
    public void TestMouseDown()
    {
      ((IEventTarget)rect).AddEventListener("mousedown", new EventListener(PropagateHandlerAtTarget), false);
      ((IEventTarget)rect).DispatchEvent(new Event("mousedown", true, true));
      Assert.AreEqual(1, eventStatus);
      ((IEventTarget)rect).AddEventListener("mousedown", new EventListener(PropagateHandlerAtTarget), false);
    }

    [Test]
    public void TestMouseUp()
    {
      ((IEventTarget)rect).AddEventListener("mouseup", new EventListener(PropagateHandlerAtTarget), false);
      ((IEventTarget)rect).DispatchEvent(new Event("mouseup", true, true));
      Assert.AreEqual(1, eventStatus);
      ((IEventTarget)rect).RemoveEventListener("mouseup", new EventListener(PropagateHandlerAtTarget), false);
    }
    
    [Test]
    public void TestMouseOver()
    {
      ((IEventTarget)rect).AddEventListener("mouseover", new EventListener(PropagateHandlerAtTarget), false);
      ((IEventTarget)rect).DispatchEvent(new Event("mouseover", true, true));
      Assert.AreEqual(1, eventStatus);
      ((IEventTarget)rect).RemoveEventListener("mouseover", new EventListener(PropagateHandlerAtTarget), false);
    }

    [Test]
    public void TestMouseOut()
    {
      ((IEventTarget)rect).AddEventListener("mouseout", new EventListener(PropagateHandlerAtTarget), false);
      ((IEventTarget)rect).DispatchEvent(new Event("mouseout", true, true));
      Assert.AreEqual(1, eventStatus);
      ((IEventTarget)rect).RemoveEventListener("mouseout", new EventListener(PropagateHandlerAtTarget), false);
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.