Ejemplo n.º 1
0
        public void CCFE_ConfigurationTest()
        {
            //ARRANGE

            //ACT
            CCFE_Configuration config = new CCFE_Configuration();

            //ASSERT
            Assert.IsNotNull(config);
            Assert.IsNotNull(config.PropertyList);
        }
Ejemplo n.º 2
0
        public void addPropertyTest()
        {
            //ARRANGE
            CCFE_Configuration config = new CCFE_Configuration();

            //ACT
            config.addProperty(new CCFE_ConfigurationProperty("TestProperty", "TestValue"));
            //try to add duplicate
            config.addProperty(new CCFE_ConfigurationProperty("TestProperty", "TestValue"));
            config.addProperty(new CCFE_ConfigurationProperty("TestProperty", "AnotherTestValue"));

            //ASSERT
            Assert.IsTrue(config.PropertyList.Count == 1);
            Assert.IsTrue(config.PropertyList.Exists(x => (x.Name.Equals("TestProperty") && x.Value.Equals("TestValue"))));
        }
Ejemplo n.º 3
0
        public void CCFE_ConfigurationTest_PropertyList()
        {
            //ARRANGE
            List<CCFE_ConfigurationProperty> propertyList = new List<CCFE_ConfigurationProperty>();
            propertyList.Add(new CCFE_ConfigurationProperty("TriggerMode", "5"));
            propertyList.Add(new CCFE_ConfigurationProperty("OverlapPercent", "75"));
            propertyList.Add(new CCFE_ConfigurationProperty("KnownHalAltitudeUnits", "feet"));
            propertyList.Add(new CCFE_ConfigurationProperty("KnownHalAltitude", "400"));
            propertyList.Add(new CCFE_ConfigurationProperty("Time", "3.8"));
            propertyList.Add(new CCFE_ConfigurationProperty("Distance", "10"));
            propertyList.Add(new CCFE_ConfigurationProperty("WaitForGpsFix", "yes"));
            propertyList.Add(new CCFE_ConfigurationProperty("Version", "1.0"));

            //ACT
            CCFE_Configuration config = new CCFE_Configuration(propertyList);

            //will cause assert to fail if shallow copy
            foreach (CCFE_ConfigurationProperty property in propertyList)
            {
                if (property.Name.Equals("TriggerMode"))
                {
                    property.Value = "0";
                    break;
                }
            }

            //ASSERT
            Assert.IsNotNull(config);
            Assert.IsNotNull(config.PropertyList);
            Assert.IsTrue(config.getValue("TriggerMode").Equals("5"));
            Assert.IsTrue(config.getValue("OverlapPercent").Equals("75"));
            Assert.IsTrue(config.getValue("KnownHalAltitudeUnits").Equals("feet"));
            Assert.IsTrue(config.getValue("KnownHalAltitude").Equals("400"));
            Assert.IsTrue(config.getValue("Time").Equals("3.8"));
            Assert.IsTrue(config.getValue("Distance").Equals("10"));
            Assert.IsTrue(config.getValue("WaitForGpsFix").Equals("yes"));
            Assert.IsTrue(config.getValue("Version").Equals("1.0"));
        }
