Though most of this code is located in AddCnvtrDlg, because the buttons and listbox are there, we're testing it in here because this Properties Tab is where you're expected to add/configure the Converters
상속: SIL.FieldWorks.FwCoreDlgs.AddCnvtrDlg
예제 #1
0
        public void FixtureSetup()
        {
            var encConverters = new EncConverters();

            // Remove any encoding converters we created that have been left over due to a crash
            // or other mishap.  (That's why we use wierd names starting with ZZZUnitTest, so
            // there won't be any conceivable conflict with user chosen names.  Inconceivable
            // conflicts might still happen, but...)
            RemoveTestConverters(encConverters, "Installed mappings before test setup:");
            string[] ccFileContents = { "'c' > 'C'" };
            m_ccFileName = CreateTempFile(ccFileContents, "cct");
            encConverters.AddConversionMap("ZZZUnitTestCC", m_ccFileName,
                                           ConvType.Legacy_to_Unicode, "SIL.cc", "", "",
                                           ProcessTypeFlags.UnicodeEncodingConversion);

            string[] mapFileContents =
            {
                "EncodingName	'ZZZUnitTestText'",
                "DescriptiveName	'Silly test file'",
                "ByteDefault		'?'",
                "UniDefault		replacement_character",
                "0x80	<>	euro_sign"
            };
            m_mapFileName = CreateTempFile(mapFileContents, "map");
            encConverters.AddConversionMap("ZZZUnitTestMap", m_mapFileName,
                                           ConvType.Legacy_to_from_Unicode, "SIL.map", "", "",
                                           ProcessTypeFlags.UnicodeEncodingConversion);

            // TODO: Should test a legitimate compiled TecKit file by embedding a zipped
            // up one in the resources for testing purposes.

            // This is a randomly chosen ICU converter. The test may break when we reduce the set of
            // ICU converters we ship.
            encConverters.AddConversionMap("ZZZUnitTestICU", "ISO-8859-1",
                                           ConvType.Legacy_to_from_Unicode, "ICU.conv", "", "",
                                           ProcessTypeFlags.ICUConverter);

            // Add a 1-step compound converter, which won't be any of the types our dialog
            // recognizes for now.
            encConverters.AddCompoundConverterStep("ZZZUnitTestCompound", "ZZZUnitTestCC", true,
                                                   NormalizeFlags.None);

            encConverters.Remove("BogusTecKitFile");                    // shouldn't exist, but...

            m_myDlg             = new DummyAddCnvtrDlg();
            m_myCtrl            = new DummyCnvtrPropertiesCtrl();
            m_myCtrl.Converters = encConverters;
            // Load all the mappings after the dummy mappings are added, so the Converter
            // Mapping File combo box won't contain obsolete versions of the mappings referring
            // to old temp files from a previous run of the tests.q
            m_myCtrl.CnvtrPropertiesCtrl_Load(null, null);
#if !QUIET
            Console.WriteLine("Installed mappings after test setup:");
            foreach (var name in encConverters.Mappings)
            {
                var conv = encConverters[name];
                Console.WriteLine("    {0} ({1})", name, conv == null ? "null" : conv.GetType().ToString());
            }
#endif
        }
