Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CatLib.Core.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.27130.2036
VisualStudioVersion = 15.0.26430.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CatLib.Core", "src\CatLib.Core\CatLib.Core.csproj", "{4204658E-81FD-4106-A347-890CD369C8A4}"
EndProject
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p align="center"><img width="173" height="57" src="http://catlib.io/images/logo.txt.png"></p>
<p align="center"><img width="173" height="57" src="http://catlib.io/images/logo.txt.png"></p>

<p align="center">
<a href="https://github.com/Catlib/Core/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" title="license-mit" /></a>
Expand Down Expand Up @@ -28,7 +28,7 @@
**使用Nuget安装**

```PM
Install-Package CatLib.Core -Version 1.2.9
Install-Package CatLib.Core -Version 1.2.10
```

**直接下载发布版本**
Expand Down
1 change: 1 addition & 0 deletions src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<Compile Include="..\CatLib.Core\Support\SortSet\SortSet.cs" Link="Support\SortSet\SortSet.cs" />
<Compile Include="..\CatLib.Core\Support\Storage\IStorage.cs" Link="Support\Storage\IStorage.cs" />
<Compile Include="..\CatLib.Core\Support\Storage\MemoryStorage.cs" Link="Support\Storage\MemoryStorage.cs" />
<Compile Include="..\CatLib.Core\Support\Stream\PipelineStream.cs" Link="Support\Stream\PipelineStream.cs" />
<Compile Include="..\CatLib.Core\Support\Stream\StorageStream.cs" Link="Support\Stream\StorageStream.cs" />
<Compile Include="..\CatLib.Core\Support\Template\IManaged.cs" Link="Support\Template\IManaged.cs" />
<Compile Include="..\CatLib.Core\Support\Template\IManager.cs" Link="Support\Template\IManager.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/CatLib.Core.Tests/CatLib.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<Compile Include="Support\RingBuffer\RingBufferTests.cs" />
<Compile Include="Support\SortSet\SortSetTests.cs" />
<Compile Include="Support\Storage\MemoryStorageTests.cs" />
<Compile Include="Support\Stream\PipelineStreamTests.cs" />
<Compile Include="Support\Stream\StorageStreamTests.cs" />
<Compile Include="Support\Template\ManagerTests.cs" />
<Compile Include="Support\Template\SingleManagerTests.cs" />
Expand Down
4 changes: 2 additions & 2 deletions src/CatLib.Core.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@

[assembly: Guid("3c9f4024-910c-4881-a04d-34a6c3a09019")]

[assembly: AssemblyVersion("1.2.9.0")]
[assembly: AssemblyFileVersion("1.2.9.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.10.0")]
2 changes: 1 addition & 1 deletion src/CatLib.Core.Tests/Support/Container/ContainerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ public void TestOverflowParamNum()
{
container.Call(cls, "GetNumber", new object[256]);
}
catch (Exception ex)
catch (Exception)
{
isThrow = true;
}
Expand Down
152 changes: 152 additions & 0 deletions src/CatLib.Core.Tests/Support/Stream/PipelineStreamTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* This file is part of the CatLib package.
*
* (c) Yu Bin <support@catlib.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Document: http://catlib.io/
*/

