...
1/*
2 * Copyright 2014 Google Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17using System;
18using System.Collections.Generic;
19using System.Linq;
20using System.Reflection;
21
22namespace Google.FlatBuffers.Test
23{
24 static class Program
25 {
26 public static int Main(string[] args)
27 {
28 var testResults = new List<bool>();
29
30 var testClasses = Assembly.GetExecutingAssembly().GetExportedTypes()
31 .Where(t => t.IsClass && t.GetCustomAttributes(typeof (FlatBuffersTestClassAttribute), false).Length > 0);
32
33 foreach (var testClass in testClasses)
34 {
35 var methods = testClass.GetMethods(BindingFlags.Public |
36 BindingFlags.Instance)
37 .Where(m => m.GetCustomAttributes(typeof(FlatBuffersTestMethodAttribute), false).Length > 0);
38
39 var inst = Activator.CreateInstance(testClass);
40
41 foreach (var method in methods)
42 {
43 try
44 {
45 method.Invoke(inst, new object[] { });
46 testResults.Add(true);
47 }
48 catch (Exception ex)
49 {
50 Console.WriteLine("{0}: FAILED when invoking {1} with error {2}",
51 testClass.Name ,method.Name, ex.GetBaseException());
52 testResults.Add(false);
53 }
54 }
55 }
56
57 var failedCount = testResults.Count(i => i == false);
58
59 Console.WriteLine("{0} tests run, {1} failed", testResults.Count, failedCount);
60
61 if (failedCount > 0)
62 {
63 return -1;
64 }
65 return 0;
66 }
67 }
68}
View as plain text