Skip to content

Commit ea02961

Browse files
committed
Merge branch '1.2' of https://github.com/CatLib/Core into 1.2
2 parents e4038a6 + cd82a2f commit ea02961

File tree

16 files changed

+1410
-29
lines changed

16 files changed

+1410
-29
lines changed

CatLib.Core.sln.DotSettings.user

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
3+
&lt;Assembly Path="D:\Software\VS2017\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll" /&gt;&#xD;
4+
&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>

src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
<Compile Include="..\CatLib.Core\Support\RingBuffer\RingBuffer.cs" Link="Support\RingBuffer\RingBuffer.cs" />
105105
<Compile Include="..\CatLib.Core\Support\SortSet\ISortSet.cs" Link="Support\SortSet\ISortSet.cs" />
106106
<Compile Include="..\CatLib.Core\Support\SortSet\SortSet.cs" Link="Support\SortSet\SortSet.cs" />
107+
<Compile Include="..\CatLib.Core\Support\Storage\IStorage.cs" Link="Support\Storage\IStorage.cs" />
108+
<Compile Include="..\CatLib.Core\Support\Storage\MemoryStorage.cs" Link="Support\Storage\MemoryStorage.cs" />
109+
<Compile Include="..\CatLib.Core\Support\Stream\StorageStream.cs" Link="Support\Stream\StorageStream.cs" />
107110
<Compile Include="..\CatLib.Core\Support\Template\IManaged.cs" Link="Support\Template\IManaged.cs" />
108111
<Compile Include="..\CatLib.Core\Support\Template\IManager.cs" Link="Support\Template\IManager.cs" />
109112
<Compile Include="..\CatLib.Core\Support\Template\ISingleManaged.cs" Link="Support\Template\ISingleManaged.cs" />
@@ -132,8 +135,10 @@
132135
<Folder Include="Support\Guard\" />
133136
<Folder Include="Support\QuickList\" />
134137
<Folder Include="Support\SortSet\" />
138+
<Folder Include="Support\Stream\" />
135139
<Folder Include="Support\Template\" />
136140
<Folder Include="Support\RingBuffer\" />
141+
<Folder Include="Support\Storage\" />
137142
</ItemGroup>
138143

139144
</Project>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@
5151
<Compile Include="Support\QuickList\QuickListTests.cs" />
5252
<Compile Include="Support\RingBuffer\RingBufferTests.cs" />
5353
<Compile Include="Support\SortSet\SortSetTests.cs" />
54+
<Compile Include="Support\Storage\MemoryStorageTests.cs" />
55+
<Compile Include="Support\Stream\StorageStreamTests.cs" />
5456
<Compile Include="Support\Template\ManagerTests.cs" />
5557
<Compile Include="Support\Template\SingleManagerTests.cs" />
5658
<Compile Include="Support\Util\ArrTests.cs" />
5759
<Compile Include="Support\Util\DictTests.cs" />
5860
<Compile Include="Support\Util\EnumTests.cs" />
61+
<Compile Include="Support\Util\StreamExtensionTests.cs" />
5962
<Compile Include="Support\Util\StrTests.cs" />
6063
<Compile Include="Support\Util\SystemTimeTests.cs" />
6164
<Compile Include="Support\VersionTests.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.7.0")]
29-
[assembly: AssemblyFileVersion("1.2.7.0")]
28+
[assembly: AssemblyVersion("1.2.8.0")]
29+
[assembly: AssemblyFileVersion("1.2.8.0")]

src/CatLib.Core.Tests/Support/SortSet/SortSetTests.cs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,36 @@ public void TestRandValue()
5858
}
5959

6060
[TestMethod]
61+
6162
public void TestRank()
6263
{
63-
var sortSets = new SortSet<int, int>();
64+
var n = 100;
65+
while (n-- > 0)
66+
{
67+
var sortSets = new SortSet<int, int>();
68+
69+
sortSets.Add(1000, 85);
70+
sortSets.Add(999, 75);
71+
sortSets.Add(998, 185);
72+
sortSets.Add(997, 85);
73+
sortSets.Add(996, 185);
74+
sortSets.Add(995, 85);
75+
76+
Assert.AreEqual(1, sortSets.GetRank(995));
77+
Assert.AreEqual(995, sortSets.GetElementByRank(1));
78+
Assert.AreEqual(997, sortSets.GetElementByRank(2));
79+
Assert.AreEqual(1000, sortSets.GetElementByRank(3));
80+
Assert.AreEqual(996, sortSets.GetElementByRank(4));
81+
Assert.AreEqual(998, sortSets.GetElementByRank(5));
6482

65-
sortSets.Add(1000, 85);
66-
sortSets.Add(999, 75);
67-
sortSets.Add(998, 185);
68-
sortSets.Add(997, 85);
69-
sortSets.Add(996, 185);
70-
sortSets.Add(995, 85);
71-
72-
Assert.AreEqual(1, sortSets.GetRank(995));
73-
Assert.AreEqual(995, sortSets.GetElementByRank(1));
74-
Assert.AreEqual(997, sortSets.GetElementByRank(2));
75-
Assert.AreEqual(1000, sortSets.GetElementByRank(3));
76-
Assert.AreEqual(996, sortSets.GetElementByRank(4));
77-
Assert.AreEqual(998, sortSets.GetElementByRank(5));
78-
79-
Assert.AreEqual(3, sortSets.GetRangeCount(80, 90));
83+
var i = 100;
84+
var faild = 0;
85+
while (i-- > 0)
86+
{
87+
Assert.AreEqual(3, sortSets.GetRangeCount(80, 90));
88+
}
89+
Console.WriteLine(faild);
90+
}
8091
}
8192