예제 #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Executes in two distinct scenarios.
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        protected override void Dispose(bool disposing)
        {
            //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
                // Dispose managed resources here.
                if (m_fileMaker != null)
                {
                    m_fileMaker.Dispose();
                }
                if (m_myCtrl != null)
                {
                    m_myCtrl.Dispose();
                }
                if (m_myDlg != null)
                {
                    m_myDlg.Dispose();
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_fileMaker   = null;
            m_myCtrl      = null;
            m_myDlg       = null;
            m_ccFileName  = null;
            m_mapFileName = null;

            base.Dispose(disposing);
        }
        /// <summary>
        /// Clean up after running all the tests.
        /// </summary>
        public override void FixtureTeardown()
        {
            EncConverters encConverters;

            // Dispose managed resources here.
            if (m_myCtrl != null)
            {
                encConverters = m_myCtrl.Converters;
                m_myCtrl.Dispose();
                m_myCtrl = null;
            }
            else
            {
                encConverters = new EncConverters();
            }

            if (m_myDlg != null)
            {
                m_myDlg.Dispose();
                m_myDlg = null;
            }

            try
            {
                // Delete any temp files that have been created.
                if (!String.IsNullOrEmpty(m_ccFileName))
                {
                    File.Delete(m_ccFileName);
                    m_ccFileName = null;
                }
                if (!String.IsNullOrEmpty(m_mapFileName))
                {
                    File.Delete(m_mapFileName);
                    m_mapFileName = null;
                }
                if (!String.IsNullOrEmpty(m_bogusFileName))
                {
                    File.Delete(m_bogusFileName);
                    m_bogusFileName = null;
                }
            }
            catch
            {
                // for some reason deleting the temporary files occasionally fails - not sure
                // why. If this happens we just ignore it and continue.
            }

            // Remove any encoding converters that we may have created during this test run.
            RemoveTestConverters(encConverters, "Installed mappings after test teardown:");

            base.FixtureTeardown();
        }
예제 #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates and loads a set of dummy converters to test the
        /// <see cref="CnvtrPropertiesCtrl"/> class.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public override void FixtureSetup()
        {
            base.FixtureSetup();

            m_fileMaker = new TempSFFileMaker();
            m_myDlg     = new DummyAddCnvtrDlg();
            m_myCtrl    = new DummyCnvtrPropertiesCtrl();

            SilEncConverters31.EncConverters encConverters = new SilEncConverters31.EncConverters();

            string[] ccFileContents = { "'c' > 'C'" };
            m_ccFileName = m_fileMaker.CreateFileNoID(ccFileContents, "cct");
            encConverters.AddConversionMap("ZZZTestCC", m_ccFileName,
                                           ConvType.Legacy_to_Unicode, "SIL.cc", "", "",
                                           ProcessTypeFlags.UnicodeEncodingConversion);

            string[] mapFileContents =
            {
                "EncodingName	'ZZZText'",
                "DescriptiveName	'Silly test file'",
                "ByteDefault		'?'",
                "UniDefault		replacement_character",
                "0x80	<>	euro_sign"
            };
            m_mapFileName = m_fileMaker.CreateFileNoID(mapFileContents, "map");
            encConverters.AddConversionMap("ZZZTestMap", m_mapFileName,
                                           ConvType.Legacy_to_from_Unicode, "SIL.map", "", "",
                                           ProcessTypeFlags.UnicodeEncodingConversion);

            // TODO: Should test a legitimate compiled TecKit file by embedding a zipped
            // up one in the resources for testing purposes.

            // This is a randomly chosen ICU converter. The test may break when we reduce the set of
            // ICU converters we ship.
            encConverters.AddConversionMap("ZZZTestICU", "ISO-8859-1",
                                           ConvType.Legacy_to_from_Unicode, "ICU.conv", "", "",
                                           ProcessTypeFlags.UnicodeEncodingConversion);

            // Add a 1-step compound converter, which won't be any of the types our dialog
            // recognizes for now.
            encConverters.AddCompoundConverterStep("ZZZTestCompound", "ZZZTestCC", true,
                                                   NormalizeFlags.None);

            // Load all the mappings after the dummy mappings are added, so the Converter
            // Mapping File combo box won't contain obsolete versions of the mappings referring
            // to old temp files from a previous run of the tests.
            m_myCtrl.CnvtrPropertiesCtrl_Load(null, null);
            encConverters.Remove("Bogus");
        }
예제 #5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Executes in two distinct scenarios.
		/// 1. If disposing is true, the method has been called directly
		/// or indirectly by a user's code via the Dispose method.
		/// Both managed and unmanaged resources can be disposed.
		/// 2. If disposing is false, the method has been called by the
		/// runtime from inside the finalizer and you should not reference (access)
		/// other managed objects, as they already have been garbage collected.
		/// Only unmanaged resources can be disposed.
		/// </summary>
		/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
		/// <remarks>
		/// If any exceptions are thrown, that is fine.
		/// If the method is being done in a finalizer, it will be ignored.
		/// If it is thrown by client code calling Dispose,
		/// it needs to be handled by fixing the bug.
		/// If subclasses override this method, they should call the base implementation.
		/// </remarks>
		/// ------------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
				if (m_fileMaker != null)
					m_fileMaker.Dispose();
				if (m_myCtrl != null)
					m_myCtrl.Dispose();
				if (m_myDlg != null)
					m_myDlg.Dispose();
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_fileMaker = null;
			m_myCtrl = null;
			m_myDlg = null;
			m_ccFileName = null;
			m_mapFileName = null;

			base.Dispose(disposing);
		}