Ejemplo n.º 4
0
        private void versionToolStripMenuItem_SelectedIndexChanged(object sender, EventArgs e)
        {
            verToolStripMenuItem.Text = "v" + versionToolStripMenuItem.Text;

            List<CCFE_ConfigurationProperty> defaultProperties = CCFE_Default.getDefaultProperties(versionToolStripMenuItem.Text);
            List<CCFE_ConfigurationProperty> extraProperties = new List<CCFE_ConfigurationProperty>();

            //if extra property still exists in this version, keep the value
            foreach (CCFE_GenericPropertyPanel genericPanel in genericPropertyPanels)
            {
                if (defaultProperties.Exists(x => x.Name.Equals(genericPanel.getPropertyName())))
                {
                    extraProperties.Add(new CCFE_ConfigurationProperty(genericPanel.getPropertyName(), genericPanel.getPropertyValue()));
                }
            }

            //remove old extra properties
            foreach (CCFE_GenericPropertyPanel genericPanel in genericPropertyPanels)
            {
                triggerOptionsPanel.Controls.Remove(genericPanel);
                genericPanel.Dispose();
            }
            genericPropertyPanels.Clear();

            //find and create extra properties needed
            foreach(CCFE_ConfigurationProperty property in defaultProperties)
            {
                if (!property.Name.Equals("TriggerMode") &&
                    !property.Name.Equals("OverlapPercent") &&
                    !property.Name.Equals("KnownHalAltitudeUnits") &&
                    !property.Name.Equals("KnownHalAltitude") &&
                    !property.Name.Equals("Time") &&
                    !property.Name.Equals("Distance") &&
                    !property.Name.Equals("WaitForGpsFix") &&
                    !property.Name.Equals("Version") &&
                    !genericPropertyPanels.Exists(x => x.getPropertyName().Equals(property.Name)))
                {
                    string propertyValue;
                    Point newPanelLocation = new Point(triggerDistancePanel.Location.X, (triggerDistancePanel.Location.Y + triggerDistancePanel.Size.Height + 6) + genericPropertyPanels.Count * (triggerDistancePanel.Size.Height + 6));
                    if (extraProperties.Exists(x => x.Name.Equals(property.Name)))
                    {
                        propertyValue = extraProperties.Find(x => x.Name.Equals(property.Name)).Value;
                    }
                    else
                    {
                        propertyValue = property.Value;
                    }
                    CCFE_GenericPropertyPanel newPanel = new CCFE_GenericPropertyPanel(newPanelLocation, property.Name, propertyValue);
                    newPanel.Name = "GenericPropertyPanel" + genericPropertyPanels.Count;
                    genericPropertyPanels.Add(newPanel);
                }
            }

            //add extra panels to the group box
            triggerOptionsPanel.Controls.AddRange(genericPropertyPanels.ToArray());

            //update configuration with new properties
            configuration = CCFE_Default.getDefaultConfiguration(versionToolStripMenuItem.Text);
        }
Ejemplo n.º 5
0
        //checks to see if either of the filehandler or configuration objects have been created
        //meaning a new file has been made or a file location was set
        public bool checkSave()
        {
            //sanitize inputs to eliminate possible blanks
            double knownHalAltitude;
            double triggerPeriod;
            double triggerDistance;
            bool kHA;
            bool tP;
            bool tD;

            kHA = Double.TryParse(knownHalAltitudeValue.Text, out knownHalAltitude);
            tP = Double.TryParse(triggerPeriodValue.Text, out triggerPeriod);
            tD = Double.TryParse(triggerDistanceValue.Text, out triggerDistance);

            if (!kHA || !tP || !tD)
            {
                String message = "The following settings were left blank:\n\n";
                if (!kHA)
                {
                    message += "Known Hal Altitude\n";
                }
                if (!tP)
                {
                    message += "Trigger Period\n";
                }
                if (!tD)
                {
                    message += "Trigger Distance\n";
                }
                message += "\nProceed with these values set to 0?";
                if (MessageBox.Show(message, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK)
                {
                    return false;
                }
                else
                {
                    if (!kHA)
                    {
                        knownHalAltitudeValue.Text = "0";
                    }
                    if (!tP)
                    {
                        triggerPeriodValue.Text = "0";
                    }
                    if (!tD)
                    {
                        triggerDistanceValue.Text = "0";
                    }
                }
            }

            if (configuration == null || fileHandler == null)
            {
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    fileHandler = new CCFE_FileHandler(saveFileDialog.FileName);
                    configuration = new CCFE_Configuration(versionToolStripMenuItem.Text);
                }
                //they canceled or input something wrong
                else
                {
                    return false;
                }
            }
            return true;
        }