8293
[TestMethod]
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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.Text;
14+
using Microsoft.VisualStudio.TestTools.UnitTesting;
15+
16+
namespace CatLib
17+
{
18+
[TestClass]
19+
public class MemoryStorageTests
20+
{
21+
[TestMethod]
22+
public void TestWrite()
23+
{
24+
// Append() is alias as Write
25+
var storage = new MemoryStorage(4);
26+
storage.Append(Encoding.Default.GetBytes("hello world"), 0, 11);
27+
var data = new byte[16];
28+
Assert.AreEqual(11, storage.Read(data, 0, data.Length));
29+
Assert.AreEqual("hello world", Encoding.Default.GetString(Arr.Slice(data, 0, 11)));
30+
}
31+
32+
[TestMethod]
33+
public void TestAppend()
34+
{
35+
var storage = new MemoryStorage(4);
36+
storage.Append(Encoding.Default.GetBytes("hello world"), 0, 11);
37+
storage.Append(Encoding.Default.GetBytes("1"), 0, 1);
38+
var data = new byte[16];
39+
Assert.AreEqual(12, storage.Read(data, 0, data.Length));
40+
Assert.AreEqual("hello world1", Encoding.Default.GetString(Arr.Slice(data, 0, 12)));
41+
42+
storage.Append(Encoding.Default.GetBytes("2"), 0, 1);
43+
Assert.AreEqual(13, storage.Read(data, 0, data.Length));
44+
Assert.AreEqual("hello world12", Encoding.Default.GetString(Arr.Slice(data, 0, 13)));
45+
}
46+
47+
[TestMethod]
48+
public void TestBlockAutomaticExpansion()
49+
{
50+
var storage = new MemoryStorage(4, 2);
51+
storage.Append(Encoding.Default.GetBytes("12345678"), 0, 8);
52+
storage.Append(Encoding.Default.GetBytes("9"), 0, 1);
53+
54+
var data = new byte[16];
55+
Assert.AreEqual(9, storage.Read(data, 0, data.Length));
56+
Assert.AreEqual("123456789", Encoding.Default.GetString(Arr.Slice(data, 0, 9)));
57+
}
58+
59+
[TestMethod]
60+
[ExpectedException(typeof(ObjectDisposedException))]
61+
public void TestDispose()
62+
{
63+
MemoryStorage storage;
64+
using (storage = new MemoryStorage(4, 2))
65+
{
66+
storage.Append(Encoding.Default.GetBytes("12345678"), 0, 8);
67+
}
68+
69+
var data = new byte[16];
70+
storage.Read(data, 0, data.Length);
71+
}
72+
73+
[TestMethod]
74+
[ExpectedException(typeof(ObjectDisposedException))]
75+
public void TestDispose2()
76+
{
77+
MemoryStorage storage;
78+
using (storage = new MemoryStorage(4, 2))
79+
{
80+
81+
}
82+
storage.Append(Encoding.Default.GetBytes("12345678"), 0, 8);
83+
}
84+
85+
[TestMethod]
86+
public void TestJumpWrite()
87+
{
88+
var storage = new MemoryStorage(4, 2);
89+
storage.Append(Encoding.Default.GetBytes("1234"), 0, 4);
90+
storage.Write(Encoding.Default.GetBytes("5678"), 0, 4, 13);
91+
Assert.AreEqual(17, storage.Length);
92+
93+
var data = new byte[]
94+
{
95+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
96+
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
97+
};
98+
Assert.AreEqual(17, storage.Read(data, 0, data.Length));
99+
Assert.AreEqual("1234\0\0\0\0\0\0\0\0\05678", Encoding.Default.GetString(Arr.Slice(data, 0, 17)));
100+
}
101+
102+
[TestMethod]
103+
[ExpectedException(typeof(OutOfMemoryException))]
104+
public void TestOutOfMemory()
105+
{
106+
var storage = new MemoryStorage(8, 4, 2);
107+
try
108+
{
109+
storage.Append(Encoding.Default.GetBytes("12345678"), 0, 8);
110+
}
111+
catch (OutOfMemoryException)
112+
{
113+
114+
}
115+
116+
storage.Append(Encoding.Default.GetBytes("1"), 0, 1);
117+
}
118+
119+
[TestMethod]
120+
public void TestDoubleDispose()
121+
{
122+
var storage = new MemoryStorage(8, 4, 2);
123+
Assert.AreEqual(false, storage.Disabled);
124+
storage.Dispose();
125+
Assert.AreEqual(true, storage.Disabled);
126+
storage.Dispose();
127+
Assert.AreEqual(true, storage.Disabled);
128+
}
129+
130+
[TestMethod]
131+
public void TestGetLocker()
132+
{
133+
using (var storage = new MemoryStorage(8, 4, 2))
134+
{
135+
Assert.AreNotEqual(null, storage.Locker);
136+
}
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)