Skip to content

Commit 834faef

Browse files
author
喵喵大人
authored
Merge pull request #43 from CatLib/feature/1.2.10
Feature/1.2.10
2 parents 378149e + 4dd813b commit 834faef

File tree

16 files changed

+653
-12
lines changed

16 files changed

+653
-12
lines changed

CatLib.Core.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27130.2036
4+
VisualStudioVersion = 15.0.26430.4
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CatLib.Core", "src\CatLib.Core\CatLib.Core.csproj", "{4204658E-81FD-4106-A347-890CD369C8A4}"
77
EndProject

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<p align="center"><img width="173" height="57" src="http://catlib.io/images/logo.txt.png"></p>
1+
<p align="center"><img width="173" height="57" src="http://catlib.io/images/logo.txt.png"></p>
22

33
<p align="center">
44
<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>
@@ -28,7 +28,7 @@
2828
**使用Nuget安装**
2929

3030
```PM
31-
Install-Package CatLib.Core -Version 1.2.9
31+
Install-Package CatLib.Core -Version 1.2.10
3232
```
3333

3434
**直接下载发布版本**

src/CatLib.Core.Tests/CatLib.Core.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<Compile Include="Support\RingBuffer\RingBufferTests.cs" />
5353
<Compile Include="Support\SortSet\SortSetTests.cs" />
5454
<Compile Include="Support\Storage\MemoryStorageTests.cs" />
55+
<Compile Include="Support\Stream\PipelineStreamTests.cs" />
5556
<Compile Include="Support\Stream\StorageStreamTests.cs" />
5657
<Compile Include="Support\Template\ManagerTests.cs" />
5758
<Compile Include="Support\Template\SingleManagerTests.cs" />

src/CatLib.Core.Tests/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525

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

28-
[assembly: AssemblyVersion("1.2.9.0")]
29-
[assembly: AssemblyFileVersion("1.2.9.0")]
28+
[assembly: AssemblyVersion("1.2.0.0")]
29+
[assembly: AssemblyFileVersion("1.2.10.0")]

