Skip to content

Commit

Permalink
Extended unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheusxx committed Feb 26, 2014
1 parent 5ae61e6 commit 89ba22c
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions MediaPortal/Tests/Tests.UPnP/HttpHeaders.cs
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand All @@ -10,7 +12,7 @@ namespace Tests.UPnP
public class HttpHeaders
{
[TestMethod]
public void ParseHttpRequestHeaders()
public void Http_ParsePostHeaders()
{
// Typical http headers, taken TMP forum search
List<string> requestHeaders = new List<string>
Expand All @@ -29,7 +31,47 @@ public void ParseHttpRequestHeaders()
"",
"keywords=header&users=&date=&nodes%5B%5D=532&_xfToken=48495%2C1392921388%2Cf813dbe3c466d430b06d11bd9bddbb5f8b6cf644",
};
Parse(requestHeaders);
}

[TestMethod]
public void Http_ParseGetHeaders()
{
List<string> requestHeaders = new List<string>
{
"GET http://forum.team-mediaportal.com/threads/error-parsing-http-headers.124716/page-4 HTTP/1.1",
"Host: forum.team-mediaportal.com",
"User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0",
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3",
"Accept-Encoding: gzip, deflate",
"Referer: http://forum.team-mediaportal.com/threads/error-parsing-http-headers.124716/page-3",
"Cookie: xf_session=6e46fc023bc61ede8011448d8a6cb515; xf_user=48495%2Cc2564e9c4f11cb5013ac081872f5d354ef63fc92",
"Connection: keep-alive",
"If-Modified-Since: Wed, 26 Feb 2014 18:49:15 GMT",
"Cache-Control: max-age=0",
""
};
Parse(requestHeaders);
}

[TestMethod]
public void Http_ParseConnectHeaders()
{
List<string> requestHeaders = new List<string>
{
"CONNECT de-de.facebook.com:443 HTTP/1.1",
"User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0",
"Connection: keep-alive",
"Connection: keep-alive",
"Host: de-de.facebook.com",
""
};
Parse(requestHeaders);
}

private static void Parse(List<string> requestHeaders)
{
// Construct header using different line break styles
IEnumerable<string> delimiters = new[] { "\r\n", "\n" };
foreach (string delimiter in delimiters)
Expand All @@ -51,5 +93,20 @@ public void ParseHttpRequestHeaders()
}
}
}

[TestMethod]
public void Http_ParseHeadersPerformanceTest()
{
var watch = Stopwatch.StartNew();
for (var i = 0; i < 5000; i++)
{
Http_ParsePostHeaders();
Http_ParseGetHeaders();
Http_ParseConnectHeaders();
}

watch.Stop();
Console.WriteLine("Elapsed time: {0}ms", watch.ElapsedMilliseconds);
}
}
}

0 comments on commit 89ba22c

Please sign in to comment.