using System;
using System.IO;
using System.Text;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CatLib.Core.Tests.Support.Stream
{
[TestClass]
public class PipelineStreamTests
{
private PipelineStream stream;

[TestMethod]
public void TestPipeline()
{
stream = new PipelineStream(256);
ThreadPool.QueueUserWorkItem(WriteThread);

var wrote = false;
stream.OnWrote += (_) =>
{
wrote = true;
};
var data = new byte[100];
int read;
var actual = new StringBuilder();
var rand = new Random();
while ((read = stream.Read(data, 0, data.Length)) != 0)
{
var str = Encoding.UTF8.GetString(data, 0, read);
actual.Append(str);
Thread.Sleep(rand.Next(1, 5));
}
stream.Dispose();

var expected = new StringBuilder();
for (var i = 0; i < 1000; i++)
{
expected.Append("0123456789");
}

Assert.AreEqual(expected.ToString(), actual.ToString());
Assert.AreEqual(true, wrote);
}

public void WriteThread(object obj)
{
var data = Encoding.UTF8.GetBytes("0123456789");
for (var i = 0; i < 1000; i++)
{
stream.Write(data, 0, data.Length);
}
stream.Close();
}

[TestMethod]
[ExpectedException(typeof(ObjectDisposedException))]
public void TestClosedAndWrite()
{
var stream = new PipelineStream(256);
Assert.AreEqual(true, stream.CanWrite);
stream.Write(Encoding.UTF8.GetBytes("0123456789"), 0, 10);
stream.Close();
Assert.AreEqual(false, stream.CanWrite);
Assert.AreEqual(true, stream.CanRead);
Assert.AreEqual(true, stream.Closed);
stream.Write(Encoding.UTF8.GetBytes("0123456789"), 0, 10);
}


[TestMethod]
[ExpectedException(typeof(ObjectDisposedException))]
public void TestDisposeAndWrite()
{
var stream = new PipelineStream(256);
Assert.AreEqual(true, stream.CanWrite);
Assert.AreEqual(false, stream.CanRead);
stream.Dispose();
Assert.AreEqual(false, stream.CanWrite);
Assert.AreEqual(false, stream.CanRead);
stream.Write(Encoding.UTF8.GetBytes("0123456789"), 0, 10);
}

[TestMethod]
public void TestCanReadCanWrite()
{
var stream = new PipelineStream(256);
stream.Write(Encoding.UTF8.GetBytes("0123456789"), 0, 10);
Assert.AreEqual(true, stream.CanWrite);
Assert.AreEqual(true, stream.CanRead);
}

[TestMethod]
public void TestCanSeek()
{
var stream = new PipelineStream(256);
Assert.AreEqual(false, stream.CanSeek);
}

[TestMethod]
[ExpectedException(typeof(NotSupportedException))]
public void TestSeek()
{
var stream = new PipelineStream(256);
stream.Seek(0, SeekOrigin.Begin);
}

[TestMethod]
[ExpectedException(typeof(NotSupportedException))]
public void TestSetLength()
{
var stream = new PipelineStream(256);
stream.SetLength(0);
}

[TestMethod]
[ExpectedException(typeof(NotSupportedException))]
public void TestSetPosition()
{
var stream = new PipelineStream(256);
stream.Position = 10;
}

[TestMethod]
[ExpectedException(typeof(NotSupportedException))]
public void TestGetPosition()
{
var stream = new PipelineStream(256);
var pos = stream.Position;
}

[TestMethod]
[ExpectedException(typeof(NotSupportedException))]
public void TestGetLength()
{
var stream = new PipelineStream(256);
var length = stream.Length;
}
}
}
2 changes: 1 addition & 1 deletion src/CatLib.Core.Tests/Support/Template/ManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void TestReleaseExtendAndMake()
return tmp = new TestManagerClass();
});

cls.ReleaseExtend();
cls.RemoveExtend();

ExceptionAssert.Throws<RuntimeException>(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void TestReleaseExtend()
manager.Extend(() => new InterfaceImpl(), "hello");

Assert.AreEqual(true, manager.ContainsExtend("hello"));
manager.ReleaseExtend("hello");
manager.RemoveExtend("hello");
Assert.AreEqual(false, manager.ContainsExtend());
Assert.AreEqual(false, manager.ContainsExtend("hello"));
}
Expand Down
30 changes: 30 additions & 0 deletions src/CatLib.Core.Tests/Support/Util/ArrTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ public void TestMerge()
Assert.AreEqual(3, newArr.Length);
}

