public static void TestPartialJsonReaderMultiSegment(bool compactData, TestCaseType type, string jsonString)
        {
            // Remove all formatting/indendation
            if (compactData)
            {
                jsonString = JsonTestHelper.GetCompactString(jsonString);
            }

            byte[] dataUtf8 = Encoding.UTF8.GetBytes(jsonString);
            ReadOnlyMemory <byte> dataMemory = dataUtf8;

            List <ReadOnlySequence <byte> > sequences = JsonTestHelper.GetSequences(dataMemory);

            for (int i = 0; i < sequences.Count; i++)
            {
                ReadOnlySequence <byte> sequence = sequences[i];
                var json = new Utf8JsonReader(sequence, isFinalBlock: true, default);
                while (json.Read())
                {
                    ;
                }
                Assert.Equal(sequence.Length, json.BytesConsumed);
                Assert.Equal(sequence.Length, json.CurrentState.BytesConsumed);

                Assert.True(sequence.Slice(json.Position).IsEmpty);
                Assert.True(sequence.Slice(json.CurrentState.Position).IsEmpty);
            }
        }
 public DecompilationTestCase(SR.MethodInfo method, TestCaseType type, string filename, string resultFilename) : base(method)
 {
     this.TestName.Name = method.DeclaringType.FullName + "." + method.Name + "." + type.ToString();
     this.TestName.FullName = this.TestName.Name;
     this.resultFilename=resultFilename;
     this.type = type;
 }
        public static void TestJsonReaderUtf8SpecialNumbers(TestCaseType type, string jsonString)
        {
            byte[] dataUtf8  = Encoding.UTF8.GetBytes(jsonString);
            byte[] result    = JsonLabReturnBytesHelper(dataUtf8, out int length);
            string actualStr = Encoding.UTF8.GetString(result.AsSpan(0, length));

            byte[] resultSequence    = JsonLabSequenceReturnBytesHelper(dataUtf8, out length);
            string actualStrSequence = Encoding.UTF8.GetString(resultSequence.AsSpan(0, length));

            Stream     stream      = new MemoryStream(dataUtf8);
            TextReader reader      = new StreamReader(stream, Encoding.UTF8, false, 1024, true);
            string     expectedStr = JsonTestHelper.NewtonsoftReturnStringHelper(reader);

            // Behavior of E-notation is different between Json.NET and JsonLab
            // Behavior of reading/writing really large number is different as well.
            // TODO: Adjust test accordingly
            //Assert.Equal(expectedStr, actualStr);
            Assert.Equal(actualStr, actualStrSequence);

            long memoryBefore = GC.GetAllocatedBytesForCurrentThread();

            JsonLabEmptyLoopHelper(dataUtf8);
            long memoryAfter = GC.GetAllocatedBytesForCurrentThread();

            Assert.Equal(0, memoryAfter - memoryBefore);
        }
        private static void ReadPartialSegmentSizeOne(bool compactData, TestCaseType type, string jsonString)
        {
            // Remove all formatting/indendation
            if (compactData)
            {
                jsonString = JsonTestHelper.GetCompactString(jsonString);
            }

            byte[] dataUtf8 = Encoding.UTF8.GetBytes(jsonString);

            Stream     stream      = new MemoryStream(dataUtf8);
            TextReader reader      = new StreamReader(stream, Encoding.UTF8, false, 1024, true);
            string     expectedStr = JsonTestHelper.NewtonsoftReturnStringHelper(reader);

            ReadOnlySequence <byte> sequence = JsonTestHelper.GetSequence(dataUtf8, 1);

            for (int j = 0; j < dataUtf8.Length; j++)
            {
                var    utf8JsonReader    = new Utf8JsonReader(sequence.Slice(0, j), isFinalBlock: false, default);
                byte[] resultSequence    = JsonTestHelper.ReaderLoop(dataUtf8.Length, out int length, ref utf8JsonReader);
                string actualStrSequence = Encoding.UTF8.GetString(resultSequence, 0, length);

                long consumed = utf8JsonReader.BytesConsumed;
                Assert.Equal(consumed, utf8JsonReader.CurrentState.BytesConsumed);
                utf8JsonReader     = new Utf8JsonReader(sequence.Slice(consumed), isFinalBlock: true, utf8JsonReader.CurrentState);
                resultSequence     = JsonTestHelper.ReaderLoop(dataUtf8.Length, out length, ref utf8JsonReader);
                actualStrSequence += Encoding.UTF8.GetString(resultSequence, 0, length);
                string message = $"Expected consumed: {dataUtf8.Length - consumed}, Actual consumed: {utf8JsonReader.BytesConsumed}, Index: {j}";
                Assert.Equal(utf8JsonReader.BytesConsumed, utf8JsonReader.CurrentState.BytesConsumed);
                Assert.True(dataUtf8.Length - consumed == utf8JsonReader.BytesConsumed, message);
                Assert.Equal(expectedStr, actualStrSequence);
            }
        }
        public static string CompileResource(string name, TestCaseType type)
        {
            string file = string.Concat(Path.GetTempFileName(), ".dll");


            string path = string.Concat(TestCasesDirectory, Path.DirectorySeparatorChar + name);

            using (var provider = GetProvider(name))
            {
                var parameters = GetDefaultParameters(name);
                parameters.IncludeDebugInformation = false;
                parameters.GenerateExecutable      = false;
                parameters.OutputAssembly          = file;
                parameters.GenerateInMemory        = false;
                if (type == TestCaseType.Release)
                {
                    parameters.CompilerOptions = "/optimize";
                }

                var results = provider.CompileAssemblyFromFile(parameters, path);
                AssertCompilerResults(results);
            }

            return(file);
        }