Ejemplo n.º 6
0
 public void newConfiguration(string version)
 {
     configuration = new CCFE_Configuration(version);
     loadConfiguration(configuration);
 }
Ejemplo n.º 7
0
        public void loadConfiguration(CCFE_Configuration config)
        {
            triggerModeComboBox.SelectedIndex = Convert.ToInt32(config.getValue(CCFE_Configuration.PROPERTY_TRIGGERMODE));
            overlapTrackBar.Value = Convert.ToInt32(config.getValue(CCFE_Configuration.PROPERTY_OVERLAPPERCENT));
            waitForGpsFixValue.Checked = (bool)config.getValue(CCFE_Configuration.PROPERTY_WAITFORGPSFIX).Equals("yes");
            knownHalAltitudeValue.Text = config.getValue(CCFE_Configuration.PROPERTY_KNOWNHALALTITUDE);

            //sets the known hal altitude unit
            if (config.getValue(CCFE_Configuration.PROPERTY_KNOWNHALALTITUDEUNITS).Equals("feet"))
            {
                //feet
                knownHalAltitudeUnit.SelectedIndex = 0;
            }
            else
            {
                //meters
                knownHalAltitudeUnit.SelectedIndex = 1;
            }
            triggerPeriodValue.Text = config.getValue(CCFE_Configuration.PROPERTY_TIME);
            triggerDistanceValue.Text = config.getValue(CCFE_Configuration.PROPERTY_DISTANCE);

            //needed to move the trackbar label to its spot under the trackbar
            setTrackBarLabelLocationAndText();
        }
Ejemplo n.º 8
0
        //allows the user to select the settings and begins the parsing
        public void fileSearch()
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                fileHandler = new CCFE_FileHandler(openFileDialog.FileName);
                configuration = new CCFE_Configuration(fileHandler.parse());

                loadConfiguration(configuration);
            }
        }
Ejemplo n.º 9
0
        public void CCFE_ConfigurationTest_SpecificVersion()
        {
            //ARRANGE

            //ACT
            CCFE_Configuration config = new CCFE_Configuration("1.0");

            //ASSERT
            Assert.IsNotNull(config);
            Assert.IsNotNull(config.PropertyList);
            Assert.IsTrue(config.getValue("TriggerMode").Equals("5"));
            Assert.IsTrue(config.getValue("OverlapPercent").Equals("75"));
            Assert.IsTrue(config.getValue("KnownHalAltitudeUnits").Equals("feet"));
            Assert.IsTrue(config.getValue("KnownHalAltitude").Equals("400"));
            Assert.IsTrue(config.getValue("Time").Equals("3.8"));
            Assert.IsTrue(config.getValue("Distance").Equals("10"));
            Assert.IsTrue(config.getValue("WaitForGpsFix").Equals("yes"));
            Assert.IsTrue(config.getValue("Version").Equals("1.0"));
        }
Ejemplo n.º 10
0
        public void setValueTest()
        {
            //ARRANGE
            CCFE_Configuration config = new CCFE_Configuration();
            config.PropertyList.Add(new CCFE_ConfigurationProperty("TestProperty1", "TestValue1"));
            config.PropertyList.Add(new CCFE_ConfigurationProperty("TestProperty2", "TestValue2"));

            //ACT
            config.setValue("TestProperty1", "NewValue");

            //ASSERT
            Assert.IsTrue(config.PropertyList.Exists(x => (x.Name.Equals("TestProperty1") && x.Value.Equals("NewValue"))));
            Assert.IsTrue(config.PropertyList.Exists(x => (x.Name.Equals("TestProperty2") && x.Value.Equals("TestValue2"))));
        }
Ejemplo n.º 11
0
        public void getValueTest()
        {
            //ARRANGE
            CCFE_Configuration config = new CCFE_Configuration();
            config.PropertyList.Add(new CCFE_ConfigurationProperty("TestProperty1", "TestValue1"));
            config.PropertyList.Add(new CCFE_ConfigurationProperty("TestProperty2", "TestValue2"));

            //ACT
            string result = config.getValue("TestProperty1");

            //ASSERT
            Assert.IsTrue(result.Equals("TestValue1"));
            Assert.IsFalse(result.Equals("TestValue2"));
        }
