Merge pull request #590 from Frassle/gamewindowtests

GameWindow tests and some X11 fixes
This commit is contained in:
Fraser Waters 2017-08-02 15:04:47 +01:00 committed by GitHub
commit bc3f33271f
10 changed files with 1961 additions and 7 deletions

View file

@ -4,6 +4,12 @@ sudo: false # use the new container-based Travis infrastructure
before_install:
- chmod +x build.sh
before_script:
# Start a virtual framebuffer as described: https://docs.travis-ci.com/user/gui-and-headless-browsers/
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
script:
- ./build.sh NuGet

View file

@ -38,6 +38,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{5EEE
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "OpenTK.Tests", "tests\OpenTK.Tests\OpenTK.Tests.fsproj", "{6801C263-ADDA-4A7B-979D-649BCB5A1DF7}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "OpenTK.Tests.Integration", "tests\OpenTK.Tests.Integration\OpenTK.Tests.Integration.fsproj", "{522D9279-3ED6-475F-867A-6AE69A53C24A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -84,6 +86,10 @@ Global
{6801C263-ADDA-4A7B-979D-649BCB5A1DF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6801C263-ADDA-4A7B-979D-649BCB5A1DF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6801C263-ADDA-4A7B-979D-649BCB5A1DF7}.Release|Any CPU.Build.0 = Release|Any CPU
{522D9279-3ED6-475F-867A-6AE69A53C24A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{522D9279-3ED6-475F-867A-6AE69A53C24A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{522D9279-3ED6-475F-867A-6AE69A53C24A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{522D9279-3ED6-475F-867A-6AE69A53C24A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -91,5 +97,6 @@ Global
GlobalSection(NestedProjects) = preSolution
{C4DDD20F-CB4E-43F4-A75C-4A3D668E1F99} = {1857BB8E-1A35-4EBF-9F6D-685F11DC025B}
{6801C263-ADDA-4A7B-979D-649BCB5A1DF7} = {1857BB8E-1A35-4EBF-9F6D-685F11DC025B}
{522D9279-3ED6-475F-867A-6AE69A53C24A} = {1857BB8E-1A35-4EBF-9F6D-685F11DC025B}
EndGlobalSection
EndGlobal

View file

@ -88,7 +88,7 @@ let activeProjects =
-- "**/OpenTK.iOS.csproj"
!! "src/**/*.??proj"
++ "tests/**/OpenTK.Tests.fsproj"
++ "tests/**/OpenTK.Tests*.fsproj"
|> xamarinFilter
// Generate assembly info files with the right version & up-to-date information

View file

@ -109,7 +109,8 @@ namespace OpenTK.Platform.X11
private static readonly IntPtr _atom_toggle = (IntPtr)2;
#pragma warning disable 649 // never assigned, compiler bug in Mono 3.4.0
private Rectangle bounds, client_rectangle;
private Rectangle bounds;
private Size client_size;
#pragma warning restore 649
private int border_left, border_right, border_top, border_bottom;
private Icon icon;
@ -228,7 +229,7 @@ namespace OpenTK.Platform.X11
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (AppDomain.CurrentDomain.FriendlyName.EndsWith(assembly.ManifestModule.Name))
if (assembly.ManifestModule.Name.Contains(AppDomain.CurrentDomain.FriendlyName))
{
if (entry_assembly == null || assembly.ManifestModule.Name.Length > entry_assembly.ManifestModule.Name.Length)
{
@ -238,7 +239,11 @@ namespace OpenTK.Platform.X11
}
}
var name = entry_assembly.GetName().Name;
var name = "null";
if (entry_assembly != null)
{
name = entry_assembly.GetName().Name;
}
class_hint.Class = name;
class_hint.Name = name.ToLower();
@ -793,7 +798,7 @@ namespace OpenTK.Platform.X11
// when the window is minimized. Many apps
// do not expect this and crash, so clamp
// minimum width/height to 1 instead.
client_rectangle.Size = new Size(
client_size = new Size(
Math.Max(e.ConfigureEvent.width, 1),
Math.Max(e.ConfigureEvent.height, 1));
OnResize(EventArgs.Empty);
@ -1249,6 +1254,7 @@ namespace OpenTK.Platform.X11
}
}
_waitForEvent = XEventName.ConfigureNotify;
ProcessEvents();
}
}
@ -1257,11 +1263,11 @@ namespace OpenTK.Platform.X11
{
get
{
return client_rectangle.Size;
return client_size;
}
set
{
bool is_size_changed = client_rectangle.Size != value;
bool is_size_changed = client_size != value;
if (is_size_changed)
{
int width = value.Width;

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<!--<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>-->
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View file

@ -0,0 +1,41 @@
namespace OpenTK.Tests.Integration.AssemblyInfo
open System.Reflection
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[<assembly: AssemblyTitle("OpenTK.Tests.Integration")>]
[<assembly: AssemblyDescription("")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("")>]
[<assembly: AssemblyProduct("OpenTK.Tests.Integration")>]
[<assembly: AssemblyCopyright("Copyright © 2017")>]
[<assembly: AssemblyTrademark("")>]
[<assembly: AssemblyCulture("")>]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[<assembly: ComVisible(false)>]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[<assembly: Guid("522d9279-3ed6-475f-867a-6ae69a53c24a")>]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [<assembly: AssemblyVersion("1.0.*")>]
[<assembly: AssemblyVersion("1.0.0.0")>]
[<assembly: AssemblyFileVersion("1.0.0.0")>]
do
()

View file

@ -0,0 +1,194 @@
namespace OpenTK.Tests.Integration
open Xunit
open FsCheck
open FsCheck.Xunit
open System
open System.Runtime.InteropServices
open OpenTK
module GameWindow =
module General =
[<Fact>]
let ``Can create and close GameWindow`` () =
use gw = new OpenTK.GameWindow()
gw.Close()
[<Fact>]
let ``Exit works like Close`` () =
use gw = new OpenTK.GameWindow()
gw.Exit()
[<Fact>]
let ``GameWindow exists after creation`` () =
use gw = new OpenTK.GameWindow()
Assert.True(gw.Exists)
gw.Exit()
[<Fact>]
let ``Can close GameWindow on UpdateFrame`` () =
use gw = new OpenTK.GameWindow()
gw.UpdateFrame.Add(fun _ -> gw.Close())
gw.Run()
[<Fact>]
let ``Closing event is sent before closed`` () =
use gw = new OpenTK.GameWindow()
let signals = System.Collections.Generic.List<string>()
gw.Closing.Add(fun _ -> signals.Add("Closing"))
gw.Closed.Add(fun _ -> signals.Add("Closed"))
gw.Close()
Assert.Equal([], signals)
gw.ProcessEvents()
Assert.Equal(["Closing"; "Closed"], signals)
module Constructors =
[<Fact>]
let ``Width and Height can be set via constructor`` () =
use gw = new OpenTK.GameWindow(200, 100)
Assert.Equal(200, gw.Width)
Assert.Equal(100, gw.Height)
module Sizes =
[<Fact>]
let ``Updates to Width take effect`` () =
use gw = new OpenTK.GameWindow()
let oldWidth = gw.Width
let newWidth = oldWidth + 1
gw.Width <- newWidth
Assert.Equal(newWidth, gw.Width)
[<Fact>]
let ``Updates to Height take effect`` () =
use gw = new OpenTK.GameWindow()
let oldHeight = gw.Height
let newHeight = oldHeight + 1
gw.Height <- newHeight
Assert.Equal(newHeight, gw.Height)
[<Fact>]
let ``Updates to Size take effect`` () =
use gw = new OpenTK.GameWindow()
let oldSize = gw.Size
let newSize = System.Drawing.Size(oldSize.Width + 1, oldSize.Height + 1)
gw.Size <- newSize
Assert.Equal(newSize, gw.Size)
[<Fact>]
let ``Updates to ClientSize take effect`` () =
use gw = new OpenTK.GameWindow()
let oldSize = gw.ClientSize
let newSize = System.Drawing.Size(oldSize.Width + 1, oldSize.Height + 1)
gw.ClientSize <- newSize
Assert.Equal(newSize, gw.ClientSize)
[<Fact>]
let ``Updates to ClientRectangle.Size take effect`` () =
use gw = new OpenTK.GameWindow()
let oldSize = gw.ClientRectangle.Size
let newSize = System.Drawing.Size(oldSize.Width + 1, oldSize.Height + 1)
let newRect = System.Drawing.Rectangle(gw.ClientRectangle.Location, newSize)
gw.ClientRectangle <- newRect
Assert.Equal(newRect, gw.ClientRectangle)
[<Fact>]
let ``Updates to Bounds.Size take effect`` () =
use gw = new OpenTK.GameWindow()
let oldSize = gw.Bounds.Size
let newSize = System.Drawing.Size(oldSize.Width + 1, oldSize.Height + 1)
let newRect = System.Drawing.Rectangle(gw.Bounds.Location, newSize)
gw.Bounds <- newRect
Assert.Equal(newRect, gw.Bounds)
[<Fact>]
let ``ClientSize equals ClientRectangle.Size`` () =
use gw = new OpenTK.GameWindow()
Assert.Equal(gw.ClientSize, gw.ClientRectangle.Size)
[<Fact>]
let ``Size equals Bounds.Size`` () =
use gw = new OpenTK.GameWindow()
Assert.Equal(gw.Size, gw.Bounds.Size)
[<Fact>]
let ``Width and Height equals ClientSize`` () =
use gw = new OpenTK.GameWindow()
Assert.Equal(System.Drawing.Size(gw.Width, gw.Height), gw.ClientSize)
module Locations =
[<Fact>]
let ``Updates to X take effect`` () =
use gw = new OpenTK.GameWindow()
let oldX = gw.X
let newX = oldX + 1
gw.X <- newX
Assert.Equal(newX, gw.X)
[<Fact>]
let ``Updates to Y take effect`` () =
use gw = new OpenTK.GameWindow()
let oldY = gw.Y
let newY = oldY + 1
gw.Y <- newY
Assert.Equal(newY, gw.Y)
[<Fact>]
let ``Updates to Location take effect`` () =
use gw = new OpenTK.GameWindow()
let oldLocation = gw.Location
let newLocation = System.Drawing.Point(oldLocation.X + 1, oldLocation.Y + 1)
gw.Location <- newLocation
Assert.Equal(newLocation, gw.Location)
[<Fact>]
let ``Updates to Bounds.Location take effect`` () =
use gw = new OpenTK.GameWindow()
let oldLocation = gw.Bounds.Location
let newLocation = System.Drawing.Point(oldLocation.X + 1, oldLocation.Y + 1)
let newRect = System.Drawing.Rectangle(newLocation, gw.ClientRectangle.Size)
gw.Bounds <- newRect
Assert.Equal(newRect, gw.Bounds)
[<Fact>]
let ``Location equals Bounds.Location`` () =
use gw = new OpenTK.GameWindow()
Assert.Equal(gw.Location, gw.Bounds.Location)
[<Fact>]
let ``X and Y equals Location`` () =
use gw = new OpenTK.GameWindow()
Assert.Equal(System.Drawing.Point(gw.X, gw.Y), gw.Location)
[<Fact>]
let ``ClientRectangle.Location is zero`` () =
use gw = new OpenTK.GameWindow()
Assert.Equal(System.Drawing.Point.Empty, gw.ClientRectangle.Location)
module Borders =
[<Fact>]
let ``Updates to BorderStyle take effect`` () =
use gw = new OpenTK.GameWindow()
gw.WindowBorder <- WindowBorder.Fixed
Assert.Equal(WindowBorder.Fixed, gw.WindowBorder)
gw.WindowBorder <- WindowBorder.Hidden
Assert.Equal(WindowBorder.Hidden, gw.WindowBorder)
gw.WindowBorder <- WindowBorder.Resizable
Assert.Equal(WindowBorder.Resizable, gw.WindowBorder)
[<Fact>]
let ``Can resize fixed borders`` () =
use gw = new OpenTK.GameWindow()
gw.WindowBorder <- WindowBorder.Fixed
let oldSize = gw.Size
let newSize = System.Drawing.Size(oldSize.Width + 1, oldSize.Height + 1)
gw.Size <- newSize
Assert.Equal(newSize, gw.Size)
[<Fact>]
let ``Can resize hidden borders`` () =
use gw = new OpenTK.GameWindow()
gw.WindowBorder <- WindowBorder.Hidden
let oldSize = gw.Size
let newSize = System.Drawing.Size(oldSize.Width + 1, oldSize.Height + 1)
gw.Size <- newSize
Assert.Equal(newSize, gw.Size)

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,2 @@
FsCheck.Xunit
xunit.assert

View file

@ -14,6 +14,9 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Name>OpenTK.Tests</Name>
<Deterministic>true</Deterministic>
<StartAction>Program</StartAction>
<StartProgram>packages\xunit.runner.console\tools\xunit.console.exe</StartProgram>
<StartArguments>OpenTK.Tests.dll</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>