Exemple #6
0
 public DecompilationTestCase(SR.MethodInfo method, TestCaseType type, string filename, string resultFilename) : base(method)
 {
     this.TestName.Name     = method.DeclaringType.FullName + "." + method.Name + "." + type.ToString();
     this.TestName.FullName = this.TestName.Name;
     this.resultFilename    = resultFilename;
     this.type = type;
 }
Exemple #7
0
 /// <param name="testCaseType"></param>
 /// <param name="priority"></param>
 /// <param name="version"></param>
 /// <param name="testCategory"></param>
 public TestInfoAttribute
     (TestCaseType testCaseType, TestPriority priority, string version, string testCategory)
 {
     TestCaseType = testCaseType;
     Priority     = priority;
     Version      = version;
     TestCategory = testCategory;
 }
Exemple #8
0
 public CecilTestCase(MethodInfo method, TestCecilAttribute attribute, TestCaseType type)
     : base(method)
 {
     this.TestName.Name     = type.ToString();
     this.TestName.FullName = method.DeclaringType.FullName + "." + method.Name + "." + type;
     this.attribute         = attribute;
     this.type = type;
 }
        public static void TestJsonReaderLargestUtf8SegmentSizeOne(bool compactData, TestCaseType type, string jsonString)
        {
            // Skipping really large JSON since slicing them (O(n^2)) is too slow.
            if (type == TestCaseType.Json40KB || type == TestCaseType.Json400KB || type == TestCaseType.ProjectLockJson)
            {
                return;
            }

            ReadPartialSegmentSizeOne(compactData, type, jsonString);
        }
        public MethodBody GetMethodBody(TestCaseType type)
        {
            string assemblyLocation = DecompilationTestFixture.CompileResource(fileName,type);
            var asmDefinition = AssemblyFactory.GetAssembly(assemblyLocation);
            MethodDefinition methodInfo = GetMethodDefinition(asmDefinition);
            if (methodInfo == null)
                return null;

            return methodInfo.Body;
        }
Exemple #11
0
        public static void TestJsonReaderUtf16(TestCaseType type, string jsonString)
        {
            byte[] dataUtf16 = Encoding.Unicode.GetBytes(jsonString);
            byte[] result    = JsonLabReturnBytesHelper(dataUtf16, SymbolTable.InvariantUtf16, out int length, 2);
            string actualStr = Encoding.Unicode.GetString(result.AsSpan(0, length));

            TextReader reader      = new StringReader(jsonString);
            string     expectedStr = NewtonsoftReturnStringHelper(reader);

            Assert.Equal(actualStr, expectedStr);
        }
Exemple #12
0
        public static void TestJsonReaderUtf8(TestCaseType type, string jsonString)
        {
            byte[] dataUtf8  = Encoding.UTF8.GetBytes(jsonString);
            byte[] result    = JsonLabReturnBytesHelper(dataUtf8, SymbolTable.InvariantUtf8, out int length);
            string actualStr = Encoding.UTF8.GetString(result.AsSpan(0, length));

            Stream     stream      = new MemoryStream(dataUtf8);
            TextReader reader      = new StreamReader(stream, Encoding.UTF8, false, 1024, true);
            string     expectedStr = NewtonsoftReturnStringHelper(reader);

            Assert.Equal(actualStr, expectedStr);
        }
Exemple #13
0
        public static void TestJsonReaderUtf8SegmentSizeOne(bool compactData, TestCaseType type, string jsonString)
        {
            // Remove all formatting/indendation
            if (compactData)
            {
                using (JsonTextReader jsonReader = new JsonTextReader(new StringReader(jsonString)))
                {
                    jsonReader.FloatParseHandling = FloatParseHandling.Decimal;
                    JToken jtoken       = JToken.ReadFrom(jsonReader);
                    var    stringWriter = new StringWriter();
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(stringWriter))
                    {
                        jtoken.WriteTo(jsonWriter);
                        jsonString = stringWriter.ToString();
                    }
                }
            }

            byte[] dataUtf8 = Encoding.UTF8.GetBytes(jsonString);

            Stream     stream      = new MemoryStream(dataUtf8);
            TextReader reader      = new StreamReader(stream, Encoding.UTF8, false, 1024, true);
            string     expectedStr = JsonTestHelper.NewtonsoftReturnStringHelper(reader);

            ReadOnlySequence <byte> sequence = JsonTestHelper.GetSequence(dataUtf8, 1);

            // Skipping really large JSON since slicing them (O(n^2)) is too slow.
            if (type == TestCaseType.Json40KB || type == TestCaseType.Json400KB || type == TestCaseType.ProjectLockJson)
            {
                var    utf8JsonReader    = new Utf8JsonReader(sequence, isFinalBlock: true, default);
                byte[] resultSequence    = JsonTestHelper.ReaderLoop(dataUtf8.Length, out int length, ref utf8JsonReader);
                string actualStrSequence = Encoding.UTF8.GetString(resultSequence, 0, length);
                Assert.Equal(expectedStr, actualStrSequence);
                return;
            }

            for (int j = 0; j < dataUtf8.Length; j++)
            {
                var    utf8JsonReader    = new Utf8JsonReader(sequence.Slice(0, j), isFinalBlock: false, default);
                byte[] resultSequence    = JsonTestHelper.ReaderLoop(dataUtf8.Length, out int length, ref utf8JsonReader);
                string actualStrSequence = Encoding.UTF8.GetString(resultSequence, 0, length);

                long consumed = utf8JsonReader.BytesConsumed;
                Assert.Equal(consumed, utf8JsonReader.CurrentState.BytesConsumed);
                utf8JsonReader     = new Utf8JsonReader(sequence.Slice(consumed), isFinalBlock: true, utf8JsonReader.CurrentState);
                resultSequence     = JsonTestHelper.ReaderLoop(dataUtf8.Length, out length, ref utf8JsonReader);
                actualStrSequence += Encoding.UTF8.GetString(resultSequence, 0, length);
                string message = $"Expected consumed: {dataUtf8.Length - consumed}, Actual consumed: {utf8JsonReader.BytesConsumed}, Index: {j}";
                Assert.Equal(utf8JsonReader.BytesConsumed, utf8JsonReader.CurrentState.BytesConsumed);
                Assert.True(dataUtf8.Length - consumed == utf8JsonReader.BytesConsumed, message);
                Assert.Equal(expectedStr, actualStrSequence);
            }
        }
