示例#1
0
 public void DictionaryObjectValueSerialization()
 {
     this.LogStart("Dictionary (Object Value)");
     try
     {
         Dictionary <int, SampleBase> nums = new Dictionary <int, SampleBase>();
         for (int i = 0; i < 4; i++)
         {
             nums.Add(i, TestCaseUtils.GetSampleBase());
         }
         string str = JsonConvert.SerializeObject(nums);
         this.LogSerialized(str);
         Dictionary <int, SampleBase> nums1 = JsonConvert.DeserializeObject <Dictionary <int, SampleBase> >(str);
         this.LogResult(nums[1].TextValue, nums1[1].TextValue);
         if (nums[1].TextValue == nums1[1].TextValue)
         {
             this.DisplaySuccess("Dictionary (Object Value)");
         }
         else
         {
             this.DisplayFail("Dictionary (Object Value)", "Incorrect Deserialized Result");
         }
     }
     catch (Exception exception)
     {
         this.DisplayFail("Dictionary (Object Value)", exception.Message);
         throw;
     }
 }
示例#2
0
 public void GenericListSerialization()
 {
     this.LogStart("List<T> Serialization");
     try
     {
         List <SimpleClassObject> list = new List <SimpleClassObject>();
         for (int i = 0; i < 4; i++)
         {
             list.Add(TestCaseUtils.GetSimpleClassObject());
         }
         string text = JsonConvert.SerializeObject(list);
         this.LogSerialized(text);
         List <SimpleClassObject> list2 = JsonConvert.DeserializeObject <List <SimpleClassObject> >(text);
         this.LogResult(list.get_Count().ToString(), list2.get_Count());
         this.LogResult(list.get_Item(2).TextValue, list2.get_Item(2).TextValue);
         if (list.get_Count() != list2.get_Count() || list.get_Item(3).TextValue != list2.get_Item(3).TextValue)
         {
             this.DisplayFail("List<T> Serialization", "Incorrect Deserialized Result");
             Debug.LogError("Deserialized List<T> has incorrect count or wrong item value");
         }
         else
         {
             this.DisplaySuccess("List<T> Serialization");
         }
     }
     catch (Exception ex)
     {
         this.DisplayFail("List<T> Serialization", ex.get_Message());
         throw;
     }
     this.LogEnd(2);
 }
 public void CanFilterConvertedTestsByCategoryWithCategoryAsFilter(string category, IReadOnlyCollection <string> expectedMatchingTestNames)
 {
     FilteringTestUtils.AssertExpectedResult(
         TestDoubleFilterExpression.AnyIsEqualTo("Category", category),
         TestCaseUtils.ConvertTestCases(FakeTestData.HierarchyTestXml),
         expectedMatchingTestNames);
 }
示例#4
0
 private static void HandleMinimization(string[] args)
 {
     string[] args2 = new string[args.Length - 1];
     Array.Copy(args, 1, args2, 0, args.Length - 1);
     TestCaseUtils.Minimize(TestCaseUtils.CollectFilesEndingWith(".cs", args2));
     Environment.Exit(0);
 }
示例#5
0
 public void GenericListSerialization()
 {
     this.LogStart("List<T> Serialization");
     try
     {
         List <SimpleClassObject> simpleClassObjects = new List <SimpleClassObject>();
         for (int i = 0; i < 4; i++)
         {
             simpleClassObjects.Add(TestCaseUtils.GetSimpleClassObject());
         }
         string str = JsonConvert.SerializeObject(simpleClassObjects);
         this.LogSerialized(str);
         List <SimpleClassObject> simpleClassObjects1 = JsonConvert.DeserializeObject <List <SimpleClassObject> >(str);
         int count = simpleClassObjects.Count;
         this.LogResult(count.ToString(), simpleClassObjects1.Count);
         this.LogResult(simpleClassObjects[2].TextValue, simpleClassObjects1[2].TextValue);
         if (simpleClassObjects.Count != simpleClassObjects1.Count || simpleClassObjects[3].TextValue != simpleClassObjects1[3].TextValue)
         {
             this.DisplayFail("List<T> Serialization", "Incorrect Deserialized Result");
             Debug.LogError("Deserialized List<T> has incorrect count or wrong item value");
         }
         else
         {
             this.DisplaySuccess("List<T> Serialization");
         }
     }
     catch (Exception exception)
     {
         this.DisplayFail("List<T> Serialization", exception.Message);
         throw;
     }
     this.LogEnd(2);
 }
