Browse Source

Merge branch 'master' into target-null-value

pull/3261/head
Jumar Macato 7 years ago
committed by GitHub
parent
commit
abd5518230
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      src/Avalonia.Visuals/Media/FontFamily.cs
  2. 34
      src/Avalonia.Visuals/Media/Fonts/FamilyNameCollection.cs
  3. 85
      tests/Avalonia.Styling.UnitTests/SelectorTests_Child.cs
  4. 2
      tests/Avalonia.Styling.UnitTests/SelectorTests_Class.cs
  5. 85
      tests/Avalonia.Styling.UnitTests/SelectorTests_Descendent.cs
  6. 3
      tests/Avalonia.Styling.UnitTests/SelectorTests_Name.cs
  7. 4
      tests/Avalonia.Styling.UnitTests/SelectorTests_Not.cs
  8. 5
      tests/Avalonia.Styling.UnitTests/SelectorTests_OfType.cs
  9. 9
      tests/Avalonia.Styling.UnitTests/SelectorTests_Or.cs
  10. 83
      tests/Avalonia.Styling.UnitTests/TestControlBase.cs
  11. 81
      tests/Avalonia.Styling.UnitTests/TestTemplatedControl.cs

27
src/Avalonia.Visuals/Media/FontFamily.cs

@ -184,36 +184,25 @@ namespace Avalonia.Media
{
unchecked
{
var hash = (int)2186146271;
if (Key != null)
{
hash = (hash * 15768619) ^ Key.GetHashCode();
}
else
{
hash = (hash * 15768619) ^ FamilyNames.GetHashCode();
}
if (Key != null)
{
hash = (hash * 15768619) ^ Key.GetHashCode();
}
return hash;
return ((FamilyNames != null ? FamilyNames.GetHashCode() : 0) * 397) ^ (Key != null ? Key.GetHashCode() : 0);
}
}
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}
if (!(obj is FontFamily other))
{
return false;
}
if (Key != null)
if (!Equals(Key, other.Key))
{
return other.FamilyNames.Equals(FamilyNames) && other.Key.Equals(Key);
return false;
}
return other.FamilyNames.Equals(FamilyNames);

34
src/Avalonia.Visuals/Media/Fonts/FamilyNameCollection.cs

@ -111,7 +111,24 @@ namespace Avalonia.Media.Fonts
/// </returns>
public override int GetHashCode()
{
return ToString().GetHashCode();
if (Count == 0)
{
return 0;
}
unchecked
{
int hash = 17;
for (var i = 0; i < Names.Count; i++)
{
string name = Names[i];
hash = hash * 23 + name.GetHashCode();
}
return hash;
}
}
/// <summary>
@ -128,7 +145,20 @@ namespace Avalonia.Media.Fonts
return false;
}
return other.ToString().Equals(ToString());
if (other.Count != Count)
{
return false;
}
for (int i = 0; i < Count; i++)
{
if (Names[i] != other.Names[i])
{
return false;
}
}
return true;
}
public int Count => Names.Count;

85
tests/Avalonia.Styling.UnitTests/SelectorTests_Child.cs

@ -81,89 +81,12 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal("TestLogical1 > TestLogical3", selector.ToString());
}
public abstract class TestLogical : ILogical, IStyleable
public abstract class TestLogical : Control
{
public TestLogical()
public ILogical LogicalParent
{
Classes = new Classes();
}
public event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged;
public event EventHandler<AvaloniaPropertyChangedEventArgs> InheritablePropertyChanged;
public event EventHandler<LogicalTreeAttachmentEventArgs> AttachedToLogicalTree;
public event EventHandler<LogicalTreeAttachmentEventArgs> DetachedFromLogicalTree;
public Classes Classes { get; }
public string Name { get; set; }
public bool IsAttachedToLogicalTree { get; }
public IAvaloniaReadOnlyList<ILogical> LogicalChildren { get; set; }
public ILogical LogicalParent { get; set; }
public Type StyleKey { get; }
public ITemplatedControl TemplatedParent { get; }
IObservable<IStyleable> IStyleable.StyleDetach { get; }
IAvaloniaReadOnlyList<string> IStyleable.Classes => Classes;
public object GetValue(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public T GetValue<T>(AvaloniaProperty<T> property)
{
throw new NotImplementedException();
}
public void SetValue(AvaloniaProperty property, object value, BindingPriority priority)
{
throw new NotImplementedException();
}
public void SetValue<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind(AvaloniaProperty property, IObservable<object> source, BindingPriority priority)
{
throw new NotImplementedException();
}
public bool IsAnimating(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public bool IsSet(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(AvaloniaProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public void NotifyAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
throw new NotImplementedException();
}
public void NotifyDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
throw new NotImplementedException();
}
public void NotifyResourcesChanged(ResourcesChangedEventArgs e)
{
throw new NotImplementedException();
get => Parent;
set => ((ISetLogicalParent)this).SetParent(value);
}
}

2
tests/Avalonia.Styling.UnitTests/SelectorTests_Class.cs

@ -144,7 +144,7 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal(new[] { true, false }, result);
}
public class Control1 : TestControlBase
public class Control1 : Control
{
}
}

85
tests/Avalonia.Styling.UnitTests/SelectorTests_Descendent.cs