Exemple #14
0
        public MethodBody GetMethodBody(TestCaseType type)
        {
            string           assemblyLocation = DecompilationTestFixture.CompileResource(fileName, type);
            var              asmDefinition    = AssemblyFactory.GetAssembly(assemblyLocation);
            MethodDefinition methodInfo       = GetMethodDefinition(asmDefinition);

            if (methodInfo == null)
            {
                return(null);
            }

            return(methodInfo.Body);
        }
Exemple #15
0
        private void OrderTestCases(TestCaseComponentGroup groupInFocus, TestCaseType typeOfTestCase)
        {
            var filteredTestCases = FilterTestCases(groupInFocus.TestCaseComponents, typeOfTestCase);

            if (filteredTestCases != null)
            {
                int index = maxControlOrder[groupInFocus.ControlName];
                filteredTestCases.OrderBy((tc) => tc.Name).ToList().ForEach((tc) =>
                {
                    tc.Order = index;
                    index++;
                });
                maxControlOrder[groupInFocus.ControlName] = index;
            }
        }
        public void ParseJson(TestCaseType type, string jsonString)
        {
            byte[]     dataUtf8 = Encoding.UTF8.GetBytes(jsonString);
            var        parser   = new JsonParser(dataUtf8);
            JsonObject obj      = parser.Parse();

            string actual = obj.PrintJson();

            // Change casing to match what JSON.NET does.
            actual = actual.Replace("true", "True").Replace("false", "False");

            TextReader reader   = new StringReader(jsonString);
            string     expected = JsonTestHelper.NewtonsoftReturnStringHelper(reader);

            Assert.Equal(expected, actual);
        }
        /// <summary>
        /// Create TestCase of given test case type
        /// </summary>
        /// <param name="testCaseType">
        /// </param>
        /// <param name="messageCaptureContext">
        /// </param>
        /// <returns>
        /// </returns>
        public static TestCase Create(TestCaseType testCaseType, MessageCaptureContext messageCaptureContext)
        {
            switch (testCaseType)
            {
            case TestCaseType.RequestResponse:
                return(new RequestResponseTestCase(messageCaptureContext));

            case TestCaseType.ConsumeConsumer:
                return(new ConsumeConsumerTestCase(messageCaptureContext));

            case TestCaseType.WebShop:
                return(new WebshopTestCase(messageCaptureContext));

            default:
                throw new ArgumentOutOfRangeException(nameof(testCaseType), testCaseType, null);
            }
        }
Exemple #18
0
        public static void TestJsonReaderUtf16(TestCaseType type, string jsonString)
        {
            byte[] dataUtf16 = Encoding.Unicode.GetBytes(jsonString);
            byte[] result    = JsonLabReturnBytesHelper(dataUtf16, SymbolTable.InvariantUtf16, out int length, 2);
            string actualStr = Encoding.Unicode.GetString(result.AsSpan(0, length));

            TextReader reader      = new StringReader(jsonString);
            string     expectedStr = NewtonsoftReturnStringHelper(reader);

            Assert.Equal(actualStr, expectedStr);

            long memoryBefore = GC.GetAllocatedBytesForCurrentThread();

            JsonLabEmptyLoopHelper(dataUtf16, SymbolTable.InvariantUtf16);
            long memoryAfter = GC.GetAllocatedBytesForCurrentThread();

            Assert.Equal(0, memoryAfter - memoryBefore);
        }
        public static void TestPartialJsonReaderSlicesMultiSegment(bool compactData, TestCaseType type, string jsonString)
        {
            // Remove all formatting/indendation
            if (compactData)
            {
                jsonString = JsonTestHelper.GetCompactString(jsonString);
            }

            byte[] dataUtf8 = Encoding.UTF8.GetBytes(jsonString);
            ReadOnlyMemory <byte> dataMemory = dataUtf8;

            List <ReadOnlySequence <byte> > sequences = JsonTestHelper.GetSequences(dataMemory);

            for (int i = 0; i < sequences.Count; i++)
            {
                ReadOnlySequence <byte> sequence = sequences[i];
                for (int j = 0; j < dataUtf8.Length; j++)
                {
                    var json = new Utf8JsonReader(sequence.Slice(0, j), isFinalBlock: false, default);
                    while (json.Read())
                    {
                        ;
                    }

                    long            consumed      = json.BytesConsumed;
                    JsonReaderState jsonState     = json.CurrentState;
                    byte[]          consumedArray = sequence.Slice(0, consumed).ToArray();
                    Assert.Equal(consumedArray, sequence.Slice(0, json.Position).ToArray());
                    Assert.True(json.Position.Equals(jsonState.Position));
                    json = new Utf8JsonReader(sequence.Slice(consumed), isFinalBlock: true, jsonState);
                    while (json.Read())
                    {
                        ;
                    }
                    Assert.Equal(dataUtf8.Length - consumed, json.BytesConsumed);
                    Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
                }
            }
        }