示例#6
0
        private static IEnumerable <TestCase> ApplyFilter(string vsTestFilterString, string testCasesXml)
        {
            var filter = FilteringTestUtils.CreateTestFilter(string.IsNullOrEmpty(vsTestFilterString) ? null :
                                                             FilteringTestUtils.CreateVSTestFilterExpression(vsTestFilterString));

            return(filter.CheckFilter(TestCaseUtils.ConvertTestCases(testCasesXml)));
        }
示例#7
0
 private static void DeleteStatLogs(string outputDir)
 {
     foreach (FileInfo fi in TestCaseUtils.CollectFilesEndingWith(".stats.txt", outputDir))
     {
         fi.Delete();
     }
 }
示例#8
0
 public void DictionaryObjectValueSerialization()
 {
     this.LogStart("Dictionary (Object Value)");
     try
     {
         Dictionary <int, SampleBase> dictionary = new Dictionary <int, SampleBase>();
         for (int i = 0; i < 4; i++)
         {
             dictionary.Add(i, TestCaseUtils.GetSampleBase());
         }
         string text = JsonConvert.SerializeObject(dictionary);
         this.LogSerialized(text);
         Dictionary <int, SampleBase> dictionary2 = JsonConvert.DeserializeObject <Dictionary <int, SampleBase> >(text);
         this.LogResult(dictionary.get_Item(1).TextValue, dictionary2.get_Item(1).TextValue);
         if (dictionary.get_Item(1).TextValue != dictionary2.get_Item(1).TextValue)
         {
             this.DisplayFail("Dictionary (Object Value)", "Incorrect Deserialized Result");
         }
         else
         {
             this.DisplaySuccess("Dictionary (Object Value)");
         }
     }
     catch (Exception ex)
     {
         this.DisplayFail("Dictionary (Object Value)", ex.get_Message());
         throw;
     }
 }
示例#9
0
    /// <summary>
    /// Serialize a dictionary with an object as the value
    /// </summary>
    public void DictionaryObjectValueSerialization()
    {
        LogStart("Dictionary (Object Value)");

        try
        {
            var dict = new Dictionary <int, SampleBase>();

            for (var i = 0; i < 4; i++)
            {
                dict.Add(i, TestCaseUtils.GetSampleBase());
            }

            var serialized = JsonConvert.SerializeObject(dict);
            LogSerialized(serialized);

            var newDict = JsonConvert.DeserializeObject <Dictionary <int, SampleBase> >(serialized);

            LogResult(dict[1].TextValue, newDict[1].TextValue);

            if (dict[1].TextValue != newDict[1].TextValue)
            {
                DisplayFail("Dictionary (Object Value)", BAD_RESULT_MESSAGE);
            }
            else
            {
                DisplaySuccess("Dictionary (Object Value)");
            }
        }
        catch (Exception ex)
        {
            DisplayFail("Dictionary (Object Value)", ex.Message);
            throw;
        }
    }
示例#10
0
        private static void HandleReduction(string[] args, Func <Collection <FileInfo>, Collection <FileInfo> > reduction)
        {
            string[] args2 = new string[args.Length - 1];
            Array.Copy(args, 1, args2, 0, args.Length - 1);
            Collection <FileInfo> oldTests = TestCaseUtils.CollectFilesEndingWith(".cs", args2);

            Console.WriteLine("Number of original tests: " + oldTests.Count);
            Collection <FileInfo> newTests = reduction(oldTests);

            Console.WriteLine("Number of reduced tests: " + newTests.Count);
            Environment.Exit(0);
        }