@ -111,89 +111,12 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal("TestLogical1.foo TestLogical3", selector.ToString());
}
public abstract class TestLogical : ILogical, IStyleable
public abstract class TestLogical : Control
{
public TestLogical()
public ILogical LogicalParent
{
Classes = new Classes();
}
public event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged;
public event EventHandler<AvaloniaPropertyChangedEventArgs> InheritablePropertyChanged;
public event EventHandler<LogicalTreeAttachmentEventArgs> AttachedToLogicalTree;
public event EventHandler<LogicalTreeAttachmentEventArgs> DetachedFromLogicalTree;
public Classes Classes { get; }
public string Name { get; set; }
public bool IsAttachedToLogicalTree { get; }
public IAvaloniaReadOnlyList<ILogical> LogicalChildren { get; set; }
public ILogical LogicalParent { get; set; }
public Type StyleKey { get; }
public ITemplatedControl TemplatedParent { get; }
IAvaloniaReadOnlyList<string> IStyleable.Classes => Classes;
IObservable<IStyleable> IStyleable.StyleDetach { get; }
public object GetValue(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public T GetValue<T>(AvaloniaProperty<T> property)
{
throw new NotImplementedException();
}
public void SetValue(AvaloniaProperty property, object value, BindingPriority priority)
{
throw new NotImplementedException();
}
public void SetValue<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind(AvaloniaProperty property, IObservable<object> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public bool IsAnimating(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public bool IsSet(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(AvaloniaProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public void NotifyAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
throw new NotImplementedException();
}
public void NotifyDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
throw new NotImplementedException();
}
public void NotifyResourcesChanged(ResourcesChangedEventArgs e)
{
throw new NotImplementedException();
get => Parent;
set => ((ISetLogicalParent)this).SetParent(value);
}
}

3
tests/Avalonia.Styling.UnitTests/SelectorTests_Name.cs

@ -1,6 +1,7 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Controls;
using Moq;
using Xunit;
@ -52,7 +53,7 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal("Control1#foo", target.ToString());
}
public class Control1 : TestControlBase
public class Control1 : Control
{
}
}

4
tests/Avalonia.Styling.UnitTests/SelectorTests_Not.cs

@ -103,11 +103,11 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal(typeof(Control1), target.TargetType);
}
public class Control1 : TestControlBase
public class Control1 : Control
{
}
public class Control2 : TestControlBase
public class Control2 : Control
{
}
}

5
tests/Avalonia.Styling.UnitTests/SelectorTests_OfType.cs

@ -1,6 +1,7 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Controls;
using Moq;
using Xunit;
@ -44,11 +45,11 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal(SelectorMatchResult.AlwaysThisType, target.Match(control).Result);
}
public class Control1 : TestControlBase
public class Control1 : Control
{
}
public class Control2 : TestControlBase
public class Control2 : Control
{
}
}

9
tests/Avalonia.Styling.UnitTests/SelectorTests_Or.cs

@ -1,6 +1,7 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Controls;
using Xunit;
namespace Avalonia.Styling.UnitTests
@ -78,7 +79,7 @@ namespace Avalonia.Styling.UnitTests
default(Selector).OfType<Control1>().Class("foo"),
default(Selector).OfType<Control2>().Class("bar"));
Assert.Equal(typeof(TestControlBase), target.TargetType);
Assert.Equal(typeof(Control), target.TargetType);
}
[Fact]
@ -91,15 +92,15 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal(null, target.TargetType);
}
public class Control1 : TestControlBase
public class Control1 : Control
{
}
public class Control2 : TestControlBase
public class Control2 : Control
{
}
public class Control3 : TestControlBase
public class Control3 : Control
{
}
}

83
tests/Avalonia.Styling.UnitTests/TestControlBase.cs

@ -1,83 +0,0 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Reactive;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Data;
namespace Avalonia.Styling.UnitTests
{
public class TestControlBase : IStyleable
{
public TestControlBase()
{
Classes = new Classes();
SubscribeCheckObservable = new TestObservable();
}
#pragma warning disable CS0067 // Event not used
public event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged;
public event EventHandler<AvaloniaPropertyChangedEventArgs> InheritablePropertyChanged;
#pragma warning restore CS0067
public string Name { get; set; }
public virtual Classes Classes { get; set; }
public Type StyleKey => GetType();
public TestObservable SubscribeCheckObservable { get; private set; }
public ITemplatedControl TemplatedParent
{
get;
set;
}
IAvaloniaReadOnlyList<string> IStyleable.Classes => Classes;
IObservable<IStyleable> IStyleable.StyleDetach { get; }
public object GetValue(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public T GetValue<T>(AvaloniaProperty<T> property)
{
throw new NotImplementedException();
}
public void SetValue(AvaloniaProperty property, object value, BindingPriority priority)
{
throw new NotImplementedException();
}
public void SetValue<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public bool IsAnimating(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public bool IsSet(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public IDisposable Bind(AvaloniaProperty property, IObservable<object> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(AvaloniaProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
}
}

81
tests/Avalonia.Styling.UnitTests/TestTemplatedControl.cs

@ -1,81 +0,0 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Reactive;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Data;
namespace Avalonia.Styling.UnitTests
{
public abstract class TestTemplatedControl : ITemplatedControl, IStyleable
{
public event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged;
public event EventHandler<AvaloniaPropertyChangedEventArgs> InheritablePropertyChanged;
public abstract Classes Classes
{
get;
}
public abstract string Name
{
get;
}
public abstract Type StyleKey
{
get;
}
public abstract ITemplatedControl TemplatedParent
{
get;
}
IAvaloniaReadOnlyList<string> IStyleable.Classes => Classes;
IObservable<IStyleable> IStyleable.StyleDetach { get; }
public object GetValue(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public T GetValue<T>(AvaloniaProperty<T> property)
{
throw new NotImplementedException();
}
public void SetValue(AvaloniaProperty property, object value, BindingPriority priority)
{
throw new NotImplementedException();
}
public void SetValue<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind(AvaloniaProperty property, IObservable<object> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(AvaloniaProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public bool IsAnimating(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public bool IsSet(AvaloniaProperty property)
{
throw new NotImplementedException();
}
}
}
Loading…
Cancel
Save