Exemple #20
0
        public static void TestJsonReaderUtf8(bool compactData, TestCaseType type, string jsonString)
        {
            // Remove all formatting/indendation
            if (compactData)
            {
                using (JsonTextReader jsonReader = new JsonTextReader(new StringReader(jsonString)))
                {
                    jsonReader.FloatParseHandling = FloatParseHandling.Decimal;
                    JToken jtoken       = JToken.ReadFrom(jsonReader);
                    var    stringWriter = new StringWriter();
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(stringWriter))
                    {
                        jtoken.WriteTo(jsonWriter);
                        jsonString = stringWriter.ToString();
                    }
                }
            }

            byte[] dataUtf8  = Encoding.UTF8.GetBytes(jsonString);
            byte[] result    = JsonLabReturnBytesHelper(dataUtf8, out int length);
            string actualStr = Encoding.UTF8.GetString(result.AsSpan(0, length));

            byte[] resultSequence    = JsonLabSequenceReturnBytesHelper(dataUtf8, out length);
            string actualStrSequence = Encoding.UTF8.GetString(resultSequence.AsSpan(0, length));

            Stream     stream      = new MemoryStream(dataUtf8);
            TextReader reader      = new StreamReader(stream, Encoding.UTF8, false, 1024, true);
            string     expectedStr = JsonTestHelper.NewtonsoftReturnStringHelper(reader);

            Assert.Equal(expectedStr, actualStr);
            Assert.Equal(expectedStr, actualStrSequence);

            long memoryBefore = GC.GetAllocatedBytesForCurrentThread();

            JsonLabEmptyLoopHelper(dataUtf8);
            long memoryAfter = GC.GetAllocatedBytesForCurrentThread();

            Assert.Equal(0, memoryAfter - memoryBefore);
        }
        private static void ReadFullySegmentSizeOne(bool compactData, TestCaseType type, string jsonString)
        {
            // Remove all formatting/indendation
            if (compactData)
            {
                jsonString = JsonTestHelper.GetCompactString(jsonString);
            }

            byte[] dataUtf8 = Encoding.UTF8.GetBytes(jsonString);

            Stream     stream      = new MemoryStream(dataUtf8);
            TextReader reader      = new StreamReader(stream, Encoding.UTF8, false, 1024, true);
            string     expectedStr = JsonTestHelper.NewtonsoftReturnStringHelper(reader);

            ReadOnlySequence <byte> sequence = JsonTestHelper.GetSequence(dataUtf8, 1);

            var utf8JsonReader = new Utf8JsonReader(sequence, isFinalBlock: true, default);

            byte[] resultSequence    = JsonTestHelper.ReaderLoop(dataUtf8.Length, out int length, ref utf8JsonReader);
            string actualStrSequence = Encoding.UTF8.GetString(resultSequence, 0, length);

            Assert.Equal(expectedStr, actualStrSequence);
        }
        public static string CompileResource(string name,TestCaseType type)
        {
            string file = string.Concat(Path.GetTempFileName(),".dll");
           
            
            string path = string.Concat(TestCasesDirectory, Path.DirectorySeparatorChar + name);

            using (var provider = GetProvider(name))
            {
                var parameters = GetDefaultParameters(name);
                parameters.IncludeDebugInformation = false;
                parameters.GenerateExecutable = false;
                parameters.OutputAssembly = file;
                parameters.GenerateInMemory = false;
                if (type == TestCaseType.Release)
                    parameters.CompilerOptions = "/optimize";

                var results = provider.CompileAssemblyFromFile(parameters, path);
                AssertCompilerResults(results);
            }

            return file;
        }
Exemple #23
0
        public static void TestJsonReaderUtf8(TestCaseType type, string jsonString)
        {
            byte[] dataUtf8  = Encoding.UTF8.GetBytes(jsonString);
            byte[] result    = JsonLabReturnBytesHelper(dataUtf8, out int length);
            string actualStr = Encoding.UTF8.GetString(result.AsSpan(0, length));

            byte[] resultSequence    = JsonLabSequenceReturnBytesHelper(dataUtf8, out length);
            string actualStrSequence = Encoding.UTF8.GetString(resultSequence.AsSpan(0, length));

            Stream     stream      = new MemoryStream(dataUtf8);
            TextReader reader      = new StreamReader(stream, Encoding.UTF8, false, 1024, true);
            string     expectedStr = NewtonsoftReturnStringHelper(reader);

            Assert.Equal(expectedStr, actualStr);
            Assert.Equal(expectedStr, actualStrSequence);

            long memoryBefore = GC.GetAllocatedBytesForCurrentThread();

            JsonLabEmptyLoopHelper(dataUtf8);
            long memoryAfter = GC.GetAllocatedBytesForCurrentThread();

            Assert.Equal(0, memoryAfter - memoryBefore);
        }