示例#11
0
    /// <summary>
    /// Polymorphism
    /// </summary>
    public void PolymorphicSerialization()
    {
        LogStart("Polymorphic Serialization");

        try
        {
            var list = new List <SampleBase>();

            for (var i = 0; i < 4; i++)
            {
                list.Add(TestCaseUtils.GetSampleChid());
            }

            var serialized = JsonConvert.SerializeObject(list, Formatting.None, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            });
            LogSerialized(serialized);

            var newList = JsonConvert.DeserializeObject <List <SampleBase> >(serialized, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            });

            var deserializedObject = newList[2] as SampleChild;

            if (deserializedObject == null)
            {
                DisplayFail("Polymorphic Serialization", BAD_RESULT_MESSAGE);
            }
            else
            {
                LogResult(list[2].TextValue, newList[2].TextValue);

                if (list[2].TextValue != newList[2].TextValue)
                {
                    DisplayFail("Polymorphic Serialization", BAD_RESULT_MESSAGE);
                }
                else
                {
                    DisplaySuccess("Polymorphic Serialization");
                }
            }
        }
        catch (Exception ex)
        {
            DisplayFail("Polymorphic Serialization", ex.Message);
            throw;
        }


        LogEnd(3);
    }
示例#12
0
    /// <summary>
    /// Serialize a dictionary with an object as the key
    /// </summary>
    public void DictionaryObjectKeySerialization()
    {
        LogStart("Dictionary (Object As Key)");

        try
        {
            var dict = new Dictionary <SampleBase, int>();

            for (var i = 0; i < 4; i++)
            {
                dict.Add(TestCaseUtils.GetSampleBase(), i);
            }

            var serialized = JsonConvert.SerializeObject(dict);
            LogSerialized(serialized);
            _text.text = serialized;
            var newDict = JsonConvert.DeserializeObject <Dictionary <SampleBase, int> >(serialized);


            var oldKeys = new List <SampleBase>();
            var newKeys = new List <SampleBase>();

            foreach (var k in dict.Keys)
            {
                oldKeys.Add(k);
            }

            foreach (var k in newDict.Keys)
            {
                newKeys.Add(k);
            }

            LogResult(oldKeys[1].TextValue, newKeys[1].TextValue);

            if (oldKeys[1].TextValue != newKeys[1].TextValue)
            {
                DisplayFail("Dictionary (Object As Key)", BAD_RESULT_MESSAGE);
            }
            else
            {
                DisplaySuccess("Dictionary (Object As Key)");
            }
        }
        catch (Exception ex)
        {
            DisplayFail("Dictionary (Object As Key)", ex.Message);
            throw;
        }
    }
示例#13
0
 public void DictionaryObjectKeySerialization()
 {
     this.LogStart("Dictionary (Object As Key)");
     try
     {
         Dictionary <SampleBase, int> dictionary = new Dictionary <SampleBase, int>();
         for (int i = 0; i < 4; i++)
         {
             dictionary.Add(TestCaseUtils.GetSampleBase(), i);
         }
         string text = JsonConvert.SerializeObject(dictionary);
         this.LogSerialized(text);
         this._text.set_text(text);
         Dictionary <SampleBase, int> dictionary2 = JsonConvert.DeserializeObject <Dictionary <SampleBase, int> >(text);
         List <SampleBase>            list        = new List <SampleBase>();
         List <SampleBase>            list2       = new List <SampleBase>();
         using (Dictionary <SampleBase, int> .KeyCollection.Enumerator enumerator = dictionary.get_Keys().GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 SampleBase current = enumerator.get_Current();
                 list.Add(current);
             }
         }
         using (Dictionary <SampleBase, int> .KeyCollection.Enumerator enumerator2 = dictionary2.get_Keys().GetEnumerator())
         {
             while (enumerator2.MoveNext())
             {
                 SampleBase current2 = enumerator2.get_Current();
                 list2.Add(current2);
             }
         }
         this.LogResult(list.get_Item(1).TextValue, list2.get_Item(1).TextValue);
         if (list.get_Item(1).TextValue != list2.get_Item(1).TextValue)
         {
             this.DisplayFail("Dictionary (Object As Key)", "Incorrect Deserialized Result");
         }
         else
         {
             this.DisplaySuccess("Dictionary (Object As Key)");
         }
     }
     catch (Exception ex)
     {
         this.DisplayFail("Dictionary (Object As Key)", ex.get_Message());
         throw;
     }
 }
