Commits

Anonymous committed bb075a4

Refactored code to improve unit tests.

  • Participants
  • Parent commits 9a8ab9f

Comments (0)

Files changed (9)

BlueGo.suo

Binary file modified.

BlueGo/BlueGo.csproj

     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="ServenZip.cs" />
     <Compile Include="Boost.cs" />
     <Compile Include="CMake.cs" />
     <Compile Include="Compiler.cs" />
     </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="UnitTest.cs" />
+    <Compile Include="UnitTest\BuildBoostTest.cs" />
+    <Compile Include="UnitTest\DownloadTest.cs" />
+    <Compile Include="UnitTest\UnitTest.cs" />
     <Compile Include="FormUpdate.cs">
       <SubType>Form</SubType>
     </Compile>
         }
     }    
 
-    class Boost
+    class BoostBuildProcess
     {
 
     }

BlueGo/FormMain.cs

 
         int coreCount = 0;
 
-        static bool is64BitProcess = (IntPtr.Size == 8);
-        static bool is64BitOperatingSystem = is64BitProcess || InternalCheckIsWow64();
 
-        [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
-        [return: MarshalAs(UnmanagedType.Bool)]
-        private static extern bool IsWow64Process(
-            [In] IntPtr hProcess,
-            [Out] out bool wow64Process
-        );
-
-        public static bool InternalCheckIsWow64()
-        {
-            if ((Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1) ||
-                Environment.OSVersion.Version.Major >= 6)
-            {
-                using (Process p = Process.GetCurrentProcess())
-                {
-                    bool retVal;
-                    if (!IsWow64Process(p.Handle, out retVal))
-                    {
-                        return false;
-                    }
-                    return retVal;
-                }
-            }
-            else
-            {
-                return false;
-            }
-        }
 
 
 
             }
         }
 
-        public static void Decompress(string filename, string destinationFolder)
-        {
-            string sevenZipExePath = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\" + "7z.exe";
-
-            if (!System.IO.File.Exists(sevenZipExePath))
-            {
-                throw new Exception("Could not locate 7zip - maybe installation failed. Tried to use 7z.exe from " + sevenZipExePath );
-            }
-
-            if(!is64BitOperatingSystem)
-            {
-                throw new Exception("Expecting a 64 bit operating system. You are running not a x64 operating system. 7z ");
-            }
-
-            // path needs not
-            //CheckDestinationFolder(destinationFolder);
-
-            try
-            {
-                Process p = new Process();
-                ProcessStartInfo info = new ProcessStartInfo(sevenZipExePath, "x -o" + destinationFolder + " " + filename);
-                p.StartInfo = info;
-                p.Start();
-                p.WaitForExit();
-
-                if (p.ExitCode != 0)
-                    throw new Exception("Decompressing failed. Maybe download is invalid.");
-            }
-            catch (System.Exception ex)
-            {
-                throw new Exception(ex.Message);
-            }
-        }
-
         void DownloadAndBuildQT4_8_3_x64()
         {
             string destinationFolder = DetermineDestinationFolder();
             message("extracting QT");
 
             // Extract Qt
-            Decompress(destinationFolder + Qt4_8_3ZipFilename, destinationFolder);
+            SevenZip.Decompress(destinationFolder + Qt4_8_3ZipFilename, destinationFolder);
 
             eCompiler compilerType = DetermineSelectedCompiler();
             if(compilerType == eCompiler.VS2012)
                     //}
                 //}
 
-                // Download boost
-                // Check if URL is valid
-                //bool validUrl = DownloadHelper.RemoteFileExists(boostDownloadURL);
-                //if (!validUrl)
-                //{
-                //    throw new Exception("Url " + boostDownloadURL + " is not valid.");
-                //}
-
                 DownloadHelper.DownloadFileFromURL(boostDownloadURL, destinationFolder + boostZIPFilename);
 
                 message("Start to unzip boost...");
                 }
 
                 // Unzip Boost 
-                Decompress(destinationFolder + "/" + boostZIPFilename, destinationFolder);
+                SevenZip.Decompress(destinationFolder + "/" + boostZIPFilename, destinationFolder);
 
                 message("boost has been unzipped!");
 

