static void Main(string[] args) { // ############################################################################################################################ // ##### TextFile // ############################################################################################################################ #region TexteFile //Declaration des variables TextFile textFileFromFile = null; // Fichier permettant de lire un fichier depuis le disque TextFile newTextFile = null; // Fichier pour tester l'ajout et la suppression de ligne bool Validated = true; // Test 0101 : Creation d'un fichier texte __________________________________________________________________________ try { DisplaySeparator(); Console.WriteLine("Test 0101 - Creation et chargement d'un fichier texte : \n"); Console.WriteLine(" -> Creation du fichier"); textFileFromFile = new TextFile(); // ------------------------------------------------------------------------------------------ Console.Write(" -> Chargement du fichier de test :"); if (textFileFromFile.Load("TestFiles/Test_Load.txt") >= 0) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Chargement du fichier vide : "); if (textFileFromFile.Load("TestFiles/Test_EmptyFile.txt") >= 0) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Tentative d'ouverture d'un fichier inexistant : "); if (textFileFromFile.Load("InvalidFile") == -1) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> FilePath vide : "); if (textFileFromFile.Load("") == -1) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Chargement d'un fichier de 100 Lignes : "); if (textFileFromFile.Load("TestFiles/Test_100Lines.txt") == 100) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Chargement d'un fichier de 1000 Lignes : "); if (textFileFromFile.Load("TestFiles/Test_1000Lines.txt") == 1000) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Chargement d'un fichier de 10000 Lignes : "); if (textFileFromFile.Load("TestFiles/Test_10000Lines.txt") == 10000) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0101 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } // Test 0102 : Verification des propriétés __________________________________________________________________________ try { DisplaySeparator(); Console.WriteLine("Test 0102 - Test des priorités : \n"); Console.WriteLine(" -> Creation du fichier"); newTextFile = new TextFile(); // ------------------------------------------------------------------------------------------ Console.Write(" -> Count sur un fichier vide :"); if (newTextFile.Count() == 0) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Count sur un fichier normal (100 Lignes) :"); newTextFile.Load("TestFiles/Test_100Lines.txt"); if (newTextFile.Count() == 100) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Count sur un fichier normal (1000 Lignes) :"); newTextFile.Load("TestFiles/Test_1000Lines.txt"); if (newTextFile.Count() == 1000) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0102 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } // Test 0103 : Ajout de ligne _______________________________________________________________________________________ try { DisplaySeparator(); Console.WriteLine("Test 0103 - Ajout de nouvelle ligne : \n"); Console.WriteLine(" -> Creation du fichier"); newTextFile = new TextFile(); // ------------------------------------------------------------------------------------------ Console.Write(" -> Ajout d'une ligne dans un fichier vide:"); newTextFile.AddLine("Ligne 01"); if (newTextFile.Count() == 1) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Ajout d'une ligne vide :"); newTextFile.AddLine(null); if (newTextFile.Count() == 1) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Ajout d'une ligne sans contenu :"); newTextFile.AddLine(""); if (newTextFile.Count() == 2) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Ajout d'une ligne avec un index erroné :"); newTextFile.AddLine("Ligne -1", -1); if (newTextFile.Count() == 2) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Ajout d'une ligne à un index spécifié :"); newTextFile.AddLine("Ligne 00", 0); if (newTextFile.Count() == 3) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Ajout d'une ligne null à un index spécifié :"); newTextFile.AddLine(null, 0); if (newTextFile.Count() == 3) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Ajout d'une ligne à un index erroné :"); newTextFile.AddLine(null, -1); if (newTextFile.Count() == 3) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0103 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } // Test 0104 : Récupération d'une ligne _____________________________________________________________________________ try { DisplaySeparator(); Console.WriteLine("Test 0104 - Lecture d'une ligne : \n"); Console.WriteLine(" -> Creation du fichier"); newTextFile = new TextFile(); // ------------------------------------------------------------------------------------------ Console.Write(" -> Lecture d'une ligne dans un fichier vide:"); if (newTextFile.GetLine(0) == null) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Lecture d'une ligne avec un index négatif :"); newTextFile.AddLine("Ligne 01"); newTextFile.AddLine("Ligne 02"); newTextFile.AddLine("Ligne 03"); if (newTextFile.GetLine(-1) == null) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Lecture d'une ligne avec un index erroné :"); if (newTextFile.GetLine(100) == null) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Lecture d'une ligne valide :"); if (newTextFile.GetLine(0) == "Ligne 01") { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Lecture de la dernière ligne du fichier :"); if (newTextFile.GetLine(2) == "Ligne 03") { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0104 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } // Test 0105 : Sauvegarde du fichier ________________________________________________________________________________ try { DisplaySeparator(); Console.WriteLine("Test 0105 - Sauvegarde des fichiers : \n"); Console.WriteLine(" -> Creation du fichier"); newTextFile = new TextFile(); // ------------------------------------------------------------------------------------------ Console.Write(" -> Sauvegarde d'un fichier non initialisé :"); if (newTextFile.Save() == -1) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Sauvegarde d'un fichier null :"); if (newTextFile.SaveTo(null) == -1) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Sauvegarde d'un fichier non valide :"); if (newTextFile.SaveTo("Invalid") == -1) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Sauvegarde dans un fichier valide :"); newTextFile.Load("TestFiles/Test_100Lines.txt"); if (newTextFile.SaveTo("TestFiles/Test_100Lines_ouptut_SaveTo.txt") == 100) { Console.Write(" Ok + Verification manuelle à réaliser\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Sauvegarde d'un fichier valide :"); newTextFile.SaveTo("TestFiles/Test_100Lines_ouptut_Save.txt"); if (newTextFile.Save() == 100) { Console.Write(" Ok + Verification manuelle à réaliser\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0105 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } // Test 0106 : Caractère spéciaux ___________________________________________________________________________________ try { DisplaySeparator(); Console.WriteLine("Test 0106 - Utilisation de caractères spéciaux : \n"); Console.WriteLine(" -> Creation du fichier"); newTextFile = new TextFile(); String textToCheck = "\t&@éèàûîêäëïç'§µ%"; newTextFile.AddLine(textToCheck); // ------------------------------------------------------------------------------------------ Console.Write(" -> Ecriture du fichier :"); if (newTextFile.SaveTo("TestFiles/SpecificChar.txt") > 0) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Relecture du fichier :"); newTextFile.Load("TestFiles/SpecificChar.txt"); if (newTextFile.GetLine(0) == textToCheck) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0106 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } // Test 0107 : Suppression d'une ligne ______________________________________________________________________________ try { DisplaySeparator(); Console.WriteLine("Test 0107 - Suppression d'une ligne : \n"); Console.WriteLine(" -> Creation du fichier"); newTextFile = new TextFile(); // ------------------------------------------------------------------------------------------ Console.Write(" -> Suppression d'une ligne dans un fichier vide :"); newTextFile.RemoveLine(0); if (newTextFile.Count() == 0) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Suppression d'une ligne non valide :"); newTextFile.RemoveLine(-1); if (newTextFile.Count() == 0) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Suppression d'une ligne dans un fichier :"); newTextFile.AddLine("Ligne01"); newTextFile.AddLine("Ligne02"); newTextFile.AddLine("Ligne03"); newTextFile.RemoveLine(0); if ((newTextFile.Count() == 2) && (newTextFile.GetLine(0) == "Ligne02")) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Suppression de toutes les lignes d'un fichier :"); newTextFile.AddLine("Ligne01"); newTextFile.AddLine("Ligne02"); newTextFile.AddLine("Ligne03"); newTextFile.RemoveAllLine(); if (newTextFile.Count() == 0) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0107 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } #endregion // ############################################################################################################################ // ##### StructuredFileKey // ############################################################################################################################ #region StructuredFileKey StructuredFileKey testKey = null; // Test 0201 : Constructeurs ________________________________________________________________________________________ try { DisplaySeparator(); Console.WriteLine("Test 0201 - StructuredFileKey : \n"); // ------------------------------------------------------------------------------------------ Console.Write(" -> Constructeur vide :"); testKey = new StructuredFileKey(); if ((null != testKey) && (testKey.keyName == null) && (testKey.valueString == null)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.Write(" -> Constructeur avec paramètres ('keyString', 'valueString') :"); testKey = new StructuredFileKey("keyString", "valueString"); if ((null != testKey) && (testKey.keyName == "keyString") && (testKey.valueString == "valueString")) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.Write(" -> Constructeur avec paramètres ('keyInt', 100) :"); testKey = new StructuredFileKey("keyInt", 100); if ((null != testKey) && (testKey.keyName == "keyInt") && (testKey.valueInt == 100)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.Write(" -> Constructeur avec paramètres ('keyDouble', 1.2) :"); testKey = new StructuredFileKey("keyDouble", 1.2); if ((null != testKey) && (testKey.keyName == "keyDouble") && (testKey.valueDouble == 1.2)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0201 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } #endregion // ############################################################################################################################ // ##### StructuredFileGroup // ############################################################################################################################ #region StructuredFileGroup StructuredFileGroup testKeyGroup = null; StructuredFileGroup testKeyGroup1 = null; StructuredFileGroup testKeyGroup2 = null; // Test 0301 : Constructeurs ________________________________________________________________________________________ try { DisplaySeparator(); Console.WriteLine("Test 0301 - StructuredFileGroup : \n"); // ------------------------------------------------------------------------------------------ Console.Write(" -> Constructeur vide :"); testKeyGroup = new StructuredFileGroup(0); if ((testKeyGroup.ID == 0) && (testKeyGroup.GetAllKeys() == null)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.Write(" -> Constructeur avec paramètres (groupID = 0 et key = null) :"); testKeyGroup = new StructuredFileGroup(0, null); if ((testKeyGroup.ID == 0) && (testKeyGroup.GetAllKeys() == null)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.Write(" -> Constructeur avec paramètres (groupID=0 et key=(TestKey, TestValue) :"); testKeyGroup = new StructuredFileGroup(5, new StructuredFileKey("TestKey", "TestValue")); if ((testKeyGroup.ID == 5) && (testKeyGroup.GetAllKeys().Count == 1)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.Write(" -> Test de la fonction Add() :"); testKeyGroup = new StructuredFileGroup(1); testKeyGroup.AddKey(new StructuredFileKey("1", "1")); testKeyGroup.AddKey(new StructuredFileKey("2", "2")); if ((testKeyGroup.ID == 1) && (testKeyGroup.GetAllKeys().Count == 2)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.Write(" -> Test de la fonction Add(List<>) :"); testKeyGroup = new StructuredFileGroup(1); List<StructuredFileKey> listToAdd = new List<StructuredFileKey>(); listToAdd.Add(new StructuredFileKey("1", "1")); listToAdd.Add(new StructuredFileKey("2", "2")); testKeyGroup.AddKey(listToAdd); if ((testKeyGroup.ID == 1) && (testKeyGroup.Count() == 2)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.Write(" -> Test de la fonction Count() :"); testKeyGroup = new StructuredFileGroup(1, null); testKeyGroup1 = new StructuredFileGroup(1, new StructuredFileKey("Key1", "Value1")); testKeyGroup2 = new StructuredFileGroup(2, new StructuredFileKey("Key1", "Value1")); testKeyGroup2.AddKey(new StructuredFileKey("Key2", "Value2")); if ((testKeyGroup.Count() == 0) && (testKeyGroup1.Count() == 1) && (testKeyGroup2.Count() == 2)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.Write(" -> Test de la fonction GetAllKeys() :"); testKeyGroup = new StructuredFileGroup(1); testKeyGroup.AddKey(new StructuredFileKey("Key1", "Value1")); testKeyGroup.AddKey(new StructuredFileKey("Key2", "Value2")); if ((testKeyGroup.ID == 1) && (testKeyGroup.GetAllKeys().Count() == 2)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.Write(" -> Test de la fonction GetKeys(keyID) :"); testKeyGroup = new StructuredFileGroup(1); testKeyGroup.AddKey(new StructuredFileKey("Key1", "Value1")); testKeyGroup.AddKey(new StructuredFileKey("Key2", "Value2")); testKeyGroup.AddKey(new StructuredFileKey("Key2", "Value22")); if ((testKeyGroup.ID == 1) && (testKeyGroup.GetKeys("Key3") == null) && (testKeyGroup.GetKeys("Key2").Count() == 2)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0301 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } #endregion // ############################################################################################################################ // ##### StructuredFile // ############################################################################################################################ #region StructuredFile StructuredFile testStructuredFile = null; StructuredFile testStructuredFile2 = null; // Test 0401 : Constructeurs ________________________________________________________________________________________ try { DisplaySeparator(); Console.WriteLine("Test 0401 - Constructeurs : \n"); // ------------------------------------------------------------------------------------------ Console.Write(" -> Constructeur vide :"); testStructuredFile = new StructuredFile(); if (null != testStructuredFile) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Constructeur avec paramètre :"); testStructuredFile = new StructuredFile("CheminInvalid"); if (null != testStructuredFile) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Fonction GetAllGroupID vide :"); testStructuredFile = new StructuredFile(); if (testStructuredFile.GetAllGroup() == null) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Fonction d'ajout :"); testStructuredFile = new StructuredFile(); testStructuredFile2 = new StructuredFile(); testStructuredFile.AddGroup(new StructuredFileGroup(1)); testStructuredFile.AddGroup(null); testStructuredFile2.AddGroup(new StructuredFileGroup(1, new StructuredFileKey("Key1", 1))); testStructuredFile2.AddGroup(new StructuredFileGroup(1, new StructuredFileKey("Key2", 2))); testStructuredFile2.AddGroup(new StructuredFileGroup(2, new StructuredFileKey("Key3", 3))); if ((testStructuredFile.GetAllGroup().Count() == 1) && (testStructuredFile.GetAllGroup().Count() == 1)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Fonction de suppression totale :"); testStructuredFile = new StructuredFile(); testStructuredFile2 = new StructuredFile(); testStructuredFile.AddGroup(new StructuredFileGroup(1)); testStructuredFile.AddGroup(new StructuredFileGroup(2)); testStructuredFile.AddGroup(new StructuredFileGroup(3)); testStructuredFile.RemoveAllGroup(); testStructuredFile2.RemoveAllGroup(); if ((testStructuredFile.GetAllGroup() == null) && (testStructuredFile2.GetAllGroup() == null)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Fonction de suppression à partir de l'ID :"); testStructuredFile = new StructuredFile(); testStructuredFile2 = new StructuredFile(); testStructuredFile.AddGroup(new StructuredFileGroup(1)); testStructuredFile.AddGroup(new StructuredFileGroup(2)); testStructuredFile.AddGroup(new StructuredFileGroup(3)); testStructuredFile.RemoveGroupByID(2); testStructuredFile.RemoveGroupByID(5); testStructuredFile2.RemoveGroupByID(5); if (testStructuredFile.GetAllGroup().Count() == 2) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Fonction de recherche à partir de l'ID :"); testStructuredFile = new StructuredFile(); testStructuredFile2 = new StructuredFile(); testStructuredFile.AddGroup(new StructuredFileGroup(1)); testStructuredFile.AddGroup(new StructuredFileGroup(2)); testStructuredFile.AddGroup(new StructuredFileGroup(3)); if ((testStructuredFile2.GetGroupByID(5) == null) && (testStructuredFile.GetGroupByID(5) == null) && (testStructuredFile.GetGroupByID(2).ID == 2)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Ecriture du fichier via SaveTo (format par défaut) :"); testStructuredFile = new StructuredFile(); testStructuredFile2 = new StructuredFile(); testStructuredFile.AddGroup(new StructuredFileGroup(1)); StructuredFileGroup newGroup = new StructuredFileGroup(2,new StructuredFileKey("Key1", 1)); newGroup.AddKey(new StructuredFileKey("Key2", 2)); newGroup.AddKey(new StructuredFileKey("Key3", 3)); testStructuredFile.AddGroup(newGroup); testStructuredFile.AddGroup(new StructuredFileGroup(3,new StructuredFileKey("Key1", 10))); if ((testStructuredFile.SaveTo("TestFiles/StructuredFile.sfile") > 0) && (testStructuredFile2.SaveTo("TestFiles/StructuredFileErr.sfile") == -1)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.Write(" -> Ecriture du fichier via Save (format par défaut) :"); if ((testStructuredFile.Save() > 0) && (testStructuredFile2.Save() == -1)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Lecture d'un fichier :"); newTextFile = new TextFile(); newTextFile.AddLine("key1 = A"); newTextFile.AddLine("key2 = B"); newTextFile.AddLine("[Groupe 5]"); newTextFile.AddLine("key3 = C"); newTextFile.AddLine("key4 = D"); newTextFile.AddLine("key5 E"); newTextFile.AddLine("key6 = F"); newTextFile.AddLine("key7 = G"); newTextFile.AddLine("key8 = H"); newTextFile.AddLine("key9 = I"); newTextFile.AddLine(" "); newTextFile.AddLine("key10 = J"); newTextFile.AddLine("[Groupe A]"); newTextFile.AddLine("key11 = K"); newTextFile.AddLine("key12 = L"); newTextFile.AddLine("[ Groupe 5]"); newTextFile.AddLine("[Groupe 7]"); newTextFile.AddLine("[Groupe 5]"); newTextFile.AddLine("key13 = M"); testStructuredFile = new StructuredFile(); if ((testStructuredFile.Load(newTextFile) > 0) && (testStructuredFile.SaveTo("TestFiles/StructuredFile2.sfile") > 0)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Export d'un fichier :"); newTextFile = new TextFile(); newTextFile.AddLine("[Groupe 0]"); newTextFile.AddLine("Key1 = (0,1)"); newTextFile.AddLine("Key2 = (0,2)"); newTextFile.AddLine("[Groupe 2]"); newTextFile.AddLine("Key1 = (2,1)"); newTextFile.AddLine("Key2 = (2,2)"); newTextFile.AddLine("[Groupe 3]"); newTextFile.AddLine("Key1 = (3,1)"); newTextFile.AddLine("Key2 = (3,2)"); newTextFile.AddLine("[Groupe 1]"); newTextFile.AddLine("Var1 = Var1-1"); newTextFile.AddLine("Var2 = Var2-1"); newTextFile.AddLine("Var3 = Var3-1"); newTextFile.AddLine("Var4 = Var4-1"); newTextFile.AddLine("Var5 = Var5-1"); newTextFile.AddLine("[Groupe 2]"); newTextFile.AddLine("Var1 = Var1-2"); newTextFile.AddLine("Var2 = Var2-2"); newTextFile.AddLine("Var3 = Var3-2"); newTextFile.AddLine("Var4 = Var4-2"); newTextFile.AddLine("Var5 = Var5-2"); newTextFile.AddLine("[Groupe 3]"); newTextFile.AddLine("Var1 = Var1-3"); newTextFile.AddLine("Var2 = Var2-3"); newTextFile.AddLine("Var3 = Var3-3"); newTextFile.AddLine("Var4 = Var4-3"); newTextFile.AddLine("Var5 = Var5-3"); newTextFile.AddLine("[Groupe 4]"); newTextFile.AddLine("Var1 = Var1-4"); newTextFile.AddLine("Var2 = Var2-4"); newTextFile.AddLine("Var3 = Var3-4"); newTextFile.AddLine("Var4 = Var4-4"); newTextFile.AddLine("Var5 = Var5-4"); newTextFile.AddLine("[Groupe 5]"); newTextFile.AddLine("Var1 = Var1-5"); newTextFile.AddLine("Var2 = Var2-5"); newTextFile.AddLine("Var3 = Var3-5"); newTextFile.AddLine("Var4 = Var4-5"); newTextFile.AddLine("Var5 = Var5-5"); testStructuredFile = new StructuredFile(); testStructuredFile.Load(newTextFile); testStructuredFile.SetPatternFile("TestFiles/ExportPatternFile.pattern"); if (testStructuredFile.Export("TestFiles/ExportPatternFile.output") == 6) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.Write(" -> Import d'un fichier :"); testStructuredFile = new StructuredFile(); testStructuredFile.SetPatternFile("TestFiles/ImportPatternFile.pattern"); if ((testStructuredFile.Import("TestFiles/ImportFile.txt") > 0) && (testStructuredFile.SaveTo("TestFiles/ImportFile.sfile") > 0)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0401 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } #endregion // Fin du programme ----------------------------------------------------------------------------- DisplaySeparator(); Console.Write("\nTest terminé. Etat du module : "); if(Validated == true) { Console.Write("Validé ! \n(Sous réserve que les fichiers de sortie soit valides)\n"); }else { Console.Write("Invalide !\n"); } Console.Read(); }
/// <summary> /// Permet d'exporter l'action en cours dans un StructuredFileGroup /// </summary> /// <returns>Un objet StructuredFileGroup</returns> public StructuredFileGroup Export() { // Creation du groupe StructuredFileGroup Ret = new StructuredFileGroup(Convert.ToUInt32(_uID)); // Ajout des données Ret.AddKey(new StructuredFileKey(ExchangeTag.cmd, _cmd.ToString())); Ret.AddKey(new StructuredFileKey(ExchangeTag.cmdType, _cmdType.ToString())); Ret.AddKey(new StructuredFileKey(ExchangeTag.param1, _param1)); Ret.AddKey(new StructuredFileKey(ExchangeTag.param2, _param2)); Ret.AddKey(new StructuredFileKey(ExchangeTag.param3, _param3)); Ret.AddKey(new StructuredFileKey(ExchangeTag.param4, _param4)); Ret.AddKey(new StructuredFileKey(ExchangeTag.activeSensors, _activeSensors.Activated)); Ret.AddKey(new StructuredFileKey(ExchangeTag.nextID, _nextID)); Ret.AddKey(new StructuredFileKey(ExchangeTag.timeoutID, _timeoutID)); return Ret; }
/// <summary> /// Crée un dossier ayant le nom de la stratégie dans le dossier "Data" à coté de l'executable /// La stratégie principale + toutes les sous-stratégies sont exportées dans des fichiers indépendants /// ATTENTION : Si le sous dossier existe déjà, il est détruit et remplacé par la sauvegarde courante (sans confirmation) /// </summary> public void Save() { // Verification des données internes if ((_strategyName != null) && (_subStrategies != null)) { try { String outputDir = Directory.GetCurrentDirectory().ToString() + "/"+ PrivateConst.outputDir + _strategyName +"/"; // Verification du répertoire de sortie if (Directory.Exists(Directory.GetCurrentDirectory().ToString() + "/" + PrivateConst.outputDir) != true) { // Si le dossier n'existe pas, il faut le créer Directory.CreateDirectory(Directory.GetCurrentDirectory().ToString() + "/" + PrivateConst.outputDir); } // Verification du sous répertoire de sortie if (Directory.Exists(outputDir) == true) { // Si le dossier existe, il faut le vider Directory.Delete(outputDir, true); } while (Directory.Exists(outputDir) == true) Thread.Sleep(500); // Creation du répertoire de sortie while (Directory.Exists(outputDir) == false) { Thread.Sleep(1000); Directory.CreateDirectory(outputDir); } // Sauvegarde des informations générales StructuredFile mainFile = new StructuredFile(); StructuredFileGroup mainGroup = new StructuredFileGroup(0); mainGroup.AddKey(new StructuredFileKey(PrivateConst.mainStrategyName, _strategyName)); mainGroup.AddKey(new StructuredFileKey(PrivateConst.TAG_InitialPosX, _initialPos.param2)); mainGroup.AddKey(new StructuredFileKey(PrivateConst.TAG_InitialPosY, _initialPos.param3)); mainGroup.AddKey(new StructuredFileKey(PrivateConst.TAG_InitialPosA, _initialPos.param4)); mainGroup.AddKey(new StructuredFileKey(PrivateConst.TAG_DefaultSpeed, _defaultSpeed)); mainGroup.AddKey(new StructuredFileKey(PrivateConst.TAG_DefaultPivotSpeed, _defaultPivotSpeed)); mainFile.AddGroup(mainGroup); mainFile.SaveTo(outputDir + _strategyName + ".strategy"); mainFile = null; mainGroup = null; // Sauvegarde des sub-stratégies foreach(SubStrategy currentSubStrategy in _subStrategies) { currentSubStrategy.Save(outputDir + currentSubStrategy.Name + ".sfile"); // Verification du répertoire d'import if (Directory.Exists(Directory.GetCurrentDirectory().ToString() + "/" + PrivateConst.outputDir) != true) { // Si le dossier n'existe pas, il faut le créer Directory.CreateDirectory(Directory.GetCurrentDirectory().ToString() + "/" + PrivateConst.outputDir); } } } catch (Exception ex) { MessageBox.Show("Erreur d'écriture de la stratégie !", "Strategy Generator", MessageBoxButtons.OK, MessageBoxIcon.Error); _debugTool.WriteLine("Strategy.cs = " + ex.Message); } } }
/// <summary> /// Export current strategy into an external file (given as parameter) /// </summary> /// <param name="outputFileName">filename of output file</param> /// <param name="patternFileName">pattern file to use for the exportation</param> /// <returns></returns> public int Export(String outputFileName, String patternFileName) { int Ret = -1; int iLine = 0; // iterator bool loopSubStrategyPatternFlag = false; // Flag pour indiquer si la ligne en cours est une ligne de sub-stratégie pattern String currentLine = ""; // Ligne courrante (pour copie et/ou analyse) StructuredFile outputFile = new StructuredFile(); // Fichier de sortie TextFile patternFile = new TextFile(); // Fichier pattern TextFile outputPatternFile = new TextFile(); // Fichier pattern à utiliser pour écrire le fichier de sortie List<String> loopSubStrategyPattern = new List<string>(); // Lignes à répéter pour les subStratégies dans le fichier de sortie try { // Verification des paramètres d'entrée et des paramètres internes if ((outputFileName != null) && (patternFileName != null) && (_subStrategies != null)) { // Chargement du fichier model patternFile.Load(patternFileName); // Verification du fichier pattern et création du fichier réel de sortie if (patternFile.Count() > 0) { // On parcourt tout le fichier et on copie toutes les lignes qui n'appartiennent pas à boucle de stratégie for (iLine = 0; iLine < patternFile.Count(); iLine++) { // Lecture de la ligne currentLine = patternFile.GetLine(iLine); // Analyse de la ligne // Est-ce dans une boucle de lecture de pattern if (loopSubStrategyPatternFlag == true) { if (loopSubStrategyPatternFlag == true) { // A-t-on trouver le flag de fin de boucle if (currentLine.ToUpper().Contains(PrivateConst.subStrategyEndTag.ToUpper()) == true) { // La fin de boucle a été trouvée. On abaisse le flag loopSubStrategyPatternFlag = false; // On duplique le modèle en fonction des données en interne // Pour toutes les sub-stratégies for (int iSubStrategy = 0; iSubStrategy < _subStrategies.Count(); iSubStrategy++) { SubStrategy currentSubStrategy = _subStrategies[iSubStrategy]; // Export des données de la sous-stratégie for (int i = 0; i < currentSubStrategy.Count(); i++) { // Ecriture des infos de la stratégie foreach (String patternLineToAdd in loopSubStrategyPattern) outputPatternFile.AddLine(patternLineToAdd); } // Ecriture d'un saut de ligne pour la mise en page outputPatternFile.AddLine(""); } // On ajoute la Tag de fin de boucle outputPatternFile.AddLine(currentLine); } else { // Nous ajoutons la ligne courante au pattern loopSubStrategyPattern.Add(currentLine); } } } else { if (currentLine.ToUpper().Contains(PrivateConst.subStrategyBeginTag.ToUpper()) == true) loopSubStrategyPatternFlag = true; // Nous sommes en lecture normale, cette ligne sera copiée dans le fichier de pattern final outputPatternFile.AddLine(currentLine); } } } // Si le fichier pattern est prêt, nous écrivons les données dans le fichier de sortie if (outputPatternFile.Count() > 0) { StructuredFileGroup groupToAdd = null; // Creation des données génériques groupToAdd = new StructuredFileGroup(0); // Creation du groupe générique groupToAdd.AddKey(new StructuredFileKey(PrivateConst.TAG_StrategyName, _strategyName)); groupToAdd.AddKey(new StructuredFileKey(PrivateConst.TAG_DefaultSpeed, _defaultSpeed)); groupToAdd.AddKey(new StructuredFileKey(PrivateConst.TAG_DefaultPivotSpeed, _defaultPivotSpeed)); groupToAdd.AddKey(new StructuredFileKey(PrivateConst.TAG_InitialPosX, _initialPos.param2)); groupToAdd.AddKey(new StructuredFileKey(PrivateConst.TAG_InitialPosY, _initialPos.param3)); groupToAdd.AddKey(new StructuredFileKey(PrivateConst.TAG_InitialPosA, _initialPos.param4)); // Ajout du groupe outputFile.AddGroup(groupToAdd); // Creation des données spécifiques if (_subStrategies.Count() > 0) { // Pour chaque sous stratégies foreach (SubStrategy currentSubStrategy in _subStrategies) { String currentSubStrategyName = currentSubStrategy.Name; if (currentSubStrategy.Count() > 0) { // Pour chacune des actions de la stratégie foreach (RobotAction currentAction in currentSubStrategy.GetAllActions()) { groupToAdd = currentAction.Export(); groupToAdd.AddKey(new StructuredFileKey(PrivateConst.TAG_SubStrategyName, currentSubStrategyName)); outputFile.AddGroup(groupToAdd); } } } } // Ecriture du fichier final outputFile.SetPatternFile(outputPatternFile); outputFile.Export(outputFileName); // Sauvegarde des données Save(); } } } catch (Exception ex) { _debugTool.WriteLine("Strategy Export() : " + ex.Message); Ret = -1; } return Ret; }
/// <summary> /// Sauvegarde des informations de la substrategy dans le fichier spécifié en paramètre /// </summary> /// <param name="fileName">Nom du fichier pour la sauvegarde</param> /// <returns>Retourne le nombre d'action sauvegardée, -1 en cas d'erreur</returns> public int Save(String fileName) { int Ret = -1; int counter = 0; StructuredFile outputFile = null; StructuredFileGroup groupToAdd = null; if (fileName != null) { // Création du fichier pour la sauvegarde (fichier sans pattern) outputFile = new StructuredFile(); // Création des objets globaux groupToAdd = new StructuredFileGroup(0); groupToAdd.AddKey(new StructuredFileKey("SubStrategyName", _subStrategyName)); groupToAdd.AddKey(new StructuredFileKey("SubStrategyID", _subStrategyID)); // Ajout des objets outputFile.AddGroup(groupToAdd); groupToAdd = null; // Création des objets relatifs aux RobotAction if (_actions != null) { foreach (RobotAction currentRobotAction in _actions) { // Creation du groupe pour stocker les données groupToAdd = currentRobotAction.Export(); // Ajout des données outputFile.AddGroup(groupToAdd); groupToAdd = null; counter = counter + 1; } } try { outputFile.SaveTo(fileName); Ret = counter; } catch (Exception ex) { Ret = -1; } } return Ret; }
static void Main(string[] args) { bool Validated = true; // ############################################################################################################################ // ##### ActiveSensors // ############################################################################################################################ #region ActiveSensors ActiveSensors testActiveSensors = new ActiveSensors(); // Test 0200 : ActiveSensors __________________________________________________________________________________________________ try { DisplaySeparator(); Console.WriteLine("Test 0200 - Verification des objets ActiveSensors : \n"); if (testActiveSensors.Activated == "(APP_PARAM_STRATEGYFLAG_NONE)") { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } testActiveSensors.ActivateSensors("APP_PARAM_STRATEGYFLAG_COLLISION_FRONT"); testActiveSensors.ActivateSensors("APP_PARAM_STRATEGYFLAG_COLLISION_FRONT"); testActiveSensors.ActivateSensors("APP_PARAM_STRATEGYFLAG_COLLISION_REAR"); if (testActiveSensors.Activated == "(APP_PARAM_STRATEGYFLAG_COLLISION_FRONT + APP_PARAM_STRATEGYFLAG_COLLISION_REAR)") { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } testActiveSensors.DesactivateSensors("APP_PARAM_STRATEGYFLAG_COLLISION_FRONT"); if (testActiveSensors.Activated == "(APP_PARAM_STRATEGYFLAG_COLLISION_REAR)") { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } testActiveSensors.DesactivateAllSensors(); if (testActiveSensors.Activated == "(APP_PARAM_STRATEGYFLAG_NONE)") { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } testActiveSensors.ActivateSensors("APP_PARAM_STRATEGYFLAG_COLLISION_FRONT"); testActiveSensors.ForceSensors("APP_PARAM_STRATEGYFLAG_COLLISION_REAR"); if (testActiveSensors.Activated == "(APP_PARAM_STRATEGYFLAG_COLLISION_REAR)") { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0200 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } #endregion // ############################################################################################################################ // ##### RobotAction // ############################################################################################################################ #region RobotAction RobotAction testAction = new RobotAction(); // Test 0201 : RobotAction ____________________________________________________________________________________________________ try { DisplaySeparator(); Console.WriteLine("Test 0201 - Verification des objets Action : \n"); Console.WriteLine(" -> Verification des private"); // ------------------------------------------------------------------------------------------ if (testAction.CheckPrivateFunction()) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.WriteLine(" -> Test de la fonction d'export() : "); testAction.ID = 1; testAction.cmd = EnumCmd.Mvt_UseMixedMode; testAction.cmdType = EnumCmdType.CmdType_Blocking; testAction.param1 = "11"; testAction.param2 = "12"; testAction.param3 = "13"; testAction.param4 = "14"; testAction.nextID = 100; testAction.timeoutID = 200; StructuredFileGroup output = testAction.Export(); if (output != null) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } // ------------------------------------------------------------------------------------------ Console.WriteLine(" -> Test de la fonction d'import() : "); testAction = new RobotAction(); StructuredFileGroup inputData = new StructuredFileGroup(10); inputData.AddKey(new StructuredFileKey("Cmd", "Mvt_UseMixedMode")); inputData.AddKey(new StructuredFileKey("CmdType", "Blocking")); inputData.AddKey(new StructuredFileKey("Param1", 50)); inputData.AddKey(new StructuredFileKey("Param2", 100)); inputData.AddKey(new StructuredFileKey("Param3", 200)); inputData.AddKey(new StructuredFileKey("Param4", 90.0)); inputData.AddKey(new StructuredFileKey("ActiveSensors", "COLLISION_FRONT")); inputData.AddKey(new StructuredFileKey("nextID", 10)); inputData.AddKey(new StructuredFileKey("timeoutID", 30)); if (testAction.Import(inputData) == true) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0201 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } #endregion // ############################################################################################################################ // ##### SubStrategy // ############################################################################################################################ #region SubStrategy // Test 0202 : SubStrategy ____________________________________________________________________________________________________ try { DisplaySeparator(); // ------------------------------------------------------------------------------------------ SubStrategy strategy1 = new SubStrategy("Strategy 1", 1); SubStrategy strategy2 = new SubStrategy("Strategy 2", 1); // Creation de l'action 1 RobotAction Action1 = new RobotAction(1); Action1.cmd = EnumCmd.Mvt_UseMixedMode; Action1.cmdType = EnumCmdType.CmdType_Blocking; Action1.param1 = "1"; Action1.param2 = "2"; Action1.param3 = "3"; Action1.param4 = "4"; Action1.nextID = -1; Action1.timeoutID = -1; RobotAction Action10 = new RobotAction(10); Action1.cmd = EnumCmd.Mvt_UseMixedMode; Action1.cmdType = EnumCmdType.CmdType_Blocking; Action1.param1 = "10"; Action1.param2 = "20"; Action1.param3 = "30"; Action1.param4 = "40"; Action1.nextID = -1; Action1.timeoutID = -1; RobotAction Action2 = new RobotAction(2); Action2.cmd = EnumCmd.App_Wait; Action2.cmdType = EnumCmdType.CmdType_Blocking; Action2.param1 = "4"; Action2.param2 = "3"; Action2.param3 = "2"; Action2.param4 = "1"; Action2.nextID = -1; Action2.timeoutID = -1; strategy1.AddAction(Action1); strategy1.AddAction(Action2); strategy1.AddAction(Action10); strategy2.AddAction(Action1); strategy2.AddAction(Action2); strategy2.AddAction(Action10); Console.WriteLine("Test 0202 - SubStrategy : "); if (strategy1.Count() == 3) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.WriteLine(" -> Suppression d'une action : "); strategy1.RemoveAction(10); strategy2.RemoveAction(20); if ((strategy1.Count() == 2) && (strategy2.Count() == 3)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.WriteLine(" -> Recherche d'une action : "); if ((strategy1.GetAction(1) != null) && (strategy1.GetAction(20) == null)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.WriteLine(" -> Ajout d'une action existante : "); strategy2.AddAction(Action1); if (strategy2.Count() == 3) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.WriteLine(" -> Update d'une action existante : "); if ((strategy1.UpdateAction(1, Action1) == true) && (strategy1.UpdateAction(1, Action2) == false) && (strategy1.UpdateAction(50, new RobotAction(40)) == false)) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0202 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } #endregion // ############################################################################################################################ // ##### Strategy // ############################################################################################################################ #region Strategy // Test 0203 : Strategy _______________________________________________________________________________________________________ try { DisplaySeparator(); // ------------------------------------------------------------------------------------------ SubStrategy subStrategy1 = new SubStrategy("Strategy 1", 1); SubStrategy subStrategy2 = new SubStrategy("Strategy 2", 1); Strategy testStrategy = new Strategy("Strategy"); Strategy testLoadStrategy = new Strategy("LoadStrategy"); // Creation de l'action 1 RobotAction Action1 = new RobotAction(1); Action1.cmd = EnumCmd.Mvt_UseMixedMode; Action1.cmdType = EnumCmdType.CmdType_Blocking; Action1.param1 = "1"; Action1.param2 = "2"; Action1.param3 = "3"; Action1.param4 = "4"; Action1.nextID = -1; Action1.timeoutID = -1; RobotAction Action10 = new RobotAction(10); Action1.cmd = EnumCmd.Mvt_UseMixedMode; Action1.cmdType = EnumCmdType.CmdType_Blocking; Action1.param1 = "10"; Action1.param2 = "20"; Action1.param3 = "30"; Action1.param4 = "40"; Action1.nextID = -1; Action1.timeoutID = -1; RobotAction Action2 = new RobotAction(2); Action2.cmd = EnumCmd.App_Wait; Action2.cmdType = EnumCmdType.CmdType_Blocking; Action2.param1 = "4"; Action2.param2 = "3"; Action2.param3 = "2"; Action2.param4 = "1"; Action2.nextID = -1; Action2.timeoutID = -1; subStrategy1.AddAction(Action1); subStrategy1.AddAction(Action2); subStrategy1.AddAction(Action10); subStrategy2.AddAction(Action1); subStrategy2.AddAction(Action2); subStrategy2.AddAction(Action10); Console.WriteLine("Test 0203 - Strategy : "); Console.WriteLine(" -> Add + Update : "); testStrategy.UpdateMainStrategy(subStrategy1); testStrategy.UpdateSubStrategy(subStrategy1); Action1.cmd = EnumCmd.Mvt_Stop; subStrategy1.UpdateAction(Action1.ID, Action1); testStrategy.UpdateSubStrategy(subStrategy1); testStrategy.AddSubStrategy(subStrategy2); if (testStrategy.GetAllSubStrategy().Count == 2) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.WriteLine(" -> Remove : "); testStrategy.RemoveSubStrategy("Strategy 2"); if (testStrategy.GetAllSubStrategy().Count == 1) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.WriteLine(" -> Remove : "); testStrategy.Clear(); if (testStrategy.GetAllSubStrategy() == null) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.WriteLine(" -> Save : "); testStrategy.UpdateMainStrategy(subStrategy1); testStrategy.AddSubStrategy(subStrategy1); testStrategy.AddSubStrategy(subStrategy2); testStrategy.Save(); if (true) { Console.Write(" Ok (Verification manuelle du dossier de sortie)\n"); } Console.WriteLine(" -> Load : "); testLoadStrategy.Load("Strategy"); if (testLoadStrategy.GetAllSubStrategy().Count == 2) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.WriteLine(" -> Export : "); RobotAction Action100 = new RobotAction(100); Action100.cmd = EnumCmd.App_Wait; Action100.cmdType = EnumCmdType.CmdType_Blocking; Action100.param1 = "40"; Action100.param2 = "30"; Action100.param3 = "20"; Action100.param4 = "10"; Action100.nextID = 101; Action100.timeoutID = 901; RobotAction Action101 = new RobotAction(101); Action101.cmd = EnumCmd.Mvt_UseMixedMode; Action101.cmdType = EnumCmdType.CmdType_NonBlocking; Action101.param1 = "41"; Action101.param2 = "31"; Action101.param3 = "21"; Action101.param4 = "11.5"; Action101.nextID = 102; Action101.timeoutID = 902; RobotAction Action102 = new RobotAction(102); Action102.cmd = EnumCmd.MvtSimple_MoveInMM; Action102.cmdType = EnumCmdType.CmdType_Blocking; Action102.param1 = "42"; Action102.param2 = "32"; Action102.param3 = "22"; Action102.param4 = "12"; Action102.nextID = 103; Action102.timeoutID = 903; RobotAction Action103 = new RobotAction(103); Action103.cmd = EnumCmd.Mvt_UsePivotMode; Action103.cmdType = EnumCmdType.CmdType_NonBlocking; Action103.param1 = "43"; Action103.param2 = "33"; Action103.param3 = "23"; Action103.param4 = "13"; Action103.nextID = 104; Action103.timeoutID = 904; RobotAction Action200 = new RobotAction(200); Action200.cmd = EnumCmd.Mvt_UseSpline; Action200.cmdType = EnumCmdType.CmdType_NonBlocking; Action200.param1 = "44"; Action200.param2 = "34"; Action200.param3 = "24"; Action200.param4 = "14"; Action103.nextID = -1; Action200.timeoutID = 905; SubStrategy subStrategyExport1 = new SubStrategy("Export Strategy 1", 1); SubStrategy subStrategyExport2 = new SubStrategy("Export Strategy 2", 1); subStrategyExport1.AddAction(Action100); subStrategyExport1.AddAction(Action101); subStrategyExport2.AddAction(Action102); subStrategyExport2.AddAction(Action103); subStrategyExport2.AddAction(Action200); Strategy testExportStrategy = new Strategy("EXPORT_STRATEGY"); testExportStrategy.AddSubStrategy(subStrategyExport1); testExportStrategy.AddSubStrategy(subStrategyExport2); testExportStrategy.Export("./Data/TestOutputStrategy.c", "./patternFiles/ImportPatternFile.spattern"); if (true) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } Console.WriteLine(" -> Import : "); Strategy testImportStrategy = new Strategy("ImportStrategy"); testImportStrategy.Import("./Data/TestOutputStrategy.c", "./patternFiles/ImportPatternFile.spattern"); testExportStrategy.Export("./Data/TestOutputStrategy_2.c", "./patternFiles/ImportPatternFile.spattern"); if (true) { Console.Write(" Ok\n"); } else { Console.Write(" Error !\n"); Validated = false; } } catch (Exception ex) { Console.WriteLine("Test 0203 Failed !!"); Console.WriteLine(ex.Message); Validated = false; } #endregion // Fin du programme ----------------------------------------------------------------------------- DisplaySeparator(); Console.Write("\nTest terminé. Etat du module : "); if(Validated == true) { Console.Write("Validé ! \n"); }else { Console.Write("Invalide !\n"); } Console.Read(); }