src/CatLib.Core.Tests/Support/Container/ContainerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ public void TestOverflowParamNum()
742742
{
743743
container.Call(cls, "GetNumber", new object[256]);
744744
}
745-
catch (Exception ex)
745+
catch (Exception)
746746
{
747747
isThrow = true;
748748
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* This file is part of the CatLib package.
3+
*
4+
* (c) Yu Bin <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Document: http://catlib.io/
10+
*/
11+
12+
using System;
13+
using System.IO;
14+
using System.Text;
15+
using System.Threading;
16+
using Microsoft.VisualStudio.TestTools.UnitTesting;
17+
18+
namespace CatLib.Core.Tests.Support.Stream
19+
{
20+
[TestClass]
21+
public class PipelineStreamTests
22+
{
23+
private PipelineStream stream;
24+
25+
[TestMethod]
26+
public void TestPipeline()
27+
{
28+
stream = new PipelineStream(256);
29+
ThreadPool.QueueUserWorkItem(WriteThread);
30+
31+
var wrote = false;
32+
stream.OnWrote += (_) =>
33+
{
34+
wrote = true;
35+
};
36+
var data = new byte[100];
37+
int read;
38+
var actual = new StringBuilder();
39+
var rand = new Random();
40+
while ((read = stream.Read(data, 0, data.Length)) != 0)
41+
{
42+
var str = Encoding.UTF8.GetString(data, 0, read);
43+
actual.Append(str);
44+
Thread.Sleep(rand.Next(1, 5));
45+
}
46+
stream.Dispose();
47+
48+
var expected = new StringBuilder();
49+
for (var i = 0; i < 1000; i++)
50+
{
51+
expected.Append("0123456789");
52+
}
53+
54+
Assert.AreEqual(expected.ToString(), actual.ToString());
55+
Assert.AreEqual(true, wrote);
56+
}
57+
58+
public void WriteThread(object obj)
59+
{
60+
var data = Encoding.UTF8.GetBytes("0123456789");
61+
for (var i = 0; i < 1000; i++)
62+
{
63+
stream.Write(data, 0, data.Length);
64+
}
65+
stream.Close();
66+
}
67+
68+
[TestMethod]
69+
[ExpectedException(typeof(ObjectDisposedException))]
70+
public void TestClosedAndWrite()
71+
{
72+
var stream = new PipelineStream(256);
73+
Assert.AreEqual(true, stream.CanWrite);
74+
stream.Write(Encoding.UTF8.GetBytes("0123456789"), 0, 10);
75+
stream.Close();
76+
Assert.AreEqual(false, stream.CanWrite);
77+
Assert.AreEqual(true, stream.CanRead);
78+
Assert.AreEqual(true, stream.Closed);
79+
stream.Write(Encoding.UTF8.GetBytes("0123456789"), 0, 10);
80+
}
81+
82+
83+
[TestMethod]
84+
[ExpectedException(typeof(ObjectDisposedException))]
85+
public void TestDisposeAndWrite()
86+
{
87+
var stream = new PipelineStream(256);
88+
Assert.AreEqual(true, stream.CanWrite);
89+
Assert.AreEqual(false, stream.CanRead);
90+
stream.Dispose();
91+
Assert.AreEqual(false, stream.CanWrite);
92+
Assert.AreEqual(false, stream.CanRead);
93+
stream.Write(Encoding.UTF8.GetBytes("0123456789"), 0, 10);
94+
}
95+
96+
[TestMethod]
97+
public void TestCanReadCanWrite()
98+
{
99+
var stream = new PipelineStream(256);
100+
stream.Write(Encoding.UTF8.GetBytes("0123456789"), 0, 10);
101+
Assert.AreEqual(true, stream.CanWrite);
102+
Assert.AreEqual(true, stream.CanRead);
103+
}
104+
105+
[TestMethod]
106+
public void TestCanSeek()
107+
{
108+
var stream = new PipelineStream(256);
109+
Assert.AreEqual(false, stream.CanSeek);
110+
}
111+
112+
[TestMethod]
113+
[ExpectedException(typeof(NotSupportedException))]
114+
public void TestSeek()
115+
{
116+
var stream = new PipelineStream(256);
117+
stream.Seek(0, SeekOrigin.Begin);
118+
}
119+
120+
[TestMethod]
121+
[ExpectedException(typeof(NotSupportedException))]
122+
public void TestSetLength()
123+
{
124+
var stream = new PipelineStream(256);
125+
stream.SetLength(0);
126+
}
127+
128+
[TestMethod]
129+
[ExpectedException(typeof(NotSupportedException))]
130+
public void TestSetPosition()
131+
{
132+
var stream = new PipelineStream(256);
133+
stream.Position = 10;
134+
}
135+
136+
[TestMethod]
137+
[ExpectedException(typeof(NotSupportedException))]
138+
public void TestGetPosition()
139+
{
140+
var stream = new PipelineStream(256);
141+
var pos = stream.Position;
142+
}
143+
144+
[TestMethod]
145+
[ExpectedException(typeof(NotSupportedException))]
146+
public void TestGetLength()
147+
{
148+
var stream = new PipelineStream(256);
149+
var length = stream.Length;
150+
}
151+
}
152+
}

src/CatLib.Core.Tests/Support/Template/ManagerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void TestReleaseExtendAndMake()
5151
return tmp = new TestManagerClass();
5252
});
5353

54-
cls.ReleaseExtend();
54+
cls.RemoveExtend();
5555