示例#14
0
 public void PolymorphicSerialization()
 {
     this.LogStart("Polymorphic Serialization");
     try
     {
         List <SampleBase> sampleBases = new List <SampleBase>();
         for (int i = 0; i < 4; i++)
         {
             sampleBases.Add(TestCaseUtils.GetSampleChid());
         }
         JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings()
         {
             TypeNameHandling = TypeNameHandling.All
         };
         string str = JsonConvert.SerializeObject(sampleBases, Formatting.None, jsonSerializerSetting);
         this.LogSerialized(str);
         jsonSerializerSetting = new JsonSerializerSettings()
         {
             TypeNameHandling = TypeNameHandling.All
         };
         List <SampleBase> sampleBases1 = JsonConvert.DeserializeObject <List <SampleBase> >(str, jsonSerializerSetting);
         if (sampleBases1[2] is SampleChild)
         {
             this.LogResult(sampleBases[2].TextValue, sampleBases1[2].TextValue);
             if (sampleBases[2].TextValue == sampleBases1[2].TextValue)
             {
                 this.DisplaySuccess("Polymorphic Serialization");
             }
             else
             {
                 this.DisplayFail("Polymorphic Serialization", "Incorrect Deserialized Result");
             }
         }
         else
         {
             this.DisplayFail("Polymorphic Serialization", "Incorrect Deserialized Result");
         }
     }
     catch (Exception exception)
     {
         this.DisplayFail("Polymorphic Serialization", exception.Message);
         throw;
     }
     this.LogEnd(3);
 }
示例#15
0
 public void PolymorphicSerialization()
 {
     this.LogStart("Polymorphic Serialization");
     try
     {
         List <SampleBase> list = new List <SampleBase>();
         for (int i = 0; i < 4; i++)
         {
             list.Add(TestCaseUtils.GetSampleChid());
         }
         string text = JsonConvert.SerializeObject(list, Formatting.None, new JsonSerializerSettings
         {
             TypeNameHandling = TypeNameHandling.All
         });
         this.LogSerialized(text);
         List <SampleBase> list2 = JsonConvert.DeserializeObject <List <SampleBase> >(text, new JsonSerializerSettings
         {
             TypeNameHandling = TypeNameHandling.All
         });
         if (!(list2.get_Item(2) is SampleChild))
         {
             this.DisplayFail("Polymorphic Serialization", "Incorrect Deserialized Result");
         }
         else
         {
             this.LogResult(list.get_Item(2).TextValue, list2.get_Item(2).TextValue);
             if (list.get_Item(2).TextValue != list2.get_Item(2).TextValue)
             {
                 this.DisplayFail("Polymorphic Serialization", "Incorrect Deserialized Result");
             }
             else
             {
                 this.DisplaySuccess("Polymorphic Serialization");
             }
         }
     }
     catch (Exception ex)
     {
         this.DisplayFail("Polymorphic Serialization", ex.get_Message());
         throw;
     }
     this.LogEnd(3);
 }
示例#16
0
        // false if no tests found.
        private static bool PostProcessTests(CommandLineArguments args, string outputDir)
        {
            //////////////////////////////////////////////////////////////////////
            // Determine directory where generated tests were written.

            DirectoryInfo resultsDir = new DirectoryInfo(outputDir);

            //////////////////////////////////////////////////////////////////////
            // Collect all tests generated.

            Collection <FileInfo> tests = TestCaseUtils.CollectFilesEndingWith(".cs", resultsDir);

            if (tests.Count == 0)
            {
                return(false);
            }

            Dictionary <TestCase.ExceptionDescription, Collection <FileInfo> > classifiedTests =
                TestCaseUtils.ClassifyTestsByMessage(tests);

            PrintStats(classifiedTests);

            //////////////////////////////////////////////////////////////////////
            // Create stats file.

            StatsManager.ComputeStats(resultsDir + "\\allstats.txt",
                                      TestCaseUtils.CollectFilesEndingWith(".stats.txt", resultsDir));

            //////////////////////////////////////////////////////////////////////
            // Create HTML index.

            //HtmlSummary.CreateIndexHtml(classifiedTests, resultsDir + "\\index.html", args.ToString());
            HtmlSummary.CreateIndexHtml2(classifiedTests, resultsDir + "\\index.html", args.ToString());

            Console.WriteLine();
            Console.WriteLine("Results written to " + resultsDir + ".");
            Console.WriteLine("You can browse the results by opening the file "
                              + System.Environment.NewLine
                              + "   " + resultsDir + "\\index.html");

            return(true);
        }
