You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by Dominik Psenner <dp...@gmail.com> on 2013/01/22 14:41:09 UTC

[PATCH 5 of 5] Step 5: tests

diff -r c4b727dc790c -r 09c42c61e2db tests/src/Appender/RollingFileAppenderTest.cs
--- a/tests/src/Appender/RollingFileAppenderTest.cs	Tue Jan 22 14:31:58 2013 +0100
+++ b/tests/src/Appender/RollingFileAppenderTest.cs	Tue Jan 22 14:37:21 2013 +0100
@@ -1874,12 +1874,110 @@
 		{
 		}
 
+        /// <summary>
+        /// 
+        /// </summary>
+        [Test]
+        public void TestGetFileDeleteList1()
+        {
+            string[] files = {   "C:\\foo\\log.201302.log", "C:\\foo\\log.201302.1.log", "C:\\foo\\log.201302.2.log", 
+                                 "C:\\foo\\log.201301.log", "C:\\foo\\log.201301.1.log", "C:\\foo\\log.201301.2.log",
+                                 "C:\\foo\\log.201212.log", "C:\\foo\\log.201212.1.log", "C:\\foo\\log.201212.2.log",  
+                                 "C:\\foo\\log.201211.log", "C:\\foo\\log.201211.1.log", "C:\\foo\\log.201211.2.log" };
+            string[] actual = GetFileDeleteList(files, DateTime.Parse("2013/02/15"), "C:\\foo\\log.log", ".yyyyMM", 
+                RollingFileAppender.RollPoint.TopOfMonth, 2, true);
+            string[] expected = { "C:\\foo\\log.201211.log", "C:\\foo\\log.201211.1.log", "C:\\foo\\log.201211.2.log" };
+            Assert.AreEqual(expected, actual);
+        }
 
-		//
+        /// <summary>
+        /// 
+        /// </summary>
+        [Test]
+        public void TestGetFileDeleteList2()
+        {
+            string[] files = {   "C:\\foo\\log.201302.log", "C:\\foo\\log.201302.1.log", "C:\\foo\\log.201302.2.log", 
+                                 "C:\\foo\\log.201301.log", "C:\\foo\\log.201301.1.log", "C:\\foo\\log.201301.2.log",
+                                 "C:\\foo\\log.201212.log", "C:\\foo\\log.201212.1.log", "C:\\foo\\log.201212.2.log",  
+                                 "C:\\foo\\log.201211.log", "C:\\foo\\log.201211.1.log", "C:\\foo\\log.201211.2.log" };
+            string[] actual = GetFileDeleteList(files, DateTime.Parse("2013/02/15"), "C:\\foo\\log.log", ".yyyyMM",
+                RollingFileAppender.RollPoint.TopOfMonth, 0, true);
+            string[] expected = {"C:\\foo\\log.201301.log", "C:\\foo\\log.201301.1.log", "C:\\foo\\log.201301.2.log",
+                                 "C:\\foo\\log.201212.log", "C:\\foo\\log.201212.1.log", "C:\\foo\\log.201212.2.log",  
+                                 "C:\\foo\\log.201211.log", "C:\\foo\\log.201211.1.log", "C:\\foo\\log.201211.2.log" };
+            Assert.AreEqual(expected, actual);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        [Test]
+        public void TestGetFileDeleteList3()
+        {
+            string[] files = {   "C:\\foo\\log.log.2013.2", "C:\\foo\\log.log.2013.2.1", "C:\\foo\\log.log.2013.2.2", 
+                                 "C:\\foo\\log.log.2013.1", "C:\\foo\\log.log.2013.1.1", "C:\\foo\\log.log.2013.1.2",
+                                 "C:\\foo\\log.log.2012.12", "C:\\foo\\log.log.2012.12.1", "C:\\foo\\log.log.2012.12.2",  
+                                 "C:\\foo\\log.log.2012.11", "C:\\foo\\log.log.2012.11.1", "C:\\foo\\log.log.2012.11.2" };
+            string[] actual = GetFileDeleteList(files, DateTime.Parse("2013/02/15"), "C:\\foo\\log.log", ".yyyy.M",
+                RollingFileAppender.RollPoint.TopOfMonth, 2, false);
+            string[] expected = { "C:\\foo\\log.log.2012.11", "C:\\foo\\log.log.2012.11.1", "C:\\foo\\log.log.2012.11.2" };
+            Assert.AreEqual(expected, actual);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        [Test]
+        public void TestGetFileDeleteList4()
+        {
+            string[] files = {   "C:\\foo\\log.2.2013.log", "C:\\foo\\log.2.2013.1.log", "C:\\foo\\log.2.2013.2.log", 
+                                 "C:\\foo\\log.1.2013.log", "C:\\foo\\log.1.2013.1.log", "C:\\foo\\log.1.2013.2.log",
+                                 "C:\\foo\\log.12.2012.log", "C:\\foo\\log.12.2012.1.log", "C:\\foo\\log.12.2012.2.log" };
+            string[] actual = GetFileDeleteList(files, DateTime.Parse("2013/02/15"), "C:\\foo\\log.log", ".M.yyyy",
+                RollingFileAppender.RollPoint.TopOfMonth, 0, true);
+            string[] expected = { "C:\\foo\\log.1.2013.log", "C:\\foo\\log.1.2013.1.log", "C:\\foo\\log.1.2013.2.log",
+                                  "C:\\foo\\log.12.2012.log", "C:\\foo\\log.12.2012.1.log", "C:\\foo\\log.12.2012.2.log"};
+            Assert.AreEqual(expected, actual);
+        }
+
+        //
 		// Helper functions to dig into the appender
 		//
+        protected class TestDateTime : RollingFileAppender.IDateTime
+        {
+            public TestDateTime(DateTime dt)
+            {
+                m_Now = dt;
+            }
 
-		private static ArrayList GetExistingFiles(string baseFilePath)
+            #region IDateTime Members
+
+            public DateTime Now
+            {
+                get { return m_Now; }
+            }
+
+            #endregion
+
+            private DateTime m_Now;
+        }
+
+        protected static string[] GetFileDeleteList(string[] fileNames, DateTime dateTime, string baseFile,
+            string datePattern, RollingFileAppender.RollPoint rollPoint, int maxDateRollBackups, bool preserveLogFileNameExtension)
+        {
+            RollingFileAppender appender = new RollingFileAppender();
+            ArrayList list = (ArrayList)Utils.InvokeMethod(appender, "GetFileDeleteList", fileNames, dateTime, baseFile,
+                datePattern, rollPoint, maxDateRollBackups, preserveLogFileNameExtension);
+            string[] rv = new string[list.Count];
+            int i=0;
+            foreach(string s in list)
+            {
+                rv[i++]=s;
+            }
+            return rv;
+        }
+
+        private static ArrayList GetExistingFiles(string baseFilePath)
 		{
 			RollingFileAppender appender = new RollingFileAppender();
 			appender.SecurityContext = NullSecurityContext.Instance;
@@ -1921,9 +2019,9 @@
 					throw new Exception("Unexpected Environment.NewLine.Length");
 			}
 		}
-	}
+    }
 
