mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-20 15:15:06 +00:00
Ported some of the python fuzz tests to C#
* Refactored the test runner to use attribute based test discovery * Ported value and vtable/object fuzzing tests from python to C#
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
@@ -24,39 +25,43 @@ namespace FlatBuffers.Test
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
var tests = new FlatBuffersExampleTests();
|
||||
try
|
||||
var testResults = new List<bool>();
|
||||
|
||||
var testClasses = Assembly.GetExecutingAssembly().GetExportedTypes()
|
||||
.Where(t => t.IsClass && t.GetCustomAttributes(typeof (FlatBuffersTestClassAttribute), false).Length > 0);
|
||||
|
||||
foreach (var testClass in testClasses)
|
||||
{
|
||||
tests.RunTests();
|
||||
var methods = testClass.GetMethods(BindingFlags.Public |
|
||||
BindingFlags.Instance)
|
||||
.Where(m => m.GetCustomAttributes(typeof(FlatBuffersTestMethodAttribute), false).Length > 0);
|
||||
|
||||
var inst = Activator.CreateInstance(testClass);
|
||||
|
||||
foreach (var method in methods)
|
||||
{
|
||||
try
|
||||
{
|
||||
method.Invoke(inst, new object[] { });
|
||||
testResults.Add(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("{0}: FAILED when invoking {1} with error {2}",
|
||||
testClass.Name ,method.Name, ex.GetBaseException());
|
||||
testResults.Add(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
var failedCount = testResults.Count(i => i == false);
|
||||
|
||||
Console.WriteLine("{0} tests run, {1} failed", testResults.Count, failedCount);
|
||||
|
||||
if (failedCount > 0)
|
||||
{
|
||||
Console.WriteLine("FlatBuffersExampleTests FAILED - {0}", ex.GetBaseException());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Run ByteBuffers Tests
|
||||
var testClass = new ByteBufferTests();
|
||||
|
||||
var methods = testClass.GetType().GetMethods(BindingFlags.Public |
|
||||
BindingFlags.Instance)
|
||||
.Where(m => m.Name.StartsWith("ByteBuffer_"));
|
||||
foreach (var method in methods)
|
||||
{
|
||||
try
|
||||
{
|
||||
method.Invoke(testClass, new object[] { });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("ByteBufferTests FAILED when invoking {0} with error {1}",
|
||||
method.Name, ex.GetBaseException());
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Console.WriteLine("FlatBuffers test: completed successfully");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user