Skip to content

Commit

Permalink
Add UWP test runner (#1358)
Browse files Browse the repository at this point in the history
* Add WIP test runner

* Fix migration tests

* Fix refresh tests

* fixes toward supporting .NET Native

* Fix .NET Native byte array accessor

* Fix tests for .NET native

* Make RealmList<T> public

Closes #1349

* Update runner to a one that logs

* Make more things public

* Revert tabs on object_cs

* Fix windows tests

* remove leftover fody

* Update UWP runner's Fody
  • Loading branch information
nirinchev authored May 3, 2017
1 parent 4d27052 commit 24f1ca3
Show file tree
Hide file tree
Showing 43 changed files with 767 additions and 313 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ ClientBin/
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
Expand Down Expand Up @@ -208,3 +207,4 @@ Resource.designer.cs
Mono.Cecil.dll
Realm.BuildTasks.dll
*.nuget.targets
*.nuget.props
35 changes: 32 additions & 3 deletions Realm.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.3
VisualStudioVersion = 15.0.26403.7
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WeaverTests", "WeaverTests", "{64B2E00E-D5D7-474B-9947-6ABC51070E7B}"
EndProject
Expand Down Expand Up @@ -59,17 +59,21 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.iOS", "Tests\Tests.iO
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Android", "Tests\Tests.Android\Tests.Android.csproj", "{AD7B78B0-AE51-4FB7-9B11-4E22A2B538CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.UWP", "Tests\Tests.UWP\Tests.UWP.csproj", "{159A55AF-9531-4107-8444-CA9C96107EF5}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Tests\Tests.Shared\Tests.Shared.projitems*{06146619-d21c-414c-bfe3-2f59acba412e}*SharedItemsImports = 13
DataBinding\Realm.DataBinding.TypeDelegator\DataBinding.TypeDelegator.projitems*{0a266cac-ef4a-4bb0-a3d9-f2084f1b1012}*SharedItemsImports = 4
Tests\Tests.Shared\Tests.Shared.projitems*{159a55af-9531-4107-8444-ca9c96107ef5}*SharedItemsImports = 4
DataBinding\Realm.DataBinding.TypeDelegator\DataBinding.TypeDelegator.projitems*{336ed3ca-5344-4f04-966c-ca170afc3348}*SharedItemsImports = 4
DataBinding\Realm.DataBinding.TypeDelegator\DataBinding.TypeDelegator.projitems*{519e6d0a-7dcf-45f6-a40a-0260eaea0df7}*SharedItemsImports = 13
Tests\Tests.Shared\Tests.Shared.projitems*{ad7b78b0-ae51-4fb7-9b11-4e22a2b538ca}*SharedItemsImports = 4
Tests\Tests.Sync.Shared\Tests.Sync.Shared.projitems*{ad7b78b0-ae51-4fb7-9b11-4e22a2b538ca}*SharedItemsImports = 4
Tests\Tests.Shared\Tests.Shared.projitems*{bfc1c1b7-2864-4456-9dec-309a3f006b66}*SharedItemsImports = 4
Tests\Tests.Sync.Shared\Tests.Sync.Shared.projitems*{c81983e0-58a0-4d67-b0d0-ae91aba71a2c}*SharedItemsImports = 13
Tests\Tests.Shared\Tests.Shared.projitems*{d2ced8f0-7a76-454d-b5f7-9e8b9fe6a58e}*SharedItemsImports = 4
Tests\Tests.Sync.Shared\Tests.Sync.Shared.projitems*{d2ced8f0-7a76-454d-b5f7-9e8b9fe6a58e}*SharedItemsImports = 4
Shared\Tests.Shared\Tests.Shared.projitems*{ed17479c-2cfe-4e6d-a592-82c491ffbe4e}*SharedItemsImports = 4
Shared\Tests.Sync.Shared\Tests.Sync.Shared.projitems*{ed17479c-2cfe-4e6d-a592-82c491ffbe4e}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -546,6 +550,30 @@ Global
{AD7B78B0-AE51-4FB7-9B11-4E22A2B538CA}.Release|x86.ActiveCfg = Release|Any CPU
{AD7B78B0-AE51-4FB7-9B11-4E22A2B538CA}.Release|x86.Build.0 = Release|Any CPU
{AD7B78B0-AE51-4FB7-9B11-4E22A2B538CA}.Release|x86.Deploy.0 = Release|Any CPU
{159A55AF-9531-4107-8444-CA9C96107EF5}.Debug|Any CPU.ActiveCfg = Debug|x86
{159A55AF-9531-4107-8444-CA9C96107EF5}.Debug|ARM.ActiveCfg = Debug|ARM
{159A55AF-9531-4107-8444-CA9C96107EF5}.Debug|ARM.Build.0 = Debug|ARM
{159A55AF-9531-4107-8444-CA9C96107EF5}.Debug|ARM.Deploy.0 = Debug|ARM
{159A55AF-9531-4107-8444-CA9C96107EF5}.Debug|iPhone.ActiveCfg = Debug|x86
{159A55AF-9531-4107-8444-CA9C96107EF5}.Debug|iPhoneSimulator.ActiveCfg = Debug|x86
{159A55AF-9531-4107-8444-CA9C96107EF5}.Debug|x64.ActiveCfg = Debug|x64
{159A55AF-9531-4107-8444-CA9C96107EF5}.Debug|x64.Build.0 = Debug|x64
{159A55AF-9531-4107-8444-CA9C96107EF5}.Debug|x64.Deploy.0 = Debug|x64
{159A55AF-9531-4107-8444-CA9C96107EF5}.Debug|x86.ActiveCfg = Debug|x86
{159A55AF-9531-4107-8444-CA9C96107EF5}.Debug|x86.Build.0 = Debug|x86
{159A55AF-9531-4107-8444-CA9C96107EF5}.Debug|x86.Deploy.0 = Debug|x86
{159A55AF-9531-4107-8444-CA9C96107EF5}.Release|Any CPU.ActiveCfg = Release|x86
{159A55AF-9531-4107-8444-CA9C96107EF5}.Release|ARM.ActiveCfg = Release|ARM
{159A55AF-9531-4107-8444-CA9C96107EF5}.Release|ARM.Build.0 = Release|ARM
{159A55AF-9531-4107-8444-CA9C96107EF5}.Release|ARM.Deploy.0 = Release|ARM
{159A55AF-9531-4107-8444-CA9C96107EF5}.Release|iPhone.ActiveCfg = Release|x86
{159A55AF-9531-4107-8444-CA9C96107EF5}.Release|iPhoneSimulator.ActiveCfg = Release|x86
{159A55AF-9531-4107-8444-CA9C96107EF5}.Release|x64.ActiveCfg = Release|x64
{159A55AF-9531-4107-8444-CA9C96107EF5}.Release|x64.Build.0 = Release|x64
{159A55AF-9531-4107-8444-CA9C96107EF5}.Release|x64.Deploy.0 = Release|x64
{159A55AF-9531-4107-8444-CA9C96107EF5}.Release|x86.ActiveCfg = Release|x86
{159A55AF-9531-4107-8444-CA9C96107EF5}.Release|x86.Build.0 = Release|x86
{159A55AF-9531-4107-8444-CA9C96107EF5}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -574,5 +602,6 @@ Global
{F7D3FB29-7D55-4703-AD6A-0E43758E77A4} = {A24C8BAE-3B43-472C-9609-8AB97180CB4F}
{D2CED8F0-7A76-454D-B5F7-9E8B9FE6A58E} = {D10BE048-9C20-4B8B-BE5B-48CC55F8BB07}
{AD7B78B0-AE51-4FB7-9B11-4E22A2B538CA} = {D10BE048-9C20-4B8B-BE5B-48CC55F8BB07}
{159A55AF-9531-4107-8444-CA9C96107EF5} = {D10BE048-9C20-4B8B-BE5B-48CC55F8BB07}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion Realm/Realm.Sync/Realm.Sync.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down
6 changes: 5 additions & 1 deletion Realm/Realm/Dynamic/DynamicRealmObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
//
////////////////////////////////////////////////////////////////////////////

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Linq.Expressions;

namespace Realms.Dynamic
{
internal class DynamicRealmObject : RealmObject, IDynamicMetaObjectProvider
[EditorBrowsable(EditorBrowsableState.Never)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented")]
public class DynamicRealmObject : RealmObject, IDynamicMetaObjectProvider
{
public DynamicMetaObject GetMetaObject(Expression parameter)
{
Expand Down
32 changes: 23 additions & 9 deletions Realm/Realm/Handles/ObjectHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static extern IntPtr set_binary(ObjectHandle handle, IntPtr propertyIndex

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "object_get_binary", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr get_binary(ObjectHandle handle, IntPtr propertyIndex,
out IntPtr retBuffer, out int retBufferLength, out NativeException ex);
IntPtr buffer, IntPtr bufferLength, [MarshalAs(UnmanagedType.I1)] out bool is_null, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "object_remove_row", CallingConvention = CallingConvention.Cdecl)]
public static extern void remove_row(ObjectHandle handle, RealmHandle realmHandle, out NativeException ex);
Expand Down Expand Up @@ -519,20 +519,34 @@ public unsafe void SetByteArray(IntPtr propertyIndex, byte[] value)

public byte[] GetByteArray(IntPtr propertyIndex)
{
return GetByteArrayBuffer(propertyIndex, 0);
}

private unsafe byte[] GetByteArrayBuffer(IntPtr propertyIndex, int size)
{
// Initially called with size = 0, we make a native call just to get the size of the buffer.
var bytes = new byte[size];
bool isNull;
NativeException nativeException;
int bufferSize;
IntPtr buffer;
var hasValue = NativeMethods.get_binary(this, propertyIndex, out buffer, out bufferSize, out nativeException) != IntPtr.Zero;

int actualSize;
fixed (byte* buffer = bytes)
{
actualSize = (int)NativeMethods.get_binary(this, propertyIndex, (IntPtr)buffer, (IntPtr)size, out isNull, out nativeException);
}
nativeException.ThrowIfNecessary();

if (hasValue)
if (isNull)
{
return null;
}

if (actualSize > size)
{
var bytes = new byte[bufferSize];
Marshal.Copy(buffer, bytes, 0, bufferSize);
return bytes;
return GetByteArrayBuffer(propertyIndex, actualSize);
}

return null;
return bytes;
}

public void RemoveFromRealm(SharedRealmHandle realmHandle)
Expand Down
4 changes: 2 additions & 2 deletions Realm/Realm/Linq/RealmResults.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 Realm Inc.
//
Expand Down Expand Up @@ -64,7 +64,7 @@ public QueryHandle CreateQuery()
return ResultsHandle.CreateQuery();
}

protected override CollectionHandleBase CreateHandle()
internal override CollectionHandleBase CreateHandle()
{
if (_handle != null)
{
Expand Down
57 changes: 45 additions & 12 deletions Realm/Realm/Linq/RealmResultsVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Realms
{
internal class RealmResultsVisitor : ExpressionVisitor
{
private Realm _realm;
private readonly Realm _realm;
private readonly RealmObject.Metadata _metadata;

internal QueryHandle CoreQueryHandle; // set when recurse down to VisitConstant
Expand Down Expand Up @@ -140,7 +140,7 @@ private void AddSort(LambdaExpression lambda, bool isStarting, bool ascending)
OptionalSortDescriptorBuilder.AddClause(propertyChain, ascending);
}

private IEnumerable<Tuple<Type, string>> TraverseSort(MemberExpression expression)
private static IEnumerable<Tuple<Type, string>> TraverseSort(MemberExpression expression)
{
var chain = new List<Tuple<Type, string>>();

Expand Down Expand Up @@ -359,33 +359,33 @@ internal override Expression VisitMethodCall(MethodCallExpression m)
// For extension methods, that should be 1
var stringArgumentIndex = 0;

if (m.Method == Methods.String.Contains.Value)
if (AreMethodsSame(m.Method, Methods.String.Contains.Value))
{
queryMethod = (q, c, v) => q.StringContains(c, v, caseSensitive: true);
}
else if (m.Method == Methods.String.ContainsStringComparison.Value)
else if (AreMethodsSame(m.Method, Methods.String.ContainsStringComparison.Value))
{
member = m.Arguments[0] as MemberExpression;
stringArgumentIndex = 1;
queryMethod = (q, c, v) => q.StringContains(c, v, GetComparisonCaseSensitive(m));
}
else if (m.Method == Methods.String.StartsWith.Value)
else if (AreMethodsSame(m.Method, Methods.String.StartsWith.Value))
{
queryMethod = (q, c, v) => q.StringStartsWith(c, v, caseSensitive: true);
}
else if (m.Method == Methods.String.StartsWithStringComparison.Value)
else if (AreMethodsSame(m.Method, Methods.String.StartsWithStringComparison.Value))
{
queryMethod = (q, c, v) => q.StringStartsWith(c, v, GetComparisonCaseSensitive(m));
}
else if (m.Method == Methods.String.EndsWith.Value)
else if (AreMethodsSame(m.Method, Methods.String.EndsWith.Value))
{
queryMethod = (q, c, v) => q.StringEndsWith(c, v, caseSensitive: true);
}
else if (m.Method == Methods.String.EndsWithStringComparison.Value)
else if (AreMethodsSame(m.Method, Methods.String.EndsWithStringComparison.Value))
{
queryMethod = (q, c, v) => q.StringEndsWith(c, v, GetComparisonCaseSensitive(m));
}
else if (m.Method == Methods.String.IsNullOrEmpty.Value)
else if (AreMethodsSame(m.Method, Methods.String.IsNullOrEmpty.Value))
{
member = m.Arguments.SingleOrDefault() as MemberExpression;
if (member == null)
Expand All @@ -402,15 +402,15 @@ internal override Expression VisitMethodCall(MethodCallExpression m)
CoreQueryHandle.GroupEnd();
return m;
}
else if (m.Method == Methods.String.EqualsMethod.Value)
else if (AreMethodsSame(m.Method, Methods.String.EqualsMethod.Value))
{
queryMethod = (q, c, v) => q.StringEqual(c, v, caseSensitive: true);
}
else if (m.Method == Methods.String.EqualsStringComparison.Value)
else if (AreMethodsSame(m.Method, Methods.String.EqualsStringComparison.Value))
{
queryMethod = (q, c, v) => q.StringEqual(c, v, GetComparisonCaseSensitive(m));
}
else if (m.Method == Methods.String.Like.Value)
else if (AreMethodsSame(m.Method, Methods.String.Like.Value))
{
member = m.Arguments[0] as MemberExpression;
stringArgumentIndex = 1;
Expand Down Expand Up @@ -449,6 +449,39 @@ internal override Expression VisitMethodCall(MethodCallExpression m)
throw new NotSupportedException($"The method '{m.Method.Name}' is not supported");
}

// Compares two methods for equality. .NET Native's == doesn't return expected results.
private static bool AreMethodsSame(MethodInfo first, MethodInfo second)
{
if (first == second)
{
return true;
}

if (first.Name != second.Name ||
first.DeclaringType != second.DeclaringType)
{
return false;
}

var firstParameters = first.GetParameters();
var secondParameters = second.GetParameters();

if (firstParameters.Length != secondParameters.Length)
{
return false;
}

for (var i = 0; i < firstParameters.Length; i++)
{
if (firstParameters[i].ParameterType != secondParameters[i].ParameterType)
{
return false;
}
}

return true;
}

internal override Expression VisitUnary(UnaryExpression u)
{
switch (u.NodeType)
Expand Down
15 changes: 11 additions & 4 deletions Realm/Realm/Native/NativeCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ public static unsafe void Initialize()

if (platform.ToString() == "Win32NT")
{
var assemblyLocation = Path.GetDirectoryName((string)assemblyLocationPI.GetValue(typeof(NativeCommon).GetTypeInfo().Assembly));
var architecture = InteropConfig.Is64BitProcess ? "x64" : "x86";
var path = Path.Combine(assemblyLocation, "lib", "win32", architecture) + Path.PathSeparator + Environment.GetEnvironmentVariable("PATH");
Environment.SetEnvironmentVariable("PATH", path);
try
{
var assemblyLocation = Path.GetDirectoryName((string)assemblyLocationPI.GetValue(typeof(NativeCommon).GetTypeInfo().Assembly));
var architecture = InteropConfig.Is64BitProcess ? "x64" : "x86";
var path = Path.Combine(assemblyLocation, "lib", "win32", architecture) + Path.PathSeparator + Environment.GetEnvironmentVariable("PATH");
Environment.SetEnvironmentVariable("PATH", path);
}
catch (PlatformNotSupportedException)
{
// Thrown on UWP
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion Realm/Realm/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
[assembly: InternalsVisibleTo("Tests.XamarinAndroid")]
[assembly: InternalsVisibleTo("Tests.XamarinIOS")]
[assembly: InternalsVisibleTo("Tests.iOS")]
[assembly: InternalsVisibleTo("Tests.Android")]
[assembly: InternalsVisibleTo("Tests.Android")]
[assembly: InternalsVisibleTo("Tests.UWP")]
2 changes: 1 addition & 1 deletion Realm/Realm/Realm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public override int GetHashCode()
{
ThrowIfDisposed();

return (int)SharedRealmHandle.DangerousGetHandle();
return (int)((long)SharedRealmHandle.DangerousGetHandle() % int.MaxValue);
}

private TableHandle GetTable(ObjectSchema schema)
Expand Down
18 changes: 11 additions & 7 deletions Realm/Realm/RealmCollectionBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 Realm Inc.
//
Expand All @@ -22,12 +22,15 @@
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.InteropServices;

namespace Realms
{
internal abstract class RealmCollectionBase<T>
[EditorBrowsable(EditorBrowsableState.Never)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented")]
public abstract class RealmCollectionBase<T>
: NotificationsHelper.INotifiable,
IRealmCollection<T>,
INotifyCollectionChanged,
Expand All @@ -36,6 +39,7 @@ internal abstract class RealmCollectionBase<T>
IThreadConfined
{
private readonly List<NotificationCallbackDelegate<T>> _callbacks = new List<NotificationCallbackDelegate<T>>();
internal readonly RealmObject.Metadata Metadata;

private NotificationTokenHandle _notificationToken;

Expand Down Expand Up @@ -92,18 +96,18 @@ public int Count

public Schema.ObjectSchema ObjectSchema => Metadata.Schema;

public RealmObject.Metadata Metadata { get; }
RealmObject.Metadata IThreadConfined.Metadata => Metadata;

public bool IsManaged => Realm != null;

public bool IsValid => Handle.Value.IsValid;

IThreadConfinedHandle IThreadConfined.Handle => Handle.Value;

protected readonly Realm Realm;
protected readonly Lazy<CollectionHandleBase> Handle;
internal readonly Realm Realm;
internal readonly Lazy<CollectionHandleBase> Handle;

protected RealmCollectionBase(Realm realm, RealmObject.Metadata metadata)
internal RealmCollectionBase(Realm realm, RealmObject.Metadata metadata)
{
Realm = realm;
Handle = new Lazy<CollectionHandleBase>(CreateHandle);
Expand All @@ -115,7 +119,7 @@ protected RealmCollectionBase(Realm realm, RealmObject.Metadata metadata)
UnsubscribeFromNotifications();
}

protected abstract CollectionHandleBase CreateHandle();
internal abstract CollectionHandleBase CreateHandle();

public T this[int index]
{
Expand Down
Loading

0 comments on commit 24f1ca3

Please sign in to comment.