-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Microsoft.Data.Sqlite: Test against e_sqlcipher and winsqlite3
- Loading branch information
Showing
11 changed files
with
211 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 14 additions & 2 deletions
16
src/Microsoft.Data.Sqlite.Core/Extensions/SQLitePCLExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
|
||
// ReSharper disable once CheckNamespace | ||
// ReSharper disable InconsistentNaming | ||
namespace SQLitePCL | ||
{ | ||
internal static class SQLitePCLExtensions | ||
{ | ||
public static bool EncryptionNotSupported() | ||
=> raw.GetNativeLibraryName() == "e_sqlite3"; | ||
private static readonly Dictionary<string, bool> _knownLibraries = new Dictionary<string, bool> | ||
{ | ||
{ "e_sqlcipher", true }, | ||
{ "e_sqlite3", false}, | ||
{ "sqlcipher", true }, | ||
{ "winsqlite3", false } | ||
}; | ||
|
||
public static bool? EncryptionSupported() | ||
=> _knownLibraries.TryGetValue(raw.GetNativeLibraryName(), out var supported) | ||
? supported | ||
: default(bool?); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.e_sqlcipher.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
<DefineConstants>$(DefineConstants);E_SQLCIPHER</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Microsoft.Data.Sqlite.Core\Microsoft.Data.Sqlite.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="$(SQLitePCLRawBundleESqlcipherPackageVersion)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
16 changes: 16 additions & 0 deletions
16
test/Microsoft.Data.Sqlite.Tests/Microsoft.Data.Sqlite.winsqlite3.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
<DefineConstants>$(DefineConstants);WINSQLITE3</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Microsoft.Data.Sqlite.Core\Microsoft.Data.Sqlite.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="SQLitePCLRaw.bundle_winsqlite3" Version="$(SQLitePCLRawBundleWinsqlite3PackageVersion)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
test/Microsoft.Data.Sqlite.Tests/TestUtilities/SqliteTestFramework.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
using System; | ||
|
||
#if WINSQLITE3 | ||
using System.Runtime.InteropServices; | ||
#endif | ||
|
||
[assembly: TestFramework( | ||
"Microsoft.Data.Sqlite.Tests.TestUtilities.SqliteTestFramework", | ||
#if E_SQLITE3 | ||
"Microsoft.Data.Sqlite.Tests")] | ||
#elif E_SQLCIPHER | ||
"Microsoft.Data.Sqlite.e_sqlcipher.Tests")] | ||
#elif WINSQLITE3 | ||
"Microsoft.Data.Sqlite.winsqlite3.Tests")] | ||
#else | ||
#error Unexpected native library | ||
#endif | ||
|
||
namespace Microsoft.Data.Sqlite.Tests.TestUtilities | ||
{ | ||
class SqliteTestFramework : XunitTestFramework | ||
{ | ||
protected SqliteTestFramework(IMessageSink diagnosticMessageSink) | ||
: base(diagnosticMessageSink) | ||
{ | ||
} | ||
|
||
protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName) | ||
=> new SqliteTestFrameworkExecutor(assemblyName, SourceInformationProvider, DiagnosticMessageSink); | ||
} | ||
|
||
class SqliteTestFrameworkExecutor : XunitTestFrameworkExecutor | ||
{ | ||
public SqliteTestFrameworkExecutor( | ||
AssemblyName assemblyName, | ||
ISourceInformationProvider sourceInformationProvider, | ||
IMessageSink diagnosticMessageSink) | ||
: base(assemblyName, sourceInformationProvider, diagnosticMessageSink) | ||
{ | ||
} | ||
|
||
protected override async void RunTestCases( | ||
IEnumerable<IXunitTestCase> testCases, | ||
IMessageSink executionMessageSink, | ||
ITestFrameworkExecutionOptions executionOptions) | ||
{ | ||
using var assemblyRunner = new SqliteTestAssemblyRunner( | ||
TestAssembly, | ||
testCases, | ||
DiagnosticMessageSink, | ||
executionMessageSink, | ||
executionOptions); | ||
await assemblyRunner.RunAsync(); | ||
} | ||
} | ||
|
||
class SqliteTestAssemblyRunner : XunitTestAssemblyRunner | ||
{ | ||
public SqliteTestAssemblyRunner( | ||
ITestAssembly testAssembly, | ||
IEnumerable<IXunitTestCase> testCases, | ||
IMessageSink diagnosticMessageSink, | ||
IMessageSink executionMessageSink, | ||
ITestFrameworkExecutionOptions executionOptions) | ||
: base(testAssembly, testCases, diagnosticMessageSink, executionMessageSink, executionOptions) | ||
{ | ||
} | ||
|
||
|
||
protected override Task<RunSummary> RunTestCollectionAsync( | ||
IMessageBus messageBus, | ||
ITestCollection testCollection, | ||
IEnumerable<IXunitTestCase> testCases, | ||
CancellationTokenSource cancellationTokenSource) | ||
{ | ||
#if WINSQLITE3 | ||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
return SkipAll("winsqlite3 isn't supported on " + RuntimeInformation.OSDescription); | ||
} | ||
|
||
#endif | ||
var version = new SqliteConnection().ServerVersion; | ||
if (new Version(version) < new Version(3, 16, 0)) | ||
{ | ||
return SkipAll("SQLite " + version + " isn't supported. Upgrade to 3.16.0 or higher"); | ||
} | ||
|
||
return new XunitTestCollectionRunner( | ||
testCollection, | ||
testCases, | ||
DiagnosticMessageSink, | ||
messageBus, | ||
TestCaseOrderer, | ||
new ExceptionAggregator(Aggregator), | ||
cancellationTokenSource) | ||
.RunAsync(); | ||
|
||
Task<RunSummary> SkipAll(string reason) | ||
{ | ||
var count = 0; | ||
foreach (var testCase in testCases) | ||
{ | ||
messageBus.QueueMessage(new TestSkipped(new XunitTest(testCase, testCase.DisplayName), reason)); | ||
count++; | ||
} | ||
|
||
return Task.FromResult(new RunSummary { Skipped = count, Total = count }); | ||
} | ||
} | ||
} | ||
} |