-	[TestFixture]
+    [TestFixture]
 	public class RollingFileAppenderSubClassTest : RollingFileAppender
 	{
 		[Test]

Re: [PATCH 5 of 5] Step 5: tests

Posted by Dominik Psenner <dp...@gmail.com>.
On 01/22/2013 02:41 PM, Dominik Psenner wrote:
> diff -r c4b727dc790c -r 09c42c61e2db tests/src/Appender/RollingFileAppenderTest.cs
> --- a/tests/src/Appender/RollingFileAppenderTest.cs	Tue Jan 22 14:31:58 2013 +0100
> +++ b/tests/src/Appender/RollingFileAppenderTest.cs	Tue Jan 22 14:37:21 2013 +0100
> @@ -1874,12 +1874,110 @@
>   		{
>   		}
>   
> +        /// <summary>
> +        ///
> +        /// </summary>
> +        [Test]
> +        public void TestGetFileDeleteList1()
> +        {
> +            string[] files = {   "C:\\foo\\log.201302.log", "C:\\foo\\log.201302.1.log", "C:\\foo\\log.201302.2.log",
> +                                 "C:\\foo\\log.201301.log", "C:\\foo\\log.201301.1.log", "C:\\foo\\log.201301.2.log",
> +                                 "C:\\foo\\log.201212.log", "C:\\foo\\log.201212.1.log", "C:\\foo\\log.201212.2.log",
> +                                 "C:\\foo\\log.201211.log", "C:\\foo\\log.201211.1.log", "C:\\foo\\log.201211.2.log" };
> +            string[] actual = GetFileDeleteList(files, DateTime.Parse("2013/02/15"), "C:\\foo\\log.log", ".yyyyMM",
> +                RollingFileAppender.RollPoint.TopOfMonth, 2, true);
> +            string[] expected = { "C:\\foo\\log.201211.log", "C:\\foo\\log.201211.1.log", "C:\\foo\\log.201211.2.log" };
> +            Assert.AreEqual(expected, actual);
> +        }
>   
> -		//
> +        /// <summary>
> +        ///
> +        /// </summary>
> +        [Test]
> +        public void TestGetFileDeleteList2()
> +        {
> +            string[] files = {   "C:\\foo\\log.201302.log", "C:\\foo\\log.201302.1.log", "C:\\foo\\log.201302.2.log",
> +                                 "C:\\foo\\log.201301.log", "C:\\foo\\log.201301.1.log", "C:\\foo\\log.201301.2.log",
> +                                 "C:\\foo\\log.201212.log", "C:\\foo\\log.201212.1.log", "C:\\foo\\log.201212.2.log",
> +                                 "C:\\foo\\log.201211.log", "C:\\foo\\log.201211.1.log", "C:\\foo\\log.201211.2.log" };
> +            string[] actual = GetFileDeleteList(files, DateTime.Parse("2013/02/15"), "C:\\foo\\log.log", ".yyyyMM",
> +                RollingFileAppender.RollPoint.TopOfMonth, 0, true);
> +            string[] expected = {"C:\\foo\\log.201301.log", "C:\\foo\\log.201301.1.log", "C:\\foo\\log.201301.2.log",
> +                                 "C:\\foo\\log.201212.log", "C:\\foo\\log.201212.1.log", "C:\\foo\\log.201212.2.log",
> +                                 "C:\\foo\\log.201211.log", "C:\\foo\\log.201211.1.log", "C:\\foo\\log.201211.2.log" };
> +            Assert.AreEqual(expected, actual);
> +        }
> +
> +        /// <summary>
> +        ///
> +        /// </summary>
> +        [Test]
> +        public void TestGetFileDeleteList3()
> +        {
> +            string[] files = {   "C:\\foo\\log.log.2013.2", "C:\\foo\\log.log.2013.2.1", "C:\\foo\\log.log.2013.2.2",
> +                                 "C:\\foo\\log.log.2013.1", "C:\\foo\\log.log.2013.1.1", "C:\\foo\\log.log.2013.1.2",
> +                                 "C:\\foo\\log.log.2012.12", "C:\\foo\\log.log.2012.12.1", "C:\\foo\\log.log.2012.12.2",
> +                                 "C:\\foo\\log.log.2012.11", "C:\\foo\\log.log.2012.11.1", "C:\\foo\\log.log.2012.11.2" };
> +            string[] actual = GetFileDeleteList(files, DateTime.Parse("2013/02/15"), "C:\\foo\\log.log", ".yyyy.M",
> +                RollingFileAppender.RollPoint.TopOfMonth, 2, false);
> +            string[] expected = { "C:\\foo\\log.log.2012.11", "C:\\foo\\log.log.2012.11.1", "C:\\foo\\log.log.2012.11.2" };
> +            Assert.AreEqual(expected, actual);
> +        }
> +
> +        /// <summary>
> +        ///
> +        /// </summary>
> +        [Test]
> +        public void TestGetFileDeleteList4()
> +        {
> +            string[] files = {   "C:\\foo\\log.2.2013.log", "C:\\foo\\log.2.2013.1.log", "C:\\foo\\log.2.2013.2.log",
> +                                 "C:\\foo\\log.1.2013.log", "C:\\foo\\log.1.2013.1.log", "C:\\foo\\log.1.2013.2.log",
> +                                 "C:\\foo\\log.12.2012.log", "C:\\foo\\log.12.2012.1.log", "C:\\foo\\log.12.2012.2.log" };
> +            string[] actual = GetFileDeleteList(files, DateTime.Parse("2013/02/15"), "C:\\foo\\log.log", ".M.yyyy",
> +                RollingFileAppender.RollPoint.TopOfMonth, 0, true);
> +            string[] expected = { "C:\\foo\\log.1.2013.log", "C:\\foo\\log.1.2013.1.log", "C:\\foo\\log.1.2013.2.log",
> +                                  "C:\\foo\\log.12.2012.log", "C:\\foo\\log.12.2012.1.log", "C:\\foo\\log.12.2012.2.log"};
> +            Assert.AreEqual(expected, actual);
> +        }
> +
> +        //
>   		// Helper functions to dig into the appender
>   		//
> +        protected class TestDateTime : RollingFileAppender.IDateTime
> +        {
> +            public TestDateTime(DateTime dt)
> +            {
> +                m_Now = dt;
> +            }
>   
> -		private static ArrayList GetExistingFiles(string baseFilePath)
> +            #region IDateTime Members
> +
> +            public DateTime Now
> +            {
> +                get { return m_Now; }
> +            }
> +
> +            #endregion
> +
> +            private DateTime m_Now;
> +        }
> +
> +        protected static string[] GetFileDeleteList(string[] fileNames, DateTime dateTime, string baseFile,
> +            string datePattern, RollingFileAppender.RollPoint rollPoint, int maxDateRollBackups, bool preserveLogFileNameExtension)
> +        {
> +            RollingFileAppender appender = new RollingFileAppender();
> +            ArrayList list = (ArrayList)Utils.InvokeMethod(appender, "GetFileDeleteList", fileNames, dateTime, baseFile,
> +                datePattern, rollPoint, maxDateRollBackups, preserveLogFileNameExtension);
> +            string[] rv = new string[list.Count];
> +            int i=0;
> +            foreach(string s in list)
> +            {
> +                rv[i++]=s;
> +            }
> +            return rv;
> +        }
> +
> +        private static ArrayList GetExistingFiles(string baseFilePath)
>   		{
>   			RollingFileAppender appender = new RollingFileAppender();
>   			appender.SecurityContext = NullSecurityContext.Instance;
> @@ -1921,9 +2019,9 @@
>   					throw new Exception("Unexpected Environment.NewLine.Length");
>   			}
>   		}
> -	}
> +    }
>   
> -	[TestFixture]
> +    [TestFixture]
>   	public class RollingFileAppenderSubClassTest : RollingFileAppender
>   	{
>   		[Test]
Regression tests are always great. Unfortunately I cannot determine if 
these are sensible or not since the patch is too big. It would make 
sense to split the previous patches into chunks that come together with 
all the tests.