Exemple #24
0
        ///  ------------------------------------------------------------------
        /// <summary>
        /// Run all the tests for patterns, control type, and AutomationElement that meet the criteria as supplied as arguments
        /// </summary>
        /// <returns></returns>
        ///  ------------------------------------------------------------------
        public static bool RunAllTests(AutomationElement element, bool testEvents, TestPriorities priority, TestCaseType testCaseType, bool testChildren, bool normalize, IApplicationCommands commands)
        {
            bool passed = true;

            if (element != null)
            {
                try
                {
                    passed &= RunAllControlTests(element, testEvents, priority, testCaseType, testChildren, normalize, commands);
                    passed &= RunAutomationElementTests(element, testEvents, priority, testCaseType, testChildren, normalize, commands);
                    passed &= RunAllPatternTests(element, testEvents, priority, testCaseType, testChildren, normalize, commands);
                }
                catch (Exception exception)
                {
                    UIVerifyLogger.LogUnexpectedError(exception);
                }
            }
            return passed;
        }
Exemple #25
0
        public void ParseJson(bool compactData, TestCaseType type, string jsonString)
        {
            // Remove all formatting/indendation
            if (compactData)
            {
                using (JsonTextReader jsonReader = new JsonTextReader(new StringReader(jsonString)))
                {
                    jsonReader.FloatParseHandling = FloatParseHandling.Decimal;
                    JToken jtoken       = JToken.ReadFrom(jsonReader);
                    var    stringWriter = new StringWriter();
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(stringWriter))
                    {
                        jtoken.WriteTo(jsonWriter);
                        jsonString = stringWriter.ToString();
                    }
                }
            }

            byte[] dataUtf8 = Encoding.UTF8.GetBytes(jsonString);

            JsonObject obj = JsonObject.Parse(dataUtf8);

            var stream       = new MemoryStream(dataUtf8);
            var streamReader = new StreamReader(stream, Encoding.UTF8, false, 1024, true);

            using (JsonTextReader jsonReader = new JsonTextReader(streamReader))
            {
                JToken jtoken = JToken.ReadFrom(jsonReader);

                string expectedString = "";
                string actualString   = "";

                if (type == TestCaseType.Json400KB)
                {
                    expectedString = ReadJson400KB(jtoken);
                    actualString   = ReadJson400KB(obj);
                }
                else if (type == TestCaseType.HelloWorld)
                {
                    expectedString = ReadHelloWorld(jtoken);
                    actualString   = ReadHelloWorld(obj);
                }
                Assert.Equal(expectedString, actualString);
            }

            string actual = obj.PrintJson();

            // Change casing to match what JSON.NET does.
            actual = actual.Replace("true", "True").Replace("false", "False");

            TextReader reader   = new StringReader(jsonString);
            string     expected = JsonTestHelper.NewtonsoftReturnStringHelper(reader);

            Assert.Equal(expected, actual);

            if (compactData)
            {
                var output   = new ArrayFormatterWrapper(1024, SymbolTable.InvariantUtf8);
                var jsonUtf8 = new Utf8JsonWriter <ArrayFormatterWrapper>(output);

                jsonUtf8.Write(obj);
                jsonUtf8.Flush();

                ArraySegment <byte> formatted = output.Formatted;
                string actualStr = Encoding.UTF8.GetString(formatted.Array, formatted.Offset, formatted.Count);

                Assert.Equal(jsonString, actualStr);
            }

            obj.Dispose();
        }
Exemple #26
0
 /// ---------------------------------------------------------------------------
 /// <summary></summary>
 /// ---------------------------------------------------------------------------
 static public string ParseType(TestCaseType value)
 {
     return ParseType(value.GetType().ToString(), value.ToString());
 }
 public static void TestJsonReaderLargeUtf8SegmentSizeOne(bool compactData, TestCaseType type, string jsonString)
 {
     ReadFullySegmentSizeOne(compactData, type, jsonString);
 }
Exemple #28
0
        /// -------------------------------------------------------------------
        /// <summary>
        /// Run all the tests associated with the defined pattern and that meet 
        /// the criteria as supplied as arguments
        /// </summary>
        /// -------------------------------------------------------------------
        public static bool RunPatternTests(AutomationElement element, bool testEvents, TestPriorities priority, TestCaseType testCaseType, string testSuite, IApplicationCommands commands)
        {
            bool passed = true;

            if (element != null)
            {
                try
                {
                    object testObject = TestObject.GetPatternTestObject(testSuite, element, testEvents, priority, commands);
                    passed &= ((TestObject)testObject).InvokeTests(testSuite, testCaseType);
                }

                catch (Exception exception)
                {
                    if (exception.InnerException != null && !(exception.InnerException is IncorrectElementConfigurationForTestException))
                        UIVerifyLogger.LogUnexpectedError(exception);
                }
            }
            return passed;
        }
		static CecilTestCase CreateTestCase (MethodInfo method, TestCecilAttribute attribute, TestCaseType type)
		{
			return new CecilTestCase (method, attribute, type);
		}
