Пример #1
0
        /// <summary>
        /// Tests the API by loading the input file, saving it to memory and comparing it to the wished result file.
        /// </summary>
        /// <param name="inFile">The file to load and save.</param>
        /// <param name="resultFile">The file to compare to.</param>
        private static void DoLoadSaveTest(string inFile, string resultFile)
        {
            MadCatzProfile profile = ProfileFactory.Load(inFile);

            byte[] data = null;
            using (var stream = new MemoryStream())
            {
                ProfileFactory.Save(stream, profile);
                data = stream.GetBuffer();
            }

            StreamReader writtenReader = null;
            MemoryStream memStream     = null;
            string       written       = null;

            try
            {
                memStream     = new MemoryStream(data);
                writtenReader = new StreamReader(memStream);
                written       = writtenReader.ReadToEnd().Trim().Replace("\0", string.Empty);
                writtenReader.Close();
                writtenReader = null;
                memStream     = null;
            }
            finally
            {
                if (writtenReader != null)
                {
                    writtenReader.Close();
                    writtenReader = null;
                    memStream     = null;
                }
                if (memStream != null)
                {
                    memStream.Close();
                }
            }

            StreamReader originalReader = null;
            string       original       = null;

            try
            {
                originalReader = new StreamReader(resultFile);
                original       = originalReader.ReadToEnd().Trim();
                originalReader.Close();
                originalReader = null;
            }
            finally
            {
                if (originalReader != null)
                {
                    originalReader.Close();
                }
            }

            Assert.AreEqual(original, written);
        }
Пример #2
0
        public void CorruptVersionTest()
        {
            var report = new TestReport();

            ProfileFactory.Load(TestConstants.CORRUPTED_TESTDATA_DIR + "CorruptVersion.pr0", report);
            report.AssertEquals(
                new List <string>(),
                new List <string>(),
                new List <string>(new string[] { "Unsupported version: 6" }));
        }
Пример #3
0
        public bool LoadProfile(FileInfo file, ValidationReport report)
        {
            var errorCatcher = new ErrorCatcherReport();

            MadCatzProfile profile = ProfileFactory.Load(file, new BranchReport(new ValidationReport[] { report, errorCatcher }));

            if (!errorCatcher.ErrorOccured)
            {
                profiles.AddLast(profile);
                profileInfos.Add(profile, new ProfileInfo(file));
            }

            return(!errorCatcher.ErrorOccured);
        }
Пример #4
0
        public void CorruptAttributesAndTags()
        {
            var report = new TestReport();

            ProfileFactory.Load(TestConstants.CORRUPTED_TESTDATA_DIR + "CorruptAttributesAndTags.pr0", report);
            report.AssertEquals(
                new List <string>(),
                new List <string>(),
                new List <string>(new string[] { "Missing required tag in \"controller\" node.",
                                                 "Missing required attribute in \"controller\" node: group",
                                                 "Missing required tag in \"shift\" node.",
                                                 "Missing required tag in \"mousepointer\" node.",
                                                 "Missing required attribute in \"member\" node: name",
                                                 "Missing required tag in \"actioncommand\" node.",
                                                 "Missing required attribute in \"actioncommand\" node: name",
                                                 "Missing required attribute in \"action\" node: device",
                                                 "Missing required attribute in \"action\" node: page",
                                                 "Missing required attribute in \"action\" node: usage", }));
        }