示例#17
0
 public void DictionaryObjectKeySerialization()
 {
     this.LogStart("Dictionary (Object As Key)");
     try
     {
         Dictionary <SampleBase, int> dictionary = new Dictionary <SampleBase, int>();
         for (int i = 0; i < 4; i++)
         {
             dictionary.Add(TestCaseUtils.GetSampleBase(), i);
         }
         string text = JsonConvert.SerializeObject(dictionary);
         this.LogSerialized(text);
         this._text.text = text;
         Dictionary <SampleBase, int> dictionary2 = JsonConvert.DeserializeObject <Dictionary <SampleBase, int> >(text);
         List <SampleBase>            list        = new List <SampleBase>();
         List <SampleBase>            list2       = new List <SampleBase>();
         foreach (SampleBase item in dictionary.Keys)
         {
             list.Add(item);
         }
         foreach (SampleBase item2 in dictionary2.Keys)
         {
             list2.Add(item2);
         }
         this.LogResult(list[1].TextValue, list2[1].TextValue);
         if (list[1].TextValue != list2[1].TextValue)
         {
             this.DisplayFail("Dictionary (Object As Key)", "Incorrect Deserialized Result");
         }
         else
         {
             this.DisplaySuccess("Dictionary (Object As Key)");
         }
     }
     catch (Exception ex)
     {
         this.DisplayFail("Dictionary (Object As Key)", ex.Message);
         throw;
     }
 }
示例#18
0
 public void DictionaryObjectKeySerialization()
 {
     this.LogStart("Dictionary (Object As Key)");
     try
     {
         Dictionary <SampleBase, int> sampleBases = new Dictionary <SampleBase, int>();
         for (int i = 0; i < 4; i++)
         {
             sampleBases.Add(TestCaseUtils.GetSampleBase(), i);
         }
         string str = JsonConvert.SerializeObject(sampleBases);
         this.LogSerialized(str);
         this._text.text = str;
         Dictionary <SampleBase, int> sampleBases1 = JsonConvert.DeserializeObject <Dictionary <SampleBase, int> >(str);
         List <SampleBase>            sampleBases2 = new List <SampleBase>();
         List <SampleBase>            sampleBases3 = new List <SampleBase>();
         foreach (SampleBase key in sampleBases.Keys)
         {
             sampleBases2.Add(key);
         }
         foreach (SampleBase sampleBase in sampleBases1.Keys)
         {
             sampleBases3.Add(sampleBase);
         }
         this.LogResult(sampleBases2[1].TextValue, sampleBases3[1].TextValue);
         if (sampleBases2[1].TextValue == sampleBases3[1].TextValue)
         {
             this.DisplaySuccess("Dictionary (Object As Key)");
         }
         else
         {
             this.DisplayFail("Dictionary (Object As Key)", "Incorrect Deserialized Result");
         }
     }
     catch (Exception exception)
     {
         this.DisplayFail("Dictionary (Object As Key)", exception.Message);
         throw;
     }
 }
示例#19
0
    /// <summary>
    /// List<T> serialization
    /// </summary>
    public void GenericListSerialization()
    {
        LogStart("List<T> Serialization");

        try
        {
            var objList = new List <SimpleClassObject>();

            for (var i = 0; i < 4; i++)
            {
                objList.Add(TestCaseUtils.GetSimpleClassObject());
            }

            var serialized = JsonConvert.SerializeObject(objList);
            LogSerialized(serialized);

            var newList = JsonConvert.DeserializeObject <List <SimpleClassObject> >(serialized);

            LogResult(objList.Count.ToString(), newList.Count);
            LogResult(objList[2].TextValue, newList[2].TextValue);

            if ((objList.Count != newList.Count) || (objList[3].TextValue != newList[3].TextValue))
            {
                DisplayFail("List<T> Serialization", BAD_RESULT_MESSAGE);
                Debug.LogError("Deserialized List<T> has incorrect count or wrong item value");
            }
            else
            {
                DisplaySuccess("List<T> Serialization");
            }
        }
        catch (Exception ex)
        {
            DisplayFail("List<T> Serialization", ex.Message);
            throw;
        }

        LogEnd(2);
    }
