[chronojump] First NUnit test done



commit 8c14942924cb23f78578fbf838c04741caae451f
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Aug 7 14:44:59 2014 +0200

    First NUnit test done

 NUnit/encoder/compile.txt     |    7 ++++
 NUnit/encoder/encoderTests.cs |   54 +++++++++++++++++++++++++++++
 src/encoder.cs                |   76 +++++++---------------------------------
 src/gui/encoder.cs            |    8 +++-
 src/util.cs                   |    2 +-
 5 files changed, 82 insertions(+), 65 deletions(-)
---
diff --git a/NUnit/encoder/compile.txt b/NUnit/encoder/compile.txt
new file mode 100644
index 0000000..62ca5ad
--- /dev/null
+++ b/NUnit/encoder/compile.txt
@@ -0,0 +1,7 @@
+export NUNIT_DLL="/usr/lib/mono/gac/nunit.framework/2.6.0.0__96d09a1eb7f44a77/nunit.framework.dll"
+export DIR="../../src"
+
+gmcs -debug -t:library -r:Mono.Data.Sqlite -r:Mono.Posix -r:System -r:System.Data -r:$NUNIT_DLL 
-out:encoder.dll encoderTests.cs $DIR/encoder.cs $DIR/constants.cs $DIR/utilDate.cs $DIR/log.cs 
$DIR/utilAll.cs $DIR/util.cs
+
+#execute: without the 4.0 there's a CLR error
+nunit-console -framework=4.0 encoder.dll
diff --git a/NUnit/encoder/encoderTests.cs b/NUnit/encoder/encoderTests.cs
new file mode 100644
index 0000000..05d98e0
--- /dev/null
+++ b/NUnit/encoder/encoderTests.cs
@@ -0,0 +1,54 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * Chronojump is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.^M
+ *
+ * Chronojump is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ *    GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  Copyright (C) 2004-2014   Xavier de Blas <xaviblas gmail com> 
+ */
+
+
+using NUnit.Framework;
+using System;
+
+namespace EncoderSQLTests {
+       [TestFixture]
+               public class EncoderSQLTests {
+                       private EncoderSQL eSQL = null;
+                       [SetUp]
+                               public void SetUp()
+                               {
+                                       eSQL = new EncoderSQL();
+                               }
+                       [Test]
+                               public void ValidateGetDateNoPretty()
+                               {
+                                       eSQL.Filename = "170-foo bar-2117-2013-10-31_10-12-13.txt";
+                                       string date = eSQL.GetDate(false);
+                                       Assert.AreEqual("2013-10-31_10-12-13", date);
+                               }
+                       [Test]
+                               public void ValidateGetDatePretty()
+                               {
+                                       eSQL.Filename = "170-foo bar-2117-2013-10-31_10-12-13.txt";
+                                       string date = eSQL.GetDate(true);
+                                       Assert.AreEqual("2013-10-31 10:12:13", date);
+                               }
+                       [TearDown]
+                               public void TearDown()
+                               {
+                                       eSQL = null;
+                               }
+               } 
+}    
diff --git a/src/encoder.cs b/src/encoder.cs
index b255200..43631e0 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -68,61 +68,6 @@ public class EncoderParams
        {
        }
 