5656
ExceptionAssert.Throws<RuntimeException>(() =>
5757
{

src/CatLib.Core.Tests/Support/Template/SingleManagerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void TestReleaseExtend()
129129
manager.Extend(() => new InterfaceImpl(), "hello");
130130

131131
Assert.AreEqual(true, manager.ContainsExtend("hello"));
132-
manager.ReleaseExtend("hello");
132+
manager.RemoveExtend("hello");
133133
Assert.AreEqual(false, manager.ContainsExtend());
134134
Assert.AreEqual(false, manager.ContainsExtend("hello"));
135135
}

src/CatLib.Core.Tests/Support/Util/ArrTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,36 @@ public void TestMerge()
3333
Assert.AreEqual(3, newArr.Length);
3434
}
3535

36+
[TestMethod]
37+
public void TestMergeNull()
38+
{
39+
var arr1 = new[] { "1", "2" };
40+
string[] arr2 = null;
41+
var arr3 = new[] { "3" };
42+
var newArr = Arr.Merge(arr1, arr2, arr3);
43+
Assert.AreEqual(3, newArr.Length);
44+
var i = 0;
45+
foreach (var result in newArr)
46+
{
47+
Assert.AreEqual((++i).ToString(), result);
48+
}
49+
}
50+
51+
[TestMethod]
52+
public void TestMergeEmpty()
53+
{
54+
var arr1 = new[] { "1", "2" };
55+
var arr2 = new string[0];
56+
var arr3 = new[] { "3" };
57+
var newArr = Arr.Merge(arr1, arr2, arr3);
58+
Assert.AreEqual(3, newArr.Length);
59+
var i = 0;
60+
foreach (var result in newArr)
61+
{
62+
Assert.AreEqual((++i).ToString(), result);
63+
}
64+
}
65+
3666
[TestMethod]
3767
public void TestRandom()
3868
{

src/CatLib.Core.Tests/Support/Util/StreamExtensionTests.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,52 @@ public void TestAppendTo()
2828
Assert.AreEqual(11, count);
2929
Assert.AreEqual("Hello world", Encoding.Default.GetString(stream2.GetBuffer(), 0, (int)stream2.Length));
3030
}
31+
32+
[TestMethod]
33+
public void TestStreamToText()
34+
{
35+
var stream1 = new MemoryStream(Encoding.Default.GetBytes("Hello world"));
36+
Assert.AreEqual("Hello world", stream1.ToText());
37+
}
38+
39+
[TestMethod]
40+
public void TestStreamToTextOtherStream()
41+
{
42+
var stream1 = new StorageStream(new MemoryStorage());
43+
stream1.Write(Encoding.Default.GetBytes("Hello world"), 0, 11);
44+
stream1.Seek(0, SeekOrigin.Begin);
45+
Assert.AreEqual("Hello world", stream1.ToText());
46+
}
47+
48+
[TestMethod]
49+
public void TestStreamToTextLarage()
50+
{
51+
var stream1 = new StorageStream(new MemoryStorage());
52+
var builder = new StringBuilder();
53+
for (var i = 0; i < (ThreadStatic.Buffer.Length / 10) + 1; i++)
54+
{
55+
stream1.Write(Encoding.Default.GetBytes("1234567890"), 0, 10);
56+
builder.Append("1234567890");
57+
}
58+
stream1.Seek(0, SeekOrigin.Begin);
59+
Assert.AreEqual(builder.ToString(), stream1.ToText());
60+
}
61+
62+
[TestMethod]
63+
public void TestStreamToTextEmpty()
64+
{
65+
var stream1 = new MemoryStream(0);
66+
Assert.AreEqual(string.Empty, stream1.ToText());
67+
}
68+
69+
[TestMethod]
70+
public void TestStreamClosed()
71+
{
72+
var stream1 = new MemoryStream(0);
73+
Assert.AreEqual(string.Empty, stream1.ToText(null, false));
74+
Assert.AreEqual(true, stream1.CanWrite);
75+
Assert.AreEqual(string.Empty, stream1.ToText());
76+
Assert.AreEqual(false, stream1.CanWrite);
77+
}
3178
}
3279
}

0 commit comments

Comments
 (0)