BlueGo/ServenZip.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+namespace BlueGo
+{
+    class SevenZip
+    {
+        public static void Decompress(string filename, string destinationFolder)
+        {
+            string sevenZipExePath = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\" + "7z.exe";
+
+            if (!System.IO.File.Exists(sevenZipExePath))
+            {
+                throw new Exception("Could not locate 7zip - maybe installation failed. Tried to use 7z.exe from " + sevenZipExePath);
+            }
+
+            if (!is64BitOperatingSystem)
+            {
+                throw new Exception("Expecting a 64 bit operating system. You are running not a x64 operating system. 7z ");
+            }
+
+            // path needs not
+            //CheckDestinationFolder(destinationFolder);
+
+            try
+            {
+                Process p = new Process();
+                ProcessStartInfo info = new ProcessStartInfo(sevenZipExePath, "x -o" + destinationFolder + " " + filename);
+                p.StartInfo = info;
+                p.Start();
+                p.WaitForExit();
+
+                if (p.ExitCode != 0)
+                    throw new Exception("Decompressing failed. Maybe download is invalid.");
+            }
+            catch (System.Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+        }
+
+        static bool is64BitProcess = (IntPtr.Size == 8);
+        static bool is64BitOperatingSystem = is64BitProcess || InternalCheckIsWow64();
+
+        [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
+        [return: MarshalAs(UnmanagedType.Bool)]
+        private static extern bool IsWow64Process(
+            [In] IntPtr hProcess,
+            [Out] out bool wow64Process
+        );
+
+        public static bool InternalCheckIsWow64()
+        {
+            if ((Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1) ||
+                Environment.OSVersion.Version.Major >= 6)
+            {
+                using (Process p = Process.GetCurrentProcess())
+                {
+                    bool retVal;
+                    if (!IsWow64Process(p.Handle, out retVal))
+                    {
+                        return false;
+                    }
+                    return retVal;
+                }
+            }
+            else
+            {
+                return false;
+            }
+        }
+    }
+}

BlueGo/UnitTest.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NUnit.Framework;
-using System.IO;
-using System.Net;
-
-namespace BlueGo
-{
-    namespace UnitTest
-    {
-        [TestFixture]
-        public class DownloadTest
-        {
-            [Test]
-            public void DownloadBoost()
-            {
-                try
-                {
-                    eBoostVersion boostVersion = eBoostVersion.Boost1_52_0;
-                
-                    string destinationFolder = @"C:\UnitTest\";
-                
-                    if (!Directory.Exists(destinationFolder))
-                    {
-                        Directory.CreateDirectory(destinationFolder);
-                    }
-
-                    string boostDownloadURL = BoostInfo.GetBoostDownloadURL(boostVersion);
-                    string boostZIPFilename = BoostInfo.GetBoostZipFileName(boostVersion);
-
-                    // Download boost
-                    // Check if URL is valid
-                    bool validUrl = DownloadHelper.RemoteFileExists(boostDownloadURL);
-                    Assert.True(validUrl);
-
-                    DownloadHelper.DownloadFileFromURL(boostDownloadURL,  destinationFolder + boostZIPFilename);
-
-                    if (boostVersion == eBoostVersion.Boost1_51_0)
-                    {
-                        FileInfo fi = new FileInfo(destinationFolder + boostZIPFilename);
-                        long fileLength = fi.Length;
-
-                        Assert.True(fileLength == 91365553);
-                    }
-
-                    if (boostVersion == eBoostVersion.Boost1_52_0)
-                    {
-                        FileInfo fi = new FileInfo(destinationFolder + boostZIPFilename);
-                        long fileLength = fi.Length;
-
-                        Assert.True(fileLength == 95342510);
-                    }
-                    
-                }
-                catch (System.Exception ex)
-                {
-                    Assert.True(false);	
-                }
-            }
-         
-
-          
-        }
-    }
-}

BlueGo/UnitTest/BuildBoostTest.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using System.IO;
+
+namespace BlueGo.UnitTest
+{ 
+    [TestFixture]
+    class BuildBoostTest
+    {
+        public void DownloadAndBuildBoost1_52_0_VS2012_x64()
+        {
+            try
+            {
+                eBoostVersion boostVersion = eBoostVersion.Boost1_52_0;
+
+                string destinationFolder = GlobalVariables.destinationFolder + @"DownloadAndBuildBoost1_52_0_VS2012_x64\";
+
+                if (!Directory.Exists(destinationFolder))
+                {
+                    Directory.CreateDirectory(destinationFolder);
+                }
+
+                string boostDownloadURL = BoostInfo.GetBoostDownloadURL(boostVersion);
+                string boostZIPFilename = BoostInfo.GetBoostZipFileName(boostVersion);
+
+                // Download boost
+                // Check if URL is valid
+                bool validUrl = DownloadHelper.RemoteFileExists(boostDownloadURL);
+                Assert.True(validUrl);
+
+                DownloadHelper.DownloadFileFromURL(boostDownloadURL, destinationFolder + boostZIPFilename);
+
+                if (boostVersion == eBoostVersion.Boost1_51_0)
+                {
+                    FileInfo fi = new FileInfo(destinationFolder + boostZIPFilename);
+                    long fileLength = fi.Length;
+
+                    Assert.True(fileLength == 91365553);
+                }
+
+                if (boostVersion == eBoostVersion.Boost1_52_0)
+                {
+                    FileInfo fi = new FileInfo(destinationFolder + boostZIPFilename);
+                    long fileLength = fi.Length;
+
+                    Assert.True(fileLength == 95342510);
+                }
+
+                // Unzip Boost 
+                SevenZip.Decompress(destinationFolder + "/" + boostZIPFilename, destinationFolder);
+
+
+                // Delete File
+                System.IO.File.Delete(destinationFolder + boostZIPFilename);
+            }
+            catch (System.Exception ex)
+            {
+                Assert.True(false);
+            }
+        }
+    }
+}

BlueGo/UnitTest/DownloadTest.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using System.IO;
+using System.Net;
+
+namespace BlueGo
+{
+    namespace UnitTest
+    {
+        [TestFixture]
+        public class DownloadTest
+        {
+            [Test]
+            public void DownloadBoost()
+            {
+                try
+                {
+                    eBoostVersion boostVersion = eBoostVersion.Boost1_52_0;
+
+                    string destinationFolder = GlobalVariables.destinationFolder +  @"DownloadBoost\";
+
+                    if (!Directory.Exists(destinationFolder))
+                    {
+                        Directory.CreateDirectory(destinationFolder);
+                    }
+
+                    string boostDownloadURL = BoostInfo.GetBoostDownloadURL(boostVersion);
+                    string boostZIPFilename = BoostInfo.GetBoostZipFileName(boostVersion);
+
+                    // Download boost
+                    // Check if URL is valid
+                    bool validUrl = DownloadHelper.RemoteFileExists(boostDownloadURL);
+                    Assert.True(validUrl);
+
+                    DownloadHelper.DownloadFileFromURL(boostDownloadURL, destinationFolder + boostZIPFilename);
+
+                    if (boostVersion == eBoostVersion.Boost1_51_0)
+                    {
+                        FileInfo fi = new FileInfo(destinationFolder + boostZIPFilename);
+                        long fileLength = fi.Length;
+
+                        Assert.True(fileLength == 91365553);
+                    }
+
+                    if (boostVersion == eBoostVersion.Boost1_52_0)
+                    {
+                        FileInfo fi = new FileInfo(destinationFolder + boostZIPFilename);
+                        long fileLength = fi.Length;
+
+                        Assert.True(fileLength == 95342510);
+                    }
+
+                    // Delete File
+                    System.IO.File.Delete(destinationFolder + boostZIPFilename);
+                }
+                catch (System.Exception ex)
+                {
+                    Assert.True(false);
+                }
+            }
+        } // end class DownloadTest
+    } // end namespace UnitTest
+} // end namespace BlueGo

BlueGo/UnitTest/UnitTest.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using System.IO;
+using System.Net;
+
+namespace BlueGo
+{
+    namespace UnitTest
+    {
+        public class GlobalVariables
+        {
+            public static string destinationFolder = @"E:\UnitTest\";
+        }
+    }
+}