示例#20
0
        private static int GetNumberOfTestCases()
        {
            int count = 0;

            if (File.Exists(TestCaseUtils.AssemblyFilePath))
            {
                Assembly assemblyInfo = Assembly.LoadFrom(TestCaseUtils.AssemblyFilePath);
                Type[]   types        = assemblyInfo.GetTypes();
                foreach (var testClass in types)
                {
                    foreach (var member in testClass.GetMethods())
                    {
                        if (TestCaseUtils.IsTestCase(member))
                        {
                            count++;
                        }
                    }
                }

                Console.WriteLine("Number of test cases : " + count);
            }
            return(count);
        }
示例#21
0
 private static void ReplaceBasic()
 {
     Debug.Assert(false);
     TestCaseUtils.InitProcess();
     TestCaseUtils.ReplaceBasic();
 }
示例#22
0
        /// <summary>
        /// Main randoop entrypoint.
        /// </summary>
        static void Main(string[] args)
        {
            NLogConfigManager.CreateFileConfig();
            Console.WriteLine("Randoop.NET: an API fuzzer for .Net. Version {0} (compiled {1}).",
                              Enviroment.RandoopVersion, Enviroment.RandoopCompileDate);

            if (args.Length == 0 || IsHelpCommand(args[0]))
            {
                Console.Error.WriteLine(HelpScreen.Usagestring());
                Environment.Exit(1);
            }

            if (ContainsHelp(args))
            {
                Console.WriteLine(HelpScreen.Usagestring());
                Environment.Exit(0);
            }

            if (args[0].Equals("/about"))
            {
                WriteAboutMessageToConsole();
                Environment.Exit(0);
            }

            //[email protected] adds "RandoopMappedCalls"
            if (args[0].Equals("methodtransformer"))
            {
                string   mapfile = args[1];
                string[] args2   = new string[args.Length - 2];
                Array.Copy(args, 2, args2, 0, args.Length - 2);
                Dictionary <string, string> methodmapper = new Dictionary <string, string>();

                try
                {
                    Instrument.ParseMapFile(mapfile, ref methodmapper); //parse a file that defines the mapping between target method and replacement method

                    foreach (string asm in args2)
                    {
                        int      mapcnt      = methodmapper.Count;
                        string[] origmethods = new string[mapcnt];
                        methodmapper.Keys.CopyTo(origmethods, 0);
                        foreach (string src in origmethods)
                        {
                            Instrument.MethodInstrument(asm, src, methodmapper[src]);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Environment.Exit(-1);
                }

                Environment.Exit(0);
            }

            if (args[0].Equals("minimize"))
            {
                HandleMinimization(args);
            }

            if (args[0].Equals("reduce"))
            {
                HandleReduction(args, EquivalenceBasedReducer.Reduce);
            }

            if (args[0].Equals("reduce2"))
            {
                HandleReduction(args, SequenceBasedReducer.Reduce);
            }

            if (args[0].Equals("reproduce"))
            {
                HandleReproduction(args);
            }

            if (args[0].StartsWith("stats:"))
            {
                string statsResultsFileName = args[0].Substring("stats:".Length);

                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);

                StatsManager.ComputeStats(statsResultsFileName,
                                          TestCaseUtils.CollectFilesEndingWith(".stats.txt", args2));
                Environment.Exit(0);
            }

            GenerateTests(args);
        }
    /// <summary>
    /// Polymorphism
    /// </summary>
    public void PolymorphicSerialization()
    {
        LogStart("Polymorphic Serialization");

        try
        {
            var list = new List <SampleBase>();

            for (var i = 0; i < 4; i++)
            {
                SampleChildB newChild = TestCaseUtils.GetSampleChid();
                list.Add(newChild);
                // Debug.Log("origin color is " + newChild.curColor);
            }

            // add child A
            for (var i = 0; i < 3; i++)
            {
                SampleChildA newChild = TestCaseUtils.GetSampleChidA();
                list.Add(newChild);
            }


            for (int i = 0; i < list.Count; i++)
            {
                list[i].UdpateCoolThing();
            }

            var serialized = JsonConvert.SerializeObject(list, Formatting.None, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            });
            LogSerialized(serialized);

            List <SampleBase> newList = JsonConvert.DeserializeObject <List <SampleBase> >(serialized, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            });


            LogResult(list[2].TextValue, newList[2].TextValue);

            for (int i = 0; i < newList.Count; i++)
            {
                SampleBase objA = (newList[i]);
                objA.UdpateCoolThing();
            }

            if (list[2].TextValue != newList[2].TextValue)
            {
                DisplayFail("Polymorphic Serialization", BAD_RESULT_MESSAGE);
            }
            else
            {
                DisplaySuccess("Polymorphic Serialization");
            }



            Dictionary <int, SampleBase> testForDic = new Dictionary <int, SampleBase>();

            for (var i = 0; i < 4; i++)
            {
                SampleChildB newChild = TestCaseUtils.GetSampleChid();
                testForDic.Add(i, newChild);
            }

            // add child A
            for (var i = 6; i < 10; i++)
            {
                SampleChildA newChild = TestCaseUtils.GetSampleChidA();
                testForDic.Add(i, newChild);
            }
            serialized = JsonConvert.SerializeObject(testForDic, Formatting.None, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });
            LogSerialized(serialized);

            Dictionary <int, SampleBase> newDic = JsonConvert.DeserializeObject <Dictionary <int, SampleBase> >(serialized, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });

            foreach (KeyValuePair <int, SampleBase> data in newDic)
            {
                if (data.Value.GetType() == typeof(SampleChildA))
                {
                    SampleChildA childAObject = data.Value as SampleChildA;
                    childAObject.UpdateChildAState();
                    Debug.Log("this is sampleChildA class ");
                }
                else if (data.Value.GetType() == typeof(SampleChildB))
                {
                    Debug.Log("this is sampleChildB class ");
                }
                Debug.Log(" this item type is " + data.GetType());
                data.Value.UdpateCoolThing();
            }
        }
        catch (Exception ex)
        {
            DisplayFail("Polymorphic Serialization", ex.Message);
            throw;
        }


        LogEnd(3);
    }
