From 2d93d89034894255917733d9a38bfd7998805f4c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Sun, 4 Feb 2018 16:06:48 +0100 Subject: [PATCH] xunit basic setup --- .../Crow.Test.csproj | 52 +- {UnitTest => Crow.Test}/ExpectedOutputs/0.png | Bin {UnitTest => Crow.Test}/ExpectedOutputs/1.png | Bin {UnitTest => Crow.Test}/ExpectedOutputs/3.png | Bin {UnitTest => Crow.Test}/ExpectedOutputs/4.png | Bin {UnitTest => Crow.Test}/ExpectedOutputs/5.png | Bin Crow.Test/Interfaces/0.crow | 2 + {UnitTest => Crow.Test}/Interfaces/1.crow | 0 {UnitTest => Crow.Test}/Interfaces/2.crow | 0 {UnitTest => Crow.Test}/Interfaces/3.crow | 38 +- {UnitTest => Crow.Test}/Interfaces/4.crow | 0 {UnitTest => Crow.Test}/Interfaces/5.crow | 0 .../Interfaces/testButton.crow | 0 Crow.Test/Test.cs | 71 +++ Crow.Test/packages.config | 4 + UnitTest/Interfaces/0.crow | 2 - UnitTest/NUnitCrowWindow.cs | 465 ------------------ UnitTest/Test.cs | 64 --- UnitTest/packages.config | 4 - 19 files changed, 116 insertions(+), 586 deletions(-) rename UnitTest/UnitTest.csproj => Crow.Test/Crow.Test.csproj (79%) rename {UnitTest => Crow.Test}/ExpectedOutputs/0.png (100%) rename {UnitTest => Crow.Test}/ExpectedOutputs/1.png (100%) rename {UnitTest => Crow.Test}/ExpectedOutputs/3.png (100%) rename {UnitTest => Crow.Test}/ExpectedOutputs/4.png (100%) rename {UnitTest => Crow.Test}/ExpectedOutputs/5.png (100%) create mode 100755 Crow.Test/Interfaces/0.crow rename {UnitTest => Crow.Test}/Interfaces/1.crow (100%) rename {UnitTest => Crow.Test}/Interfaces/2.crow (100%) rename {UnitTest => Crow.Test}/Interfaces/3.crow (62%) rename {UnitTest => Crow.Test}/Interfaces/4.crow (100%) rename {UnitTest => Crow.Test}/Interfaces/5.crow (100%) rename {UnitTest => Crow.Test}/Interfaces/testButton.crow (100%) create mode 100644 Crow.Test/Test.cs create mode 100644 Crow.Test/packages.config delete mode 100755 UnitTest/Interfaces/0.crow delete mode 100644 UnitTest/NUnitCrowWindow.cs delete mode 100644 UnitTest/Test.cs delete mode 100644 UnitTest/packages.config diff --git a/UnitTest/UnitTest.csproj b/Crow.Test/Crow.Test.csproj similarity index 79% rename from UnitTest/UnitTest.csproj rename to Crow.Test/Crow.Test.csproj index ddc46b62..94ec07b8 100644 --- a/UnitTest/UnitTest.csproj +++ b/Crow.Test/Crow.Test.csproj @@ -5,12 +5,11 @@ AnyCPU 8.0.30703 2.0 - {7BAE4448-E8F4-48B3-BB11-FA78E7F4506B} + {42C73BD8-51F5-4BB7-8EE9-9F0BE2D80A2C} Library - UnitTest - UnitTest - v4.5 - 0.4 + Crow.Test + Crow.Test + v4.6.1 true @@ -20,70 +19,58 @@ DEBUG; prompt 4 - false - full true bin\Release prompt 4 - false - - - ..\..\opentk\Binaries\OpenTK\Release\OpenTK.dll - - - - - - nunit + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - - - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest @@ -94,7 +81,8 @@ - + + \ No newline at end of file diff --git a/UnitTest/ExpectedOutputs/0.png b/Crow.Test/ExpectedOutputs/0.png similarity index 100% rename from UnitTest/ExpectedOutputs/0.png rename to Crow.Test/ExpectedOutputs/0.png diff --git a/UnitTest/ExpectedOutputs/1.png b/Crow.Test/ExpectedOutputs/1.png similarity index 100% rename from UnitTest/ExpectedOutputs/1.png rename to Crow.Test/ExpectedOutputs/1.png diff --git a/UnitTest/ExpectedOutputs/3.png b/Crow.Test/ExpectedOutputs/3.png similarity index 100% rename from UnitTest/ExpectedOutputs/3.png rename to Crow.Test/ExpectedOutputs/3.png diff --git a/UnitTest/ExpectedOutputs/4.png b/Crow.Test/ExpectedOutputs/4.png similarity index 100% rename from UnitTest/ExpectedOutputs/4.png rename to Crow.Test/ExpectedOutputs/4.png diff --git a/UnitTest/ExpectedOutputs/5.png b/Crow.Test/ExpectedOutputs/5.png similarity index 100% rename from UnitTest/ExpectedOutputs/5.png rename to Crow.Test/ExpectedOutputs/5.png diff --git a/Crow.Test/Interfaces/0.crow b/Crow.Test/Interfaces/0.crow new file mode 100755 index 00000000..fdcc11d1 --- /dev/null +++ b/Crow.Test/Interfaces/0.crow @@ -0,0 +1,2 @@ + + diff --git a/UnitTest/Interfaces/1.crow b/Crow.Test/Interfaces/1.crow similarity index 100% rename from UnitTest/Interfaces/1.crow rename to Crow.Test/Interfaces/1.crow diff --git a/UnitTest/Interfaces/2.crow b/Crow.Test/Interfaces/2.crow similarity index 100% rename from UnitTest/Interfaces/2.crow rename to Crow.Test/Interfaces/2.crow diff --git a/UnitTest/Interfaces/3.crow b/Crow.Test/Interfaces/3.crow similarity index 62% rename from UnitTest/Interfaces/3.crow rename to Crow.Test/Interfaces/3.crow index 0495dcbb..e9c88920 100755 --- a/UnitTest/Interfaces/3.crow +++ b/Crow.Test/Interfaces/3.crow @@ -6,78 +6,78 @@ - + - - + + - + - + - + - + - + - - + + - + - + - + - + - - + + - + - + - + diff --git a/UnitTest/Interfaces/4.crow b/Crow.Test/Interfaces/4.crow similarity index 100% rename from UnitTest/Interfaces/4.crow rename to Crow.Test/Interfaces/4.crow diff --git a/UnitTest/Interfaces/5.crow b/Crow.Test/Interfaces/5.crow similarity index 100% rename from UnitTest/Interfaces/5.crow rename to Crow.Test/Interfaces/5.crow diff --git a/UnitTest/Interfaces/testButton.crow b/Crow.Test/Interfaces/testButton.crow similarity index 100% rename from UnitTest/Interfaces/testButton.crow rename to Crow.Test/Interfaces/testButton.crow diff --git a/Crow.Test/Test.cs b/Crow.Test/Test.cs new file mode 100644 index 00000000..c0fa9f59 --- /dev/null +++ b/Crow.Test/Test.cs @@ -0,0 +1,71 @@ +// +// Test.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2016 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using NUnit.Framework; +using System; +using Crow; +using System.IO; +[assembly: Description ("Assembly description here")] +namespace UnitTest +{ + [TestFixture, Description ("Fixture description here")] + public class Test + { + Interface iface; + Rectangle bounds = new Rectangle (0, 0, 600, 600); + + + [SetUp] + public void Init () + { + iface = new Interface (); + iface.ProcessResize (bounds); + } + + [Test , Description("My really cool test")] + public void GraphicObject () + { + string [] tests = new string [] { "0", "1", "3", "4", "5" }; + + foreach (string s in tests) { + string fileName = Path.Combine ("Interfaces", s + ".crow"); + iface.LoadInterface (fileName); + + iface.Update (); + iface.Update (); + + using (Cairo.Surface surf = new Cairo.ImageSurface (iface.bmp, + Cairo.Format.Argb32, iface.ClientRectangle.Width, iface.ClientRectangle.Height, iface.ClientRectangle.Width * 4)) { + surf.WriteToPng (@"tmp.png"); + surf.WriteToPng (fileName + ".png"); + } + + + byte [] model = File.ReadAllBytes ("ExpectedOutputs/" + s + ".png"); + byte [] result = File.ReadAllBytes (@"tmp.png"); + + //CollectionAssert.AreEqual (model, result); + + iface.ClearInterface (); + } + } + } +} + diff --git a/Crow.Test/packages.config b/Crow.Test/packages.config new file mode 100644 index 00000000..01c187cc --- /dev/null +++ b/Crow.Test/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/UnitTest/Interfaces/0.crow b/UnitTest/Interfaces/0.crow deleted file mode 100755 index 64d6db6d..00000000 --- a/UnitTest/Interfaces/0.crow +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/UnitTest/NUnitCrowWindow.cs b/UnitTest/NUnitCrowWindow.cs deleted file mode 100644 index 0a4a9edc..00000000 --- a/UnitTest/NUnitCrowWindow.cs +++ /dev/null @@ -1,465 +0,0 @@ -#define MONO_CAIRO_DEBUG_DISPOSE - - -using System; -using System.Runtime.InteropServices; -using OpenTK; -using OpenTK.Graphics.OpenGL; -using OpenTK.Input; - -using System.Diagnostics; - -//using GGL; -using System.Threading; -using System.Collections.Generic; -using System.Linq; -using Cairo; -using System.IO; - - -namespace Crow -{ - class NUnitCrowWindow : IValueChange, ILayoutable, IGOLibHost - { - #region IValueChange implementation - public event EventHandler ValueChanged; - public virtual void NotifyValueChanged(string MemberName, object _value) - { - ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value)); - } - #endregion - - public Rectangle ClientRectangle = new Rectangle(0,0,800,600); - public List GraphicObjects = new List(); - public Color Background = Color.Transparent; - - Rectangles _redrawClip = new Rectangles();//should find another way to access it from child - List _gobjsToRedraw = new List(); - - #region IGOLibHost implementation - public XCursor MouseCursor { - set { throw new NotImplementedException ();} - } - public Rectangles clipping { - get { - return _redrawClip; - } - set { - _redrawClip = value; - } - } - public List gobjsToRedraw { - get { - return _gobjsToRedraw; - } - set { - _gobjsToRedraw = value; - } - } - public void AddWidget(GraphicObject g) - { - g.Parent = this; - GraphicObjects.Insert (0, g); - - g.RegisterForLayouting (LayoutingType.Sizing); - } - public void DeleteWidget(GraphicObject g) - { - g.Visible = false;//trick to ensure clip is added to refresh zone - g.ClearBinding(); - GraphicObjects.Remove (g); - } - public void PutOnTop(GraphicObject g) - { - if (GraphicObjects.IndexOf(g) > 0) - { - GraphicObjects.Remove(g); - GraphicObjects.Insert(0, g); - g.AddToRedrawList (); - } - } - public void Quit () - { - } - - #region focus - GraphicObject _activeWidget; //button is pressed on widget - GraphicObject _hoverWidget; //mouse is over - GraphicObject _focusedWidget; //has keyboard (or other perif) focus - - public GraphicObject activeWidget - { - get { return _activeWidget; } - set - { - if (_activeWidget == value) - return; - _activeWidget = value; - } - } - public GraphicObject hoverWidget - { - get { return _hoverWidget; } - set { _hoverWidget = value; } - } - public GraphicObject FocusedWidget { - get { return _focusedWidget; } - set { - if (_focusedWidget == value) - return; - if (_focusedWidget != null) - _focusedWidget.onUnfocused (this, null); - _focusedWidget = value; - if (_focusedWidget != null) - _focusedWidget.onFocused (this, null); - } - } - #endregion - - #endregion - - #region Events - //those events are raised only if mouse isn't in a graphic object - public event EventHandler MouseWheelChanged; - public event EventHandler MouseButtonUp; - public event EventHandler MouseButtonDown; - public event EventHandler MouseClick; - public event EventHandler MouseMove; - #endregion - - #region graphic contexte - Context ctx; - public Surface surf; - string testId; - #endregion - - #region update - public Stopwatch updateTime = new Stopwatch (); - public Stopwatch layoutTime = new Stopwatch (); - public Stopwatch guTime = new Stopwatch (); - public Stopwatch drawingTime = new Stopwatch (); - - public void Update () - { - ctx = new Context(surf); - - guTime.Reset (); - updateTime.Restart (); - layoutTime.Restart (); - - GraphicObject[] invGOList = new GraphicObject[GraphicObjects.Count]; - GraphicObjects.CopyTo (invGOList, 0); - invGOList = invGOList.Reverse ().ToArray (); - - //Debug.WriteLine ("======= Layouting queue start ======="); - - while (Interface.CurrentInterface.LayoutingQueue.Count > 0) { - LayoutingQueueItem lqi = Interface.CurrentInterface.LayoutingQueue.Dequeue (); - lqi.ProcessLayouting (); - } - - layoutTime.Stop (); - - //Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-"); - //final redraw clips should be added only when layout is completed among parents, - //that's why it take place in a second pass - GraphicObject[] gotr = new GraphicObject[gobjsToRedraw.Count]; - gobjsToRedraw.CopyTo (gotr); - gobjsToRedraw.Clear (); - foreach (GraphicObject p in gotr) { - p.IsInRedrawList = false; - p.Parent.RegisterClip (p.LastPaintedSlot); - p.Parent.RegisterClip (p.getSlot()); - } - - guTime.Start (); - - using (ctx = new Context (surf)){ - if (clipping.count > 0) { - //Link.draw (ctx); - clipping.clearAndClip(ctx); - - foreach (GraphicObject p in invGOList) { - if (!p.Visible) - continue; - - ctx.Save (); - - p.Paint (ref ctx); - - ctx.Restore (); - } - - #if DEBUG_CLIP_RECTANGLE - clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5)); - #endif - - clipping.Reset (); - } - } - - guTime.Stop (); - updateTime.Stop (); - - - sw.WriteLine ("{0}\t{1,8}\t{2,8}\t{3,8}\t{4,8}", - testId, - layoutTime.ElapsedTicks, - guTime.ElapsedTicks, - updateTime.ElapsedTicks, - loadTime.ElapsedTicks); - sw.Flush (); - -// Console.WriteLine("{3} => layout:{0}ms\tdraw{1}ms\tupdate:{2}ms", -// layoutTime.ElapsedMilliseconds, -// guTime.ElapsedMilliseconds, -// updateTime.ElapsedMilliseconds, -// testId); - //surf.WriteToPng (@"ExpectedOutputs/" + testId + ".png"); - surf.WriteToPng (@"tmp.png"); - } - #endregion - - #region loading - public Stopwatch loadTime = new Stopwatch (); - public GraphicObject LoadTest (string id) - { - testId = id; - loadTime.Start (); - GraphicObject tmp = Interface.Load ("Interfaces/" + testId + ".crow", this); - loadTime.Stop (); - AddWidget (tmp); - return tmp; - } - /// Remove all Graphic objects from top container - public void ClearInterface() - { - int i = 0; - while (GraphicObjects.Count>0) { - GraphicObject g = GraphicObjects [i]; - g.Visible = false; - g.ClearBinding (); - GraphicObjects.RemoveAt (0); - } - } - #endregion - - #region CTOR - public NUnitCrowWindow (int width, int height) - { - ClientRectangle.Width = width; - ClientRectangle.Height = height; - - surf = new ImageSurface(Format.Argb32, ClientRectangle.Width, ClientRectangle.Height); - string path = "crow-" + DateTime.Now + ".txt"; - - sw = new StreamWriter (path); - - sw.WriteLine ("ID layout draw update load"); - sw.WriteLine ("----------------------------------------------------------------"); - sw.Flush (); - } - ~NUnitCrowWindow(){ - - sw.Close (); - } - #endregion - - int frameCpt = 0; - int idx = 0; - StreamWriter sw; - - #region FPS - int _fps = 0; - - public int fps { - get { return _fps; } - set { - if (_fps == value) - return; - - _fps = value; - - if (_fps > fpsMax) { - fpsMax = _fps; - ValueChanged.Raise(this, new ValueChangeEventArgs ("fpsMax", fpsMax)); - } else if (_fps < fpsMin) { - fpsMin = _fps; - ValueChanged.Raise(this, new ValueChangeEventArgs ("fpsMin", fpsMin)); - } - - ValueChanged.Raise(this, new ValueChangeEventArgs ("fps", _fps)); - ValueChanged.Raise (this, new ValueChangeEventArgs ("update", - this.updateTime.ElapsedMilliseconds.ToString () + " ms")); - } - } - - public int fpsMin = int.MaxValue; - public int fpsMax = 0; - - void resetFps () - { - fpsMin = int.MaxValue; - fpsMax = 0; - _fps = 0; - } - //public string update = ""; - #endregion - - - #region Mouse Handling - void Mouse_Move(object sender, MouseMoveEventArgs e) - { - if (_activeWidget != null) { - //first, ensure object is still in the graphic tree - if (_activeWidget.HostContainer == null) { - activeWidget = null; - } else { - - //send move evt even if mouse move outside bounds - _activeWidget.onMouseMove (_activeWidget, e); - return; - } - } - - if (_hoverWidget != null) { - //first, ensure object is still in the graphic tree - if (_hoverWidget.HostContainer == null) { - hoverWidget = null; - } else { - //check topmost graphicobject first - GraphicObject tmp = _hoverWidget; - GraphicObject topc = null; - while (tmp is GraphicObject) { - topc = tmp; - tmp = tmp.Parent as GraphicObject; - } - int idxhw = GraphicObjects.IndexOf (topc); - if (idxhw != 0) { - int i = 0; - while (i < idxhw) { - if (GraphicObjects [i].MouseIsIn (e.Position)) { - _hoverWidget.onMouseLeave (this, e); - GraphicObjects [i].checkHoverWidget (e); - return; - } - i++; - } - } - - - if (_hoverWidget.MouseIsIn (e.Position)) { - _hoverWidget.checkHoverWidget (e); - return; - } else { - _hoverWidget.onMouseLeave (this, e); - //seek upward from last focused graph obj's - while (_hoverWidget.Parent as GraphicObject != null) { - _hoverWidget = _hoverWidget.Parent as GraphicObject; - if (_hoverWidget.MouseIsIn (e.Position)) { - _hoverWidget.checkHoverWidget (e); - return; - } else - _hoverWidget.onMouseLeave (this, e); - } - } - } - } - - //top level graphic obj's parsing - for (int i = 0; i < GraphicObjects.Count; i++) { - GraphicObject g = GraphicObjects[i]; - if (g.MouseIsIn (e.Position)) { - g.checkHoverWidget (e); - PutOnTop (g); - return; - } - } - _hoverWidget = null; - MouseMove.Raise (this, e); - } - void Mouse_ButtonUp(object sender, MouseButtonEventArgs e) - { - if (_activeWidget == null) { - MouseButtonUp.Raise (this, e); - return; - } - - _activeWidget.onMouseUp (this, e); - _activeWidget = null; - } - void Mouse_ButtonDown(object sender, MouseButtonEventArgs e) - { - if (_hoverWidget == null) { - MouseButtonDown.Raise (this, e); - return; - } - - GraphicObject g = _hoverWidget; - while (!g.Focusable) { - g = g.Parent as GraphicObject; - if (g == null) { - return; - } - } - - _activeWidget = g; - _activeWidget.onMouseDown (this, e); - } - - void Mouse_WheelChanged(object sender, MouseWheelEventArgs e) - { - if (_hoverWidget == null) { - MouseWheelChanged.Raise (this, e); - return; - } - _hoverWidget.onMouseWheel (this, e); - } - #endregion - - #region keyboard Handling - void Keyboard_KeyDown(object sender, KeyboardKeyEventArgs e) - { - if (_focusedWidget == null) - return; - _focusedWidget.onKeyDown (sender, e); - } - #endregion - - #region ILayoutable implementation - public void RegisterClip(Rectangle r){ - clipping.AddRectangle (r); - } - public void EnqueueForLayouting (LayoutingType layoutType) - { - throw new NotImplementedException (); - } - public int LayoutingTries { - get { throw new NotImplementedException (); } - set { throw new NotImplementedException (); } - } - public ILayoutable LogicalParent { - get { return null; } - set { throw new NotImplementedException (); } - } - public ILayoutable Parent { - get { return null; } - set { throw new NotImplementedException (); } - } - public LayoutingType QueuedLayoutings { - get { return LayoutingType.None; } - set { throw new NotImplementedException (); } - } - public void EnqueueForLayouting (int layoutType) { throw new NotImplementedException (); } - public bool UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); } - public Rectangle ContextCoordinates (Rectangle r) => r; - public Rectangle ScreenCoordinates (Rectangle r) => r; - Rectangle ILayoutable.ClientRectangle { - get { return new Size(this.ClientRectangle.Size.Width,this.ClientRectangle.Size.Height); } - } - public IGOLibHost HostContainer { get { return this; }} - public Rectangle getSlot () => ClientRectangle; - public Rectangle getBounds () => ClientRectangle; - #endregion - } -} \ No newline at end of file diff --git a/UnitTest/Test.cs b/UnitTest/Test.cs deleted file mode 100644 index d2d24004..00000000 --- a/UnitTest/Test.cs +++ /dev/null @@ -1,64 +0,0 @@ -// -// Test.cs -// -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2016 jp -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -using NUnit.Framework; -using System; -using Crow; -using System.IO; - -namespace UnitTest -{ - [TestFixture ()] - public class Test - { - NUnitCrowWindow win; - - [SetUp] - public void Init() - { - win = new NUnitCrowWindow (600,600); - } - - [Test ()] - [Category("Alignment")] - public void GraphicObject () - { - string[] tests = new string[] { "0","1","3","4","5"}; - - foreach (string s in tests) { - win.LoadTest (s); - win.Update (); - win.Update (); - byte[] model = File.ReadAllBytes("ExpectedOutputs/" + s + ".png"); - byte[] result = File.ReadAllBytes(@"tmp.png"); - - CollectionAssert.AreEqual (model, result); - - win.ClearInterface (); - } - } - - void testAlignment(GraphicObject g){ - g.HorizontalAlignment = HorizontalAlignment.Left; - - } - } -} - diff --git a/UnitTest/packages.config b/UnitTest/packages.config deleted file mode 100644 index b183023e..00000000 --- a/UnitTest/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file -- 2.47.3