Exemple #30
0
        /// -------------------------------------------------------------------
        /// <summary>
        /// Run all the AutomationElement tests on the element that meet the
        /// criteria as supplied as arguments
        /// </summary>
        /// -------------------------------------------------------------------
        public static bool RunAutomationElementTests(AutomationElement element, bool testEvents, TestPriorities priority, TestCaseType testCaseType, bool testChildren, bool normalize, IApplicationCommands commands)
        {
            bool passed = true;

            if (element != null)
            {
                try
                {
                    object test = new AutomationElementTests(element, priority, null, testEvents, TypeOfControl.UnknownControl, commands);

                    passed &= ((TestObject)test).InvokeTests(AutomationElementTests.TestSuite, testCaseType);

                    if (testChildren)
                    {
                        passed &= RunAutomationElementTestsOnDescendants(TreeWalker.ControlViewWalker.GetFirstChild(element), testEvents, testChildren, priority, normalize, testCaseType, commands);
                    }
                }
                catch (Exception exception)
                {
                    UIVerifyLogger.LogUnexpectedError(exception);
                }
            }
            return(passed);
        }
Exemple #31
0
        /// -------------------------------------------------------------------
        /// <summary>
        /// Run all the supported pattern tests associated with the element and that meet
        /// the criteria as supplied as arguments
        /// </summary>
        /// -------------------------------------------------------------------
        public static bool RunAllPatternTests(AutomationElement element, bool testEvents, TestPriorities priority, TestCaseType testCaseType, bool testChildren, bool normalize, IApplicationCommands commands)
        {
            bool passed = true;

            if (element != null)
            {
                try
                {
                    ArrayList al = Helpers.GetPatternSuitesForAutomationElement(element);

                    foreach (string testSuite in al)
                    {
                        passed &= RunPatternTests(element, testEvents, priority, testCaseType, testSuite, commands);
                    }

                    if (testChildren)
                    {
                        passed &= RunAllPatternTestsOnDescendants(TreeWalker.ControlViewWalker.GetFirstChild(element), testEvents, testChildren, priority, normalize, testCaseType, commands);
                    }
                }
                catch (Exception exception)
                {
                    UIVerifyLogger.LogUnexpectedError(exception);
                }
            }
            return passed;
        }
Exemple #32
0
 static CecilTestCase CreateTestCase(MethodInfo method, TestCecilAttribute attribute, TestCaseType type)
 {
     return(new CecilTestCase(method, attribute, type));
 }
Exemple #33
0
        /// -------------------------------------------------------------------
        /// <summary>
        /// Run all control tests, pattern tests, and automation element tests
        /// </summary>
        /// -------------------------------------------------------------------
        public static bool RunAllControlTests(AutomationElement element, bool testEvents, TestPriorities priority, TestCaseType testCaseType, bool testChildren, bool normalize, IApplicationCommands commands)
        {
            bool passed = true;

            if (element != null)
            {
                try
                {
                    passed &= RunControlTests(element, testEvents, false, priority, testCaseType, commands);

                    if (testChildren)
                    {
                        passed &= RunAllControlTestOnDescendants(TreeWalker.ControlViewWalker.GetFirstChild(element), testEvents, testChildren, priority, normalize, testCaseType, commands);
                    }
                }
                catch (Exception exception)
                {
                    UIVerifyLogger.LogUnexpectedError(exception);
                }
            }
            return passed;
        }
Exemple #34
0
        /// -------------------------------------------------------------------
        /// <summary>
        /// Run all the AutomationElement tests on the element that meet the 
        /// criteria as supplied as arguments
        /// </summary>
        /// -------------------------------------------------------------------
        public static bool RunAutomationElementTests(AutomationElement element, bool testEvents, TestPriorities priority, TestCaseType testCaseType, bool testChildren, bool normalize, IApplicationCommands commands)
        {
            bool passed = true;

            if (element != null)
            {
                try
                {
                    object test = new AutomationElementTests(element, priority, null, testEvents, TypeOfControl.UnknownControl, commands);

                    passed &= ((TestObject)test).InvokeTests(AutomationElementTests.TestSuite, testCaseType);

                    if (testChildren)
                    {
                        passed &= RunAutomationElementTestsOnDescendants(TreeWalker.ControlViewWalker.GetFirstChild(element), testEvents, testChildren, priority, normalize, testCaseType, commands);
                    }
                }
                catch (Exception exception)
                {
                    UIVerifyLogger.LogUnexpectedError(exception);
                }
            }
            return passed;
        }
Exemple #35
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        static bool RunPatternTestsOnDescendants(AutomationElement element, bool testEvents, bool testChildren, string testSuite, TestCaseType testCaseType, IApplicationCommands commands)
        {
            bool passed = true;

            if (element != null)
            {
                try
                {

                    object testObject = TestObject.GetPatternTestObject(testSuite, element, testEvents, TestPriorities.PriAll, commands);

                    // Test this object
                    passed &= ((TestObject)testObject).InvokeTests(testSuite, testCaseType);
                    if (testChildren)
                    {
                        passed &= RunPatternTestsOnDescendants(TreeWalker.ControlViewWalker.GetFirstChild(element), testEvents, testChildren, testSuite, testCaseType, commands);
                        passed &= RunPatternTestsOnDescendants(TreeWalker.ControlViewWalker.GetNextSibling(element), testEvents, testChildren, testSuite, testCaseType, commands);
                    }
                }
                catch (Exception exception)
                {
                    UIVerifyLogger.LogUnexpectedError(exception);
                }
            }

            return passed;
        }
Exemple #36
0
		public TestRunner(TestCase testCase, TestCaseType type)
		{
			this.test_case = testCase;
			this.type = type;
		}