示例#24
0
        /// <summary>
        /// Main randoop entrypoint.
        /// </summary>
        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("Randoop.NET: an API fuzzer for .Net. Version {0} (compiled {1}).",
                              Common.Enviroment.RandoopVersion, Common.Enviroment.RandoopCompileDate);

            if (args.Length == 0 || IsHelpCommand(args[0]))
            {
                Console.Error.WriteLine(HelpScreen.Usagestring());
                System.Environment.Exit(1);
            }

            if (ContainsHelp(args))
            {
                Console.WriteLine(HelpScreen.Usagestring());
                System.Environment.Exit(0);
            }

            if (args[0].Equals("/about"))
            {
                WriteAboutMessageToConsole();
                System.Environment.Exit(0);
            }

            if (args[0].Equals("minimize"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                TestCaseUtils.Minimize(TestCaseUtils.CollectFilesEndingWith(".cs", args2));
                System.Environment.Exit(0);
            }

            if (args[0].Equals("reduce"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                Collection <FileInfo> oldTests = TestCaseUtils.CollectFilesEndingWith(".cs", args2);
                Console.WriteLine("Number of original tests: " + oldTests.Count);
                Collection <FileInfo> newTests = TestCaseUtils.Reduce(oldTests);
                Console.WriteLine("Number of reduced tests: " + newTests.Count);
                Dictionary <TestCase.ExceptionDescription, Collection <FileInfo> > classifiedTests =
                    TestCaseUtils.ClassifyTestsByMessage(newTests);
                PrintStats(classifiedTests);
                StringBuilder b = new StringBuilder();
                foreach (string s in args)
                {
                    b.Append(" " + s);
                }
                string htmlFileName = "reduced" + Path.GetRandomFileName() + ".html";
                HtmlSummary.CreateIndexHtml(classifiedTests, htmlFileName, b.ToString());
                OpenExplorer(htmlFileName);
                System.Environment.Exit(0);
            }

            if (args[0].Equals("reproduce"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                TestCaseUtils.ReproduceBehavior(TestCaseUtils.CollectFilesEndingWith(".cs", args2));
                System.Environment.Exit(0);
            }

            if (args[0].StartsWith("stats:"))
            {
                string statsResultsFileName = args[0].Substring("stats:".Length);

                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);

                StatsManager.ComputeStats(statsResultsFileName,
                                          TestCaseUtils.CollectFilesEndingWith(".stats.txt", args2));
                System.Environment.Exit(0);
            }

            GenerateTests(args);
        }
示例#25
0
        /// <summary>
        /// Main randoop entrypoint.
        /// </summary>
        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("Randoop.NET: an API fuzzer for .Net. Version {0} (compiled {1}).",
                              Common.Enviroment.RandoopVersion, Common.Enviroment.RandoopCompileDate);

            if (args.Length == 0 || IsHelpCommand(args[0]))
            {
                Console.Error.WriteLine(HelpScreen.Usagestring());
                System.Environment.Exit(1);
            }

            if (ContainsHelp(args))
            {
                Console.WriteLine(HelpScreen.Usagestring());
                System.Environment.Exit(0);
            }

            if (args[0].Equals("/about"))
            {
                WriteAboutMessageToConsole();
                System.Environment.Exit(0);
            }

            //[email protected] adds "RandoopMappedCalls"
            if (args[0].Equals("methodtransformer"))
            {
                string   mapfile = args[1];
                string[] args2   = new string[args.Length - 2];
                Array.Copy(args, 2, args2, 0, args.Length - 2);
                Dictionary <string, string> methodmapper = new Dictionary <string, string>();

                try
                {
                    Instrument.ParseMapFile(mapfile, ref methodmapper); //parse a file that defines the mapping between target method and replacement method

                    foreach (string asm in args2)
                    {
                        int       mapcnt      = methodmapper.Count;
                        string [] origmethods = new string [mapcnt];
                        methodmapper.Keys.CopyTo(origmethods, 0);
                        foreach (string src in origmethods)
                        {
                            Instrument.MethodInstrument(asm, src, methodmapper[src]);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    System.Environment.Exit(-1);
                }

                System.Environment.Exit(0);
            }
            //[email protected] adds "RandoopMappedCalls"

            if (args[0].Equals("minimize"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                TestCaseUtils.Minimize(TestCaseUtils.CollectFilesEndingWith(".cs", args2));
                System.Environment.Exit(0);
            }

            if (args[0].Equals("reduce"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                Collection <FileInfo> oldTests = TestCaseUtils.CollectFilesEndingWith(".cs", args2);
                Console.WriteLine("Number of original tests: " + oldTests.Count);
                Collection <FileInfo> newTests = TestCaseUtils.Reduce(oldTests);
                Console.WriteLine("Number of reduced tests: " + newTests.Count);
                //Dictionary<TestCase.ExceptionDescription, Collection<FileInfo>> classifiedTests =
                //    TestCaseUtils.ClassifyTestsByMessage(newTests);
                //PrintStats(classifiedTests);
                //StringBuilder b = new StringBuilder();
                //foreach (string s in args) b.Append(" " + s);
                //string htmlFileName = "reduced" + Path.GetRandomFileName() + ".html";
                ////HtmlSummary.CreateIndexHtml(classifiedTests, htmlFileName, b.ToString());
                //HtmlSummary.CreateIndexHtml2(classifiedTests, htmlFileName, b.ToString());
                //OpenExplorer(htmlFileName);
                System.Environment.Exit(0);
            }

            if (args[0].Equals("reduce2")) //[email protected] adds for sequence-based reduction
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                Collection <FileInfo> oldTests = TestCaseUtils.CollectFilesEndingWith(".cs", args2);
                Console.WriteLine("Number of original tests: " + oldTests.Count);
                Collection <FileInfo> newTests = TestCaseUtils.Reduce2(oldTests);
                Console.WriteLine("Number of reduced tests: " + newTests.Count);
                System.Environment.Exit(0);
            }

            if (args[0].Equals("reproduce"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                TestCaseUtils.ReproduceBehavior(TestCaseUtils.CollectFilesEndingWith(".cs", args2));
                System.Environment.Exit(0);
            }

            if (args[0].StartsWith("stats:"))
            {
                string statsResultsFileName = args[0].Substring("stats:".Length);

                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);

                StatsManager.ComputeStats(statsResultsFileName,
                                          TestCaseUtils.CollectFilesEndingWith(".stats.txt", args2));
                System.Environment.Exit(0);
            }

            GenerateTests(args);
        }