[TestMethod]
public void TestMergeNull()
{
var arr1 = new[] { "1", "2" };
string[] arr2 = null;
var arr3 = new[] { "3" };
var newArr = Arr.Merge(arr1, arr2, arr3);
Assert.AreEqual(3, newArr.Length);
var i = 0;
foreach (var result in newArr)
{
Assert.AreEqual((++i).ToString(), result);
}
}

[TestMethod]
public void TestMergeEmpty()
{
var arr1 = new[] { "1", "2" };
var arr2 = new string[0];
var arr3 = new[] { "3" };
var newArr = Arr.Merge(arr1, arr2, arr3);
Assert.AreEqual(3, newArr.Length);
var i = 0;
foreach (var result in newArr)
{
Assert.AreEqual((++i).ToString(), result);
}
}

[TestMethod]
public void TestRandom()
{
Expand Down
47 changes: 47 additions & 0 deletions src/CatLib.Core.Tests/Support/Util/StreamExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,52 @@ public void TestAppendTo()
Assert.AreEqual(11, count);
Assert.AreEqual("Hello world", Encoding.Default.GetString(stream2.GetBuffer(), 0, (int)stream2.Length));
}

[TestMethod]
public void TestStreamToText()
{
var stream1 = new MemoryStream(Encoding.Default.GetBytes("Hello world"));
Assert.AreEqual("Hello world", stream1.ToText());
}

[TestMethod]
public void TestStreamToTextOtherStream()
{
var stream1 = new StorageStream(new MemoryStorage());
stream1.Write(Encoding.Default.GetBytes("Hello world"), 0, 11);
stream1.Seek(0, SeekOrigin.Begin);
Assert.AreEqual("Hello world", stream1.ToText());
}

[TestMethod]
public void TestStreamToTextLarage()
{
var stream1 = new StorageStream(new MemoryStorage());
var builder = new StringBuilder();
for (var i = 0; i < (ThreadStatic.Buffer.Length / 10) + 1; i++)
{
stream1.Write(Encoding.Default.GetBytes("1234567890"), 0, 10);
builder.Append("1234567890");
}
stream1.Seek(0, SeekOrigin.Begin);
Assert.AreEqual(builder.ToString(), stream1.ToText());
}

[TestMethod]
public void TestStreamToTextEmpty()
{
var stream1 = new MemoryStream(0);
Assert.AreEqual(string.Empty, stream1.ToText());
}

[TestMethod]
public void TestStreamClosed()
{
var stream1 = new MemoryStream(0);
Assert.AreEqual(string.Empty, stream1.ToText(null, false));
Assert.AreEqual(true, stream1.CanWrite);
Assert.AreEqual(string.Empty, stream1.ToText());
Assert.AreEqual(false, stream1.CanWrite);
}
}
}
1 change: 1 addition & 0 deletions src/CatLib.Core/CatLib.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<Compile Include="Support\RingBuffer\IRingBuffer.cs" />
<Compile Include="Support\RingBuffer\RingBuffer.cs" />
<Compile Include="Support\Storage\IStorage.cs" />
<Compile Include="Support\Stream\PipelineStream.cs" />
<Compile Include="Support\Stream\StorageStream.cs" />
<Compile Include="Support\Storage\MemoryStorage.cs" />
<Compile Include="Support\Util\Dict.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/CatLib.Core/CatLib/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Application : Container, IApplication, IOriginalDispatcher
/// <summary>
/// 版本号
/// </summary>
private readonly Version version = new Version("1.2.9");
private readonly Version version = new Version("1.2.10");

/// <summary>
/// 框架启动流程
Expand Down
4 changes: 2 additions & 2 deletions src/CatLib.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

[assembly: Guid("4204658e-81fd-4106-a347-890cd369c8a4")]

[assembly: AssemblyVersion("1.2.9.0")]
[assembly: AssemblyFileVersion("1.2.9.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.10.0")]

[assembly: InternalsVisibleTo("Assembly-CSharp-Editor"),
InternalsVisibleTo("Assembly-CSharp-Editor-firstpass"),
Expand Down
Loading