-       /*
-       //to encoder capture
-       //RunEncoderCapturePython: pyserial_pyper.py and pyserial_pyper_windows.py . This will be deprecated 
soon 
-       public EncoderParams(int time, int minHeight, int exercisePercentBodyWeight, string mass, 
-                       string smoothCon, string eccon, string analysisOptions,
-                       double heightHigherCondition, double heightLowerCondition, 
-                       double meanSpeedHigherCondition, double meanSpeedLowerCondition, 
-                       double maxSpeedHigherCondition, double maxSpeedLowerCondition, 
-                       int powerHigherCondition, int powerLowerCondition, 
-                       int peakPowerHigherCondition, int peakPowerLowerCondition,
-                       string mainVariable//, bool inverted)
-               )
-       {
-               this.time = time;
-               this.minHeight = minHeight;
-               this.exercisePercentBodyWeight = exercisePercentBodyWeight;
-               this.mass = mass;
-               this.smoothCon = smoothCon;
-               this.eccon = eccon;
-               this.analysisOptions = analysisOptions;
-               this.heightHigherCondition = heightHigherCondition;
-               this.heightLowerCondition = heightLowerCondition;
-               this.meanSpeedHigherCondition = meanSpeedHigherCondition;
-               this.meanSpeedLowerCondition = meanSpeedLowerCondition;
-               this.maxSpeedHigherCondition = maxSpeedHigherCondition;
-               this.maxSpeedLowerCondition = maxSpeedLowerCondition;
-               this.powerHigherCondition = powerHigherCondition;
-               this.powerLowerCondition = powerLowerCondition;
-               this.peakPowerHigherCondition = peakPowerHigherCondition;
-               this.peakPowerLowerCondition = peakPowerLowerCondition;
-               this.mainVariable = mainVariable;
-               //this.inverted = inverted;
-       }
-
-       //to encoder capture
-       //RunEncoderCapturePython: pyserial_pyper.py and pyserial_pyper_windows.py . This will be deprecated 
soon 
-       public string ToString1 () 
-       {
-               string analysisOptionsPrint = analysisOptions;
-               if(analysisOptionsPrint == "")
-                       analysisOptionsPrint = "none";
-
-               return time.ToString() + " " + minHeight.ToString() + " " + 
exercisePercentBodyWeight.ToString() + 
-                       " " + mass.ToString() + " " + smoothCon + " " + eccon + " " + analysisOptionsPrint +
-                       " " + heightHigherCondition.ToString() +        " " + heightLowerCondition.ToString() 
+
-                       " " + Util.ConvertToPoint(meanSpeedHigherCondition.ToString()) +        
-                       " " + Util.ConvertToPoint(meanSpeedLowerCondition.ToString()) +
-                       " " + Util.ConvertToPoint(maxSpeedHigherCondition.ToString()) +         
-                       " " + Util.ConvertToPoint(maxSpeedLowerCondition.ToString()) +
-                       " " + powerHigherCondition.ToString() +         " " + powerLowerCondition.ToString() +
-                       " " + peakPowerHigherCondition.ToString() +     " " + 
peakPowerLowerCondition.ToString() +
-                       " " + mainVariable //+ " " + Util.BoolToInt(inverted).ToString();
-               ;
-       }
-       */
        
        //to graph.R    
        public EncoderParams(int minHeight, int exercisePercentBodyWeight, string massBody, string massExtra, 
@@ -624,7 +569,7 @@ public class EncoderSQL
        }
 
        //uniqueID:name
-       public void ChangePerson(string newIDAndName) {
+       public EncoderSQL ChangePerson(string newIDAndName) {
                int newPersonID = Util.FetchID(newIDAndName);
                string newPersonName = Util.FetchName(newIDAndName);
                string newFilename = filename;
@@ -670,9 +615,17 @@ public class EncoderSQL
                if(success)
                        filename = newFilename;
 
-               //SqliteUpdate
-               SqliteEncoder.Update(false, this);
+               //will update SqliteEncoder
+               return (this);
        }
+
+
+       //used in NUnit
+       public string Filename
+       {
+               set { filename = value; }
+       }
+
 }
 
 
@@ -889,9 +842,9 @@ public class EncoderConfiguration {
                gearedDown = 1;
        }
 
-       /* note: if this changes, change also in:
-        * UtilEncoder.EncoderConfigurationList(enum encoderType)
-        */
+       // note: if this changes, change also in:
+       // UtilEncoder.EncoderConfigurationList(enum encoderType)
+       
        public EncoderConfiguration(Constants.EncoderConfigurationNames name) {
                this.name = name;
                has_d = false;
@@ -1142,5 +1095,4 @@ public class EncoderConfiguration {
 
                return code + str_d + str_D + str_anglePush + str_angleWeight + str_inertia + str_gearedDown;
        }
-       
 }
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 28a30d9..53b7af1 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -919,7 +919,9 @@ public partial class ChronoJumpWindow
                Log.WriteLine("new person: " + genericWin.GetComboSelected);
                int newPersonID = Util.FetchID(genericWin.GetComboSelected);
                if(newPersonID != currentPerson.UniqueID) {
-                       eSQL.ChangePerson(genericWin.GetComboSelected);
+                       EncoderSQL eSQLChangedPerson = eSQL.ChangePerson(genericWin.GetComboSelected);
+                       SqliteEncoder.Update(false, eSQLChangedPerson);
+
                        genericWin.RemoveSelectedRow();
                }
 
@@ -1318,7 +1320,9 @@ public partial class ChronoJumpWindow
                Log.WriteLine("new person: " + genericWin.GetComboSelected);
                int newPersonID = Util.FetchID(genericWin.GetComboSelected);
                if(newPersonID != currentPerson.UniqueID) {
-                       eSQL.ChangePerson(genericWin.GetComboSelected);
+                       EncoderSQL eSQLChangedPerson = eSQL.ChangePerson(genericWin.GetComboSelected);
+                       SqliteEncoder.Update(false, eSQLChangedPerson);
+                       
                        genericWin.RemoveSelectedRow();
                }
 
diff --git a/src/util.cs b/src/util.cs
index 8a0e13f..78e44bb 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -873,7 +873,7 @@ public class Util
 
        public static string GetPrefixDir(){
                string baseDirectory = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, 
"..");
-               if (!Directory.Exists(Path.Combine (baseDirectory, "lib", "chronojump"))) {
+               if (! Directory.Exists(Path.Combine(baseDirectory, "lib" + Path.DirectorySeparatorChar + 
"chronojump"))) {
                        baseDirectory = System.IO.Path.Combine(baseDirectory, "..");
                }
                return baseDirectory;


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