예제 #6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates and loads a set of dummy converters to test the
		/// <see cref="CnvtrPropertiesCtrl"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public override void FixtureSetup()
		{
			base.FixtureSetup();

			m_fileMaker = new TempSFFileMaker();
			m_myDlg = new DummyAddCnvtrDlg();
			m_myCtrl = new DummyCnvtrPropertiesCtrl();

			SilEncConverters31.EncConverters encConverters = new SilEncConverters31.EncConverters();

			string[] ccFileContents = {"'c' > 'C'"};
			m_ccFileName = m_fileMaker.CreateFileNoID(ccFileContents, "cct");
			encConverters.AddConversionMap("ZZZTestCC", m_ccFileName,
				ConvType.Legacy_to_Unicode, "SIL.cc", "", "",
				ProcessTypeFlags.UnicodeEncodingConversion);

			string[] mapFileContents = {
										   "EncodingName	'ZZZText'",
										   "DescriptiveName	'Silly test file'",
										   "ByteDefault		'?'",
										   "UniDefault		replacement_character",
										   "0x80	<>	euro_sign"
									   };
			m_mapFileName = m_fileMaker.CreateFileNoID(mapFileContents, "map");
			encConverters.AddConversionMap("ZZZTestMap", m_mapFileName,
				ConvType.Legacy_to_from_Unicode, "SIL.map", "", "",
				ProcessTypeFlags.UnicodeEncodingConversion);

			// TODO: Should test a legitimate compiled TecKit file by embedding a zipped
			// up one in the resources for testing purposes.

			// This is a randomly chosen ICU converter. The test may break when we reduce the set of
			// ICU converters we ship.
			encConverters.AddConversionMap("ZZZTestICU", "ISO-8859-1",
				ConvType.Legacy_to_from_Unicode, "ICU.conv", "", "",
				ProcessTypeFlags.UnicodeEncodingConversion);

			// Add a 1-step compound converter, which won't be any of the types our dialog
			// recognizes for now.
			encConverters.AddCompoundConverterStep("ZZZTestCompound", "ZZZTestCC", true,
				NormalizeFlags.None);

			// Load all the mappings after the dummy mappings are added, so the Converter
			// Mapping File combo box won't contain obsolete versions of the mappings referring
			// to old temp files from a previous run of the tests.
			m_myCtrl.CnvtrPropertiesCtrl_Load(null, null);
			encConverters.Remove("Bogus");
		}
		/// <summary>
		/// Clean up after running all the tests.
		/// </summary>
		public override void FixtureTeardown()
		{
			EncConverters encConverters;
			// Dispose managed resources here.
			if (m_myCtrl != null)
			{
				encConverters = m_myCtrl.Converters;
				m_myCtrl.Dispose();
				m_myCtrl = null;
			}
			else
			{
				encConverters = new EncConverters();
			}

			if (m_myDlg != null)
			{
				m_myDlg.Dispose();
				m_myDlg = null;
			}

			try
			{
				// Delete any temp files that have been created.
				if (!String.IsNullOrEmpty(m_ccFileName))
				{
					File.Delete(m_ccFileName);
					m_ccFileName = null;
				}
				if (!String.IsNullOrEmpty(m_mapFileName))
				{
					File.Delete(m_mapFileName);
					m_mapFileName = null;
				}
				if (!String.IsNullOrEmpty(m_bogusFileName))
				{
					File.Delete(m_bogusFileName);
					m_bogusFileName = null;
				}
			}
			catch
			{
				// for some reason deleting the temporary files occasionally fails - not sure
				// why. If this happens we just ignore it and continue.
			}

			// Remove any encoding converters that we may have created during this test run.
			RemoveTestConverters(encConverters, "Installed mappings after test teardown:");

			base.FixtureTeardown();
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates and loads a set of dummy converters to test the
		/// <see cref="CnvtrPropertiesCtrl"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public override void FixtureSetup()
		{
			base.FixtureSetup();

			var encConverters = new EncConverters();
			// Remove any encoding converters we created that have been left over due to a crash
			// or other mishap.  (That's why we use wierd names starting with ZZZUnitTest, so
			// there won't be any conceivable conflict with user chosen names.  Inconceivable
			// conflicts might still happen, but...)
			RemoveTestConverters(encConverters, "Installed mappings before test setup:");
			string[] ccFileContents = {"'c' > 'C'"};
			m_ccFileName = CreateTempFile(ccFileContents, "cct");
			encConverters.AddConversionMap("ZZZUnitTestCC", m_ccFileName,
				ConvType.Legacy_to_Unicode, "SIL.cc", "", "",
				ProcessTypeFlags.UnicodeEncodingConversion);

			string[] mapFileContents = {
										   "EncodingName	'ZZZUnitTestText'",
										   "DescriptiveName	'Silly test file'",
										   "ByteDefault		'?'",
										   "UniDefault		replacement_character",
										   "0x80	<>	euro_sign"
									   };
			m_mapFileName = CreateTempFile(mapFileContents, "map");
			encConverters.AddConversionMap("ZZZUnitTestMap", m_mapFileName,
				ConvType.Legacy_to_from_Unicode, "SIL.map", "", "",
				ProcessTypeFlags.UnicodeEncodingConversion);

			// TODO: Should test a legitimate compiled TecKit file by embedding a zipped
			// up one in the resources for testing purposes.

			// This is a randomly chosen ICU converter. The test may break when we reduce the set of
			// ICU converters we ship.
			encConverters.AddConversionMap("ZZZUnitTestICU", "ISO-8859-1",
				ConvType.Legacy_to_from_Unicode, "ICU.conv", "", "",
				ProcessTypeFlags.ICUConverter);

			// Add a 1-step compound converter, which won't be any of the types our dialog
			// recognizes for now.
			encConverters.AddCompoundConverterStep("ZZZUnitTestCompound", "ZZZUnitTestCC", true,
				NormalizeFlags.None);

			encConverters.Remove("BogusTecKitFile");	// shouldn't exist, but...

			m_myDlg = new DummyAddCnvtrDlg();
			m_myCtrl = new DummyCnvtrPropertiesCtrl();
			m_myCtrl.Converters = encConverters;
			// Load all the mappings after the dummy mappings are added, so the Converter
			// Mapping File combo box won't contain obsolete versions of the mappings referring
			// to old temp files from a previous run of the tests.q
			m_myCtrl.CnvtrPropertiesCtrl_Load(null, null);
#if !QUIET
			Console.WriteLine("Installed mappings after test setup:");
			foreach (var name in encConverters.Mappings)
			{
				var conv = encConverters[name];
				Console.WriteLine("    {0} ({1})", name, conv == null ? "null" : conv.GetType().ToString());
			}
#endif
		}