This repository was archived by the owner on Jul 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathSearchMarkTest.cs
More file actions
105 lines (81 loc) · 3.55 KB
/
Copy pathSearchMarkTest.cs
File metadata and controls
105 lines (81 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System.Threading.Tasks;
using Xunit;
using System;
using System.Net;
using System.Net.Sockets;
using System.Collections.Generic;
using SuperSocket.ProtoBase;
using System.Text;
namespace SuperSocket.ClientEngine.Test
{
public class SearchMarkTest
{
[Fact]
public void TestMatchSecondTime()
{
byte[] first = Encoding.ASCII.GetBytes("HTTP/1.0 200 Connection Established\r\n");
byte[] second = Encoding.ASCII.GetBytes("\r\n");
byte[] mark = Encoding.ASCII.GetBytes("\r\n\r\n");
// -2 means "\r\n\r\n" is partially matched at last 2 bytes
Assert.Equal(-2, first.SearchMark(0, first.Length, mark));
// 0 means later part of "\r\n\r\n" is fully matched at 0
Assert.Equal(0, second.SearchMark(0, second.Length, mark, 2));
}
[Fact]
public void TestMatchFirstTime()
{
byte[] first = Encoding.ASCII.GetBytes("HTTP/1.0 200 Connection Established\r\n\r\n");
byte[] mark = Encoding.ASCII.GetBytes("\r\n\r\n");
// "\r\n\r\n" is matched at first[35] to [38]
Assert.Equal(35, first.SearchMark(0, first.Length, mark));
}
[Fact]
public void TestMatchFirstTimeWithSearchMarkState()
{
byte[] first = Encoding.ASCII.GetBytes("HTTP/1.0 200 Connection Established\r\n\r\n");
byte[] mark = Encoding.ASCII.GetBytes("\r\n\r\n");
var searchState = new SearchMarkState<byte>(mark);
// "\r\n\r\n" is matched at first[35] to [38]
Assert.Equal(35, first.SearchMark(0, first.Length, searchState));
}
[Fact]
public void TestMatchSecondTimeWithSearchMarkState()
{
byte[] first = Encoding.ASCII.GetBytes("HTTP/1.0 200 Connection Established\r\n");
byte[] second = Encoding.ASCII.GetBytes("\r\n");
byte[] mark = Encoding.ASCII.GetBytes("\r\n\r\n");
var searchState = new SearchMarkState<byte>(mark);
{
// -1 means: not matched, or partially matched.
Assert.Equal(-1, first.SearchMark(0, first.Length, searchState));
// Check if (1 <= searchState.Matched) in case of partial match.
}
{
var prevMatched = searchState.Matched;
Assert.Equal(prevMatched, 2);
// "\r\n\r\n" is completely matched on second buffer at second[0] to [1].
Assert.Equal(0, second.SearchMark(0, second.Length, searchState));
}
}
[Fact]
public void Test()
{
byte[] first = Encoding.ASCII.GetBytes("HTTP/1.1 200 Connection Established\r\n");
byte[] second = Encoding.ASCII.GetBytes("Proxy-agent: Apache/2.2.29 (Win32)\r\n\r\n");
byte[] mark = Encoding.ASCII.GetBytes("\r\n\r\n");
var searchState = new SearchMarkState<byte>(mark);
{
// -1 means: not matched, or partially matched.
Assert.Equal(-1, first.SearchMark(0, first.Length, searchState));
// Check if (1 <= searchState.Matched) in case of partial match.
}
{
var prevMatched = searchState.Matched;
Assert.Equal(prevMatched, 2);
// "\r\n\r\n" is matched on second buffer at second[34] to [37].
// So prevMatched should be ignored this time.
Assert.Equal(34, second.SearchMark(0, second.Length, searchState));
}
}
}
}