Exemple #37
0
        ///  ------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        ///  ------------------------------------------------------------------
        public static bool RunControlTests(AutomationElement element, bool testEvents, bool testChildren, TestPriorities priority, TestCaseType testCaseType, IApplicationCommands commands)
        {
            bool passed = true;

            if (element != null)
            {
                try
                {
                    string testSuite = TestObject.GetTestType(element);
                    object testObject = TestObject.GetControlTestObject(element, testEvents, priority, commands);
                    passed &= ((TestObject)testObject).InvokeTests(testSuite, testCaseType);
                    if (testChildren)
                    {
                        passed &= RunControlTestsOnDescendants(TreeWalker.ControlViewWalker.GetFirstChild(element), testEvents, testChildren, priority, testCaseType, commands);
                    }

                }

                catch (Exception exception)
                {
                    UIVerifyLogger.LogUnexpectedError(exception);
                }
            }
            return passed;
        }
		public CecilTestCase (MethodInfo method, TestCecilAttribute attribute, TestCaseType type)
			: base (method)
		{
			this.TestName.Name = type.ToString ();
			this.TestName.FullName = method.DeclaringType.FullName + "." + method.Name + "." + type;
			this.attribute = attribute;
			this.type = type;
		}
Exemple #39
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        static bool RunPatternTestsOnDescendants(AutomationElement element, bool testEvents, bool testChildren, string testSuite, TestCaseType testCaseType, IApplicationCommands commands)
        {
            bool passed = true;

            if (element != null)
            {
                try
                {
                    object testObject = TestObject.GetPatternTestObject(testSuite, element, testEvents, TestPriorities.PriAll, commands);

                    // Test this object
                    passed &= ((TestObject)testObject).InvokeTests(testSuite, testCaseType);
                    if (testChildren)
                    {
                        passed &= RunPatternTestsOnDescendants(TreeWalker.ControlViewWalker.GetFirstChild(element), testEvents, testChildren, testSuite, testCaseType, commands);
                        passed &= RunPatternTestsOnDescendants(TreeWalker.ControlViewWalker.GetNextSibling(element), testEvents, testChildren, testSuite, testCaseType, commands);
                    }
                }
                catch (Exception exception)
                {
                    UIVerifyLogger.LogUnexpectedError(exception);
                }
            }

            return(passed);
        }