Ejemplo n.º 12
0
        public void save(CCFE_Configuration configuration)
        {
            string configurationFileText;

            configurationFileText = "[UserSettings]\n";
            configurationFileText += "# CCFE v" + CCFE_Default.programVersion + " - " + DateTime.Now.ToString(CultureInfo.CurrentCulture) + "\n";

            List<CCFE_ConfigurationProperty> configurationComments = CCFE_Default.getCommentPropertyPairs(configuration.getValue("Version"));

            foreach (CCFE_ConfigurationProperty property in configuration.PropertyList)
            {
                configurationFileText = configurationFileText + appendProperty(property, configurationComments);
            }

            System.IO.File.WriteAllText(FileLocation, configurationFileText);
        }
Ejemplo n.º 13
0
        public void parseTest()
        {
            //ARRANGE
            CCFE_Configuration configuration = new CCFE_Configuration();

            string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "/" + "UserSettings.txt";
            //delete test file if one exists
            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.Delete(filePath);
            }
            CCFE_FileHandler fileHandler = new CCFE_FileHandler(filePath);

            //make test file
            System.IO.File.WriteAllText(filePath, UserSettingsTestData);

            //ACT
            configuration.PropertyList = fileHandler.parse();

            //ASSERT
            //check if all properties are there
            Assert.IsTrue(configuration.PropertyList.Count == UserSettingsPropertyCount);
            //check if all properties have correct values
            foreach (CCFE_ConfigurationProperty property in configuration.PropertyList)
            {
                switch (property.Name)
                {
                    case "TriggerMode":
                        Assert.IsTrue(property.Value.Equals("5"));
                        break;
                    case "OverlapPercent":
                        Assert.IsTrue(property.Value.Equals("75"));
                        break;
                    case "KnownHalAltitudeUnits":
                        Assert.IsTrue(property.Value.Equals("feet"));
                        break;
                    case "KnownHalAltitude":
                        Assert.IsTrue(property.Value.Equals("400"));
                        break;
                    case "Time":
                        Assert.IsTrue(property.Value.Equals("3.8"));
                        break;
                    case "Distance":
                        Assert.IsTrue(property.Value.Equals("10"));
                        break;
                    case "WaitForGpsFix":
                        Assert.IsTrue(property.Value.Equals("yes"));
                        break;
                    case "Version":
                        Assert.IsTrue(property.Value.Equals("1.0"));
                        break;
                    default:
                        //unknown property, can't check, something parsed wrong
                        Assert.Fail();
                        break;
                }
            }

            //CLEANUP
            System.IO.File.Delete(filePath);
        }
Ejemplo n.º 14
0
        public void saveTest()
        {
            //ARRANGE
            string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "/" + "UserSettings.txt";
            //delete test file if one exists
            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.Delete(filePath);
            }
            CCFE_FileHandler fileHandler = new CCFE_FileHandler(filePath);

            CCFE_Configuration configuration = new CCFE_Configuration();
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("TriggerMode", "5"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("OverlapPercent", "75"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("KnownHalAltitudeUnits", "feet"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("KnownHalAltitude", "400"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("Time", "3.8"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("Distance", "10"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("WaitForGpsFix", "yes"));
            configuration.PropertyList.Add(new CCFE_ConfigurationProperty("Version", "1.0"));

            //ACT
            fileHandler.save(configuration);

            //ASSERT
            //check if file was created
            Assert.IsTrue(System.IO.File.Exists(filePath));
            //check if file was saved with correct data
            Assert.IsTrue(System.IO.File.ReadAllText(filePath).Equals(UserSettingsTestData));

            //CLEANUP
            System.IO.File.Delete(filePath);
        }