[smuxi] [Engine-Tests] Enhanced message buffer test-cases



commit aaae9b1253016c0a3c16a916e2ee0b0c7ddc46b3
Author: Mirco Bauer <meebey meebey net>
Date:   Mon Mar 5 00:19:51 2012 +0100

    [Engine-Tests] Enhanced message buffer test-cases

 src/Engine-Tests/GitMessageBufferTests.cs  |    4 --
 src/Engine-Tests/JsonMessageBufferTests.cs |    4 --
 src/Engine-Tests/MessageBufferTestsBase.cs |   77 +++++++++++++++++++++++++++-
 src/Engine-Tests/MessageDtoModelV1Tests.cs |   13 ++++-
 src/Engine-Tests/MessageModelTests.cs      |    6 ++
 5 files changed, 93 insertions(+), 11 deletions(-)
---
diff --git a/src/Engine-Tests/GitMessageBufferTests.cs b/src/Engine-Tests/GitMessageBufferTests.cs
index 0e2a2e4..366acfe 100644
--- a/src/Engine-Tests/GitMessageBufferTests.cs
+++ b/src/Engine-Tests/GitMessageBufferTests.cs
@@ -27,10 +27,6 @@ namespace Smuxi.Engine
     [TestFixture]
     public class GitMessageBufferTests : MessageBufferTestsBase
     {
-        static GitMessageBufferTests() {
-            log4net.Config.BasicConfigurator.Configure();
-        }
-
         protected override IMessageBuffer CreateBuffer()
         {
             var repoPath = Path.Combine(Platform.GetBuffersPath("testuser"),
diff --git a/src/Engine-Tests/JsonMessageBufferTests.cs b/src/Engine-Tests/JsonMessageBufferTests.cs
index e4f4af3..c5bb58e 100644
--- a/src/Engine-Tests/JsonMessageBufferTests.cs
+++ b/src/Engine-Tests/JsonMessageBufferTests.cs
@@ -27,10 +27,6 @@ namespace Smuxi.Engine
     [TestFixture]
     public class JsonMessageBufferTests : MessageBufferTestsBase
     {
-        static JsonMessageBufferTests() {
-            log4net.Config.BasicConfigurator.Configure();
-        }
-
         protected override IMessageBuffer CreateBuffer()
         {
             var dbPath = Path.Combine(Platform.GetBuffersPath("testuser"),
diff --git a/src/Engine-Tests/MessageBufferTestsBase.cs b/src/Engine-Tests/MessageBufferTestsBase.cs
index 475d874..3b4a02e 100644
--- a/src/Engine-Tests/MessageBufferTestsBase.cs
+++ b/src/Engine-Tests/MessageBufferTestsBase.cs
@@ -33,6 +33,11 @@ namespace Smuxi.Engine
         protected abstract IMessageBuffer CreateBuffer();
         protected abstract IMessageBuffer OpenBuffer();
 
+        static MessageBufferTestsBase()
+        {
+            log4net.Config.BasicConfigurator.Configure();
+        }
+
         [SetUp]
         public void SetUp()
         {
@@ -49,7 +54,7 @@ namespace Smuxi.Engine
             TestMessages.Add(builder.ToMessage());
 
             builder = new MessageBuilder();
-            builder.AppendText("msg3");
+            builder.AppendErrorText("msg3");
             TestMessages.Add(builder.ToMessage());
 
             foreach (var msg in TestMessages) {
@@ -95,6 +100,30 @@ namespace Smuxi.Engine
         }
 
         [Test]
+        public void IndexerBenchmark()
+        {
+            var bufferType = Buffer.GetType().Name;
+            int runs = 10000;
+            DateTime start, stop;
+            start = DateTime.UtcNow;
+            for (int i = 0; i < runs; i++) {
+                var msg1 = Buffer[0];
+                var msg2 = Buffer[1];
+                var msg3 = Buffer[2];
+            }
+            stop = DateTime.UtcNow;
+
+            var total = (stop - start).TotalMilliseconds;
+            Console.WriteLine(
+                "{0}[]: avg: {1:0.00} ms runs: {2} took: {3:0.00} ms",
+                bufferType,
+                total / runs,
+                runs,
+                total
+            );
+        }
+
+        [Test]
         public void IndexOf()
         {
             Assert.AreEqual(1, Buffer.IndexOf(TestMessages[1]));
@@ -168,6 +197,7 @@ namespace Smuxi.Engine
 
         public void RunGetRangeBenchmark(bool cold, int itemCount, int readCount)
         {
+            Buffer.Dispose();
             Buffer = CreateBuffer();
 
             var bufferType = Buffer.GetType().Name;
@@ -215,6 +245,50 @@ namespace Smuxi.Engine
         }
 
         [Test]
+        public void OpenBufferBenchmark()
+        {
+            RunOpenBufferBenchmark(1);
+            RunOpenBufferBenchmark(10000);
+            RunOpenBufferBenchmark(50000);
+        }
+
+        public void RunOpenBufferBenchmark(int itemCount)
+        {
+            Buffer.Dispose();
+            Buffer = CreateBuffer();
+
+            var bufferType = Buffer.GetType().Name;
+            // generate items
+            for (int i = 0; i < itemCount; i++) {
+                Buffer.Add(new MessageModel(SimpleMessage));
+            }
+            // flush/close buffer
+            Buffer.Dispose();
+
+            int runs = 10;
+            var messageCount = 0;
+            DateTime start, stop;
+            start = DateTime.UtcNow;
+            for (int i = 0; i < runs; i++) {
+                Buffer = OpenBuffer();
+                messageCount += Buffer.Count;
+                Buffer.Dispose();
+            }
+            stop = DateTime.UtcNow;
+            Assert.AreEqual(runs * itemCount, messageCount);
+
+            var total = (stop - start).TotalMilliseconds;
+            Console.WriteLine(
+                "{0}(): avg: {1:0.00} ms items: {2} runs: {3} took: {4:0.00} ms",
+                bufferType,
+                total / runs,
+                itemCount,
+                runs,
+                total
+            );
+        }
+
+        [Test]
         public void Add()
         {
             MessageBuilder msg = new MessageBuilder();
@@ -235,6 +309,7 @@ namespace Smuxi.Engine
 
         public void RunAddBenchmark(int itemCount)
         {
+            Buffer.Dispose();
             Buffer = CreateBuffer();
 
             DateTime start, stop;
diff --git a/src/Engine-Tests/MessageDtoModelV1Tests.cs b/src/Engine-Tests/MessageDtoModelV1Tests.cs
index 9beb9ac..e00ee27 100644
--- a/src/Engine-Tests/MessageDtoModelV1Tests.cs
+++ b/src/Engine-Tests/MessageDtoModelV1Tests.cs
@@ -24,6 +24,7 @@ using Smuxi.Engine.Dto;
 
 namespace Smuxi.Engine
 {
+    [TestFixture]
     public class MessageDtoModelV1Tests
     {
         MessageModel SimpleMessage { get; set; }
@@ -39,10 +40,9 @@ namespace Smuxi.Engine
             JsConfig<MessagePartModel>.ExcludeTypeInfo = true;
 
             var builder = new MessageBuilder();
-            builder.AppendIdendityName(
+            builder.AppendSenderPrefix(
                 new ContactModel("meeebey", "meebey", "netid", "netprot")
             );
-            builder.AppendSpace();
             builder.AppendText("solange eine message aber keine url hat ist der vorteil nur gering (wenn 
ueberhaupt)");
             SimpleMessage = builder.ToMessage();
             SimpleMessageJson = JsonSerializer.SerializeToString(SimpleMessage);
@@ -58,6 +58,15 @@ namespace Smuxi.Engine
         }
 
         [Test]
+        public void SerializeDeserialize()
+        {
+            var dtoMsg = new MessageDtoModelV1(SimpleMessage);
+            var json = JsonSerializer.SerializeToString(dtoMsg);
+            var dtoMsg2 = JsonSerializer.DeserializeFromString<MessageDtoModelV1>(json);
+            Assert.AreEqual(dtoMsg.ToMessage(), dtoMsg2.ToMessage());
+        }
+
+        [Test]
         public void ToMessageBenchmark()
         {
             int runs = 50000;
diff --git a/src/Engine-Tests/MessageModelTests.cs b/src/Engine-Tests/MessageModelTests.cs
index fa80cac..31abc9e 100644
--- a/src/Engine-Tests/MessageModelTests.cs
+++ b/src/Engine-Tests/MessageModelTests.cs
@@ -58,6 +58,12 @@ namespace Smuxi.Engine
             msg = new MessageModel();
             Assert.IsFalse(msg.Equals(null));
             Assert.IsFalse(msg == null);
+
+            msg = new MessageModel(SimpleMessage);
+            Assert.IsTrue(msg.Equals(SimpleMessage));
+            var textPart = (TextMessagePartModel) msg.MessageParts[0];
+            textPart.ForegroundColor = TextColor.Grey;
+            Assert.IsFalse(msg.Equals(SimpleMessage));
         }
 
         [Test]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]