Exemple #40
0
        /// -------------------------------------------------------------------
        /// <summary>
        /// Recursively tests the children Logical Elements
        /// </summary>
        /// -------------------------------------------------------------------
        static bool RunAutomationElementTestsOnDescendants(AutomationElement element, bool testEvents, bool testChildren, TestPriorities priority, bool normalize, TestCaseType testCaseType, IApplicationCommands commands)
        {
            bool passed = true;

            if (element != null)
            {
                try
                {
                    AutomationElement     tempLe;
                    ArrayList             list;
                    Hashtable             ht         = GetHashedElements(element);
                    IDictionaryEnumerator enumerator = ht.GetEnumerator();
                    Random rnd = new Random(unchecked ((int)DateTime.Now.Ticks));

                    // Add the nodes to the tree.  Some of the nodes we may want to remove
                    // because of redundancy for specific nodes as defined in the m_Duplicate
                    // ArrayList.
                    while (enumerator.MoveNext())
                    {
                        list = (ArrayList)ht[enumerator.Key];
                        if (normalize && Array.IndexOf(m_Duplicate, enumerator.Key) != -1)
                        {
                            // Remove defined items that we don't want duplicates of
                            tempLe = (AutomationElement)list[rnd.Next(list.Count)];

                            passed &= RunAutomationElementTests(tempLe, testEvents, priority, testCaseType, false, normalize, commands);
                            if (testChildren)
                            {
                                passed &= RunAutomationElementTestsOnDescendants(TreeWalker.ControlViewWalker.GetFirstChild(tempLe), testEvents, testChildren, priority, normalize, testCaseType, commands);
                            }
                        }
                        else
                        {
                            // Add everything else whether duplicate or not
                            foreach (AutomationElement el in list)
                            {
                                passed &= RunAutomationElementTests(el, testEvents, priority, testCaseType, false, normalize, commands);
                                if (testChildren)
                                {
                                    passed &= RunAutomationElementTestsOnDescendants(TreeWalker.ControlViewWalker.GetFirstChild(el), testEvents, testChildren, priority, normalize, testCaseType, commands);
                                }
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    UIVerifyLogger.LogUnexpectedError(exception);
                }
            }
            return(passed);
        }
 private static TestCase CreateTestCase(MethodInfo method, TestCaseType testCaseType, string filename, string resultFilename)
 {
     return(new DecompilationTestCase(method, testCaseType, filename, resultFilename));
 }
 public static void TestJsonReaderUtf8SegmentSizeOne(bool compactData, TestCaseType type, string jsonString)
 {
     ReadPartialSegmentSizeOne(compactData, type, jsonString);
 }
Exemple #43
0
 public TestRunner(TestCase testCase, TestCaseType type)
 {
     this.test_case = testCase;
     this.type      = type;
 }
Exemple #44
0
        public void UpdateTestCase(int id, byte[] input, byte[] output, TestCaseType? type)
        {
            using (DB db = new DB())
            {
                CheckRole(db, UserRole.Manager);

                TestCase testCase = db.TestCases.Find(id);
                if (testCase == null) throw new FaultException<NotFoundError>(new NotFoundError { ID = id, Type = "TestCase" });

                if (input != null)
                {
                    testCase.Input = input;
                    testCase.InputHash = MD5.Create().ComputeHash(input);
                }
                if (output != null)
                {
                    testCase.Output = output;
                    testCase.OutputHash = MD5.Create().ComputeHash(output);
                }
                if (type != null)
                    testCase.Type = type.Value;

                db.SaveChanges();
            }
        }
 private static TestCase CreateTestCase(MethodInfo method, TestCaseType testCaseType, string filename, string resultFilename)
 {
     return new DecompilationTestCase(method, testCaseType, filename, resultFilename);
 }
Exemple #46
0
        /// -------------------------------------------------------------------
        /// <summary>
        /// Run all control tests, pattern tests, and automation element tests
        /// </summary>
        /// -------------------------------------------------------------------
        public static bool RunAllControlTests(AutomationElement element, bool testEvents, TestPriorities priority, TestCaseType testCaseType, bool testChildren, bool normalize, IApplicationCommands commands)
        {
            bool passed = true;

            if (element != null)
            {
                try
                {
                    passed &= RunControlTests(element, testEvents, false, priority, testCaseType, commands);

                    if (testChildren)
                    {
                        passed &= RunAllControlTestOnDescendants(TreeWalker.ControlViewWalker.GetFirstChild(element), testEvents, testChildren, priority, normalize, testCaseType, commands);
                    }
                }
                catch (Exception exception)
                {
                    UIVerifyLogger.LogUnexpectedError(exception);
                }
            }
            return(passed);
        }
Exemple #47
0
        /// -------------------------------------------------------------------
        /// <summary>
        /// Recursively tests the children Logical Elements
        /// </summary>
        /// -------------------------------------------------------------------
        static bool RunAutomationElementTestsOnDescendants(AutomationElement element, bool testEvents, bool testChildren, TestPriorities priority, bool normalize, TestCaseType testCaseType, IApplicationCommands commands)
        {
            bool passed = true;

            if (element != null)
            {
                try
                {

                    AutomationElement tempLe;
                    ArrayList list;
                    Hashtable ht = GetHashedElements(element);
                    IDictionaryEnumerator enumerator = ht.GetEnumerator();
                    Random rnd = new Random(unchecked((int)DateTime.Now.Ticks));

                    // Add the nodes to the tree.  Some of the nodes we may want to remove
                    // because of redundancy for specific nodes as defined in the m_Duplicate
                    // ArrayList.
                    while (enumerator.MoveNext())
                    {
                        list = (ArrayList)ht[enumerator.Key];
                        if (normalize && Array.IndexOf(m_Duplicate, enumerator.Key) != -1)
                        {
                            // Remove defined items that we don't want duplicates of
                            tempLe = (AutomationElement)list[rnd.Next(list.Count)];

                            passed &= RunAutomationElementTests(tempLe, testEvents, priority, testCaseType, false, normalize, commands);
                            if (testChildren)
                            {
                                passed &= RunAutomationElementTestsOnDescendants(TreeWalker.ControlViewWalker.GetFirstChild(tempLe), testEvents, testChildren, priority, normalize, testCaseType, commands);
                            }
                        }
                        else
                        {
                            // Add everything else whether duplicate or not
                            foreach (AutomationElement el in list)
                            {
                                passed &= RunAutomationElementTests(el, testEvents, priority, testCaseType, false, normalize, commands);
                                if (testChildren)
                                {
                                    passed &= RunAutomationElementTestsOnDescendants(TreeWalker.ControlViewWalker.GetFirstChild(el), testEvents, testChildren, priority, normalize, testCaseType, commands);
                                }
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    UIVerifyLogger.LogUnexpectedError(exception);
                }
            }
            return passed;
        }
Exemple #48
0
        /// -------------------------------------------------------------------
        /// <summary>
        /// Run a specific suite of tests
        /// </summary>
        /// -------------------------------------------------------------------
        internal bool InvokeTests(string testSuite, TestCaseType testCaseType)
        {

            // Returned results from the tests
            bool passed = true;

            Type type = Type.GetType(testSuite);

            if (type == null)
                throw new Exception("Type.GetType(" + testSuite + ") failed.");

            foreach (MethodInfo method in type.GetMethods())
            {
                foreach (Attribute attr in method.GetCustomAttributes(true))
                {
                    if (attr is TestCaseAttribute)
                    {
                        TestCaseAttribute testAttribute = (TestCaseAttribute)attr;

                        // Run this if the priority and status are correct.
                        if (testAttribute.Status.Equals(TestStatus.Works) && ((testAttribute.TestCaseType & TestCaseType.Arguments) != TestCaseType.Arguments))
                        {
                            if (m_TestPriority.Equals(TestPriorities.PriAll) || ((int)testAttribute.Priority & (int)m_TestPriority) != 0)
                            {
                                if ((testCaseType & testAttribute.TestCaseType) == testCaseType)
                                {
                                    if (false == invokeTest(m_le, method, testAttribute, null))
                                        passed = false;

                                    // If caller wants to cancel running tests...
                                    if (TestObject._cancelRun == true)
                                    {
                                        TestObject._cancelRun = false;
                                        return passed;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return passed;
        }
Exemple #49
0
        public int CreateTestCase(int problemID, byte[] input, byte[] output, TestCaseType type)
        {
            using (DB db = new DB())
            {
                CheckRole(db, UserRole.Manager);

                TestCase testCase = new TestCase
                {
                    Input = input,
                    InputHash = MD5.Create().ComputeHash(input),
                    Output = output,
                    OutputHash = MD5.Create().ComputeHash(output),
                    ProblemID = problemID,
                    Type = type
                };
                db.TestCases.Add(testCase);
                db.SaveChanges();
                return testCase.ID;
            }
        }