1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
using System;
using Mono.Cecil;
using NUnit.Framework;
using Mono.Documentation.Updater.Formatters.CppFormatters;
using Mono_DocTest_Generic;
using Cpp=Mono_DocTest_Generic;
using Mono_DocTest;
namespace mdoc.Test
{
public class CppFullFormatterTests: BasicFormatterTests<CppFullMemberFormatter>
{
private static readonly CppFullMemberFormatter cppFullMemberFormatter = new CppFullMemberFormatter();
protected override CppFullMemberFormatter formatter => cppFullMemberFormatter;
private const string CSharpTestLib = "../../../../external/Test/CSharpExample.dll";
[Test]
[Category("Methods")]
public void MethodSignature_Bar() =>
TestMethodSignature(typeof(Cpp.Extensions), @"public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
static void Bar(IFoo<T> ^ self, System::String ^ s);",
nameof(Cpp.Extensions.Bar));
[Test]
[Category("Methods")]
public void MethodSignature_ForEach() =>
TestMethodSignature(typeof(Cpp.Extensions), @"public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
static void ForEach(System::Collections::Generic::IEnumerable<T> ^ self, Action<T> ^ a);",
nameof(Cpp.Extensions.ForEach));
[Test]
[Category("Methods")]
public void MethodSignature_ToEnumerable() =>
TestMethodSignature(typeof(Cpp.Extensions), @"public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
static System::Collections::Generic::IEnumerable<T> ^ ToEnumerable(T self);",
nameof(Cpp.Extensions.ToEnumerable));
[Test]
[Category("Methods")]
public void MethodSignature_ToDouble() =>
TestMethodSignature(typeof(Cpp.Extensions), @"public:
generic <typename T>
where T : IFoo<T>[System::Runtime::CompilerServices::Extension]
static double ToDouble(T val);",
nameof(Cpp.Extensions.ToDouble));
[Test]
[Category("Methods")]
public void MethodSignature_BaseMethod() =>
TestMethodSignature(typeof(GenericBase<>), @"public:
generic <typename S>
U BaseMethod(S genericParameter);",
nameof(GenericBase<int>.BaseMethod));
[Test]
[Category("Methods")]
public void MethodSignature_Method() =>
TestMethodSignature(typeof(IFoo<>), @"public:
generic <typename U>
T Method(T t, U u);",
nameof(IFoo<int>.Method));
[Test]
[Category("Fields")]
public void FieldSignature_ConstInt() =>
TestFieldSignature(typeof(GenericBase<>),
"public: const int ConstInt;",
nameof(GenericBase<int>.ConstInt));
[Test]
[Category("Fields")]
public void FieldSignature_ConstLong() =>
TestFieldSignature(typeof(GenericBase<>),
"public: const long ConstLong;",
nameof(GenericBase<int>.ConstLong));
[Test]
[Category("Fields")]
public void FieldSignature_ConstDecimal() =>
TestFieldSignature(typeof(GenericBase<>),
"public: const System::Decimal ConstDecimal;",
nameof(GenericBase<int>.ConstDecimal));
[Test]
[Category("Fields")]
public void FieldSignature_ConstShort() =>
TestFieldSignature(typeof(GenericBase<>),
"public: const short ConstShort;",
nameof(GenericBase<int>.ConstShort));
[Test]
[Category("Fields")]
public void FieldSignature_ConstUint16() =>
TestFieldSignature(typeof(GenericBase<>),
"public: const System::UInt16 ConstUint16;",
nameof(GenericBase<int>.ConstUint16));
[Test]
[Category("Fields")]
public void FieldSignature_ConstUint32() =>
TestFieldSignature(typeof(GenericBase<>),
"public: const System::UInt32 ConstUint32;",
nameof(GenericBase<int>.ConstUint32));
[Test]
[Category("Fields")]
public void FieldSignature_ConstUint64() =>
TestFieldSignature(typeof(GenericBase<>),
"public: const System::UInt64 ConstUint64;",
nameof(GenericBase<int>.ConstUint64));
[Test]
[Category("Fields")]
public void FieldSignature_ConstFloat() =>
TestFieldSignature(typeof(GenericBase<>),
"public: const float ConstFloat;",
nameof(GenericBase<int>.ConstFloat));
[Test]
[Category("Fields")]
public void FieldSignature_ConstBool() =>
TestFieldSignature(typeof(GenericBase<>),
"public: const bool ConstBool;",
nameof(GenericBase<int>.ConstBool));
[Test]
[Category("Fields")]
public void FieldSignature_ConstChar() =>
TestFieldSignature(typeof(GenericBase<>),
"public: const char ConstChar;",
nameof(GenericBase<int>.ConstChar));
[Test]
[Category("Fields")]
public void FieldSignature_ConstObject() =>
TestFieldSignature(typeof(GenericBase<>),
"public: const System::Object ^ ConstObject;",
nameof(GenericBase<int>.ConstObject));
[Test]
[Category("Fields")]
public void FieldSignature_ConstString() =>
TestFieldSignature(typeof(GenericBase<>),
"public: const System::String ^ ConstString;",
nameof(GenericBase<int>.ConstString));
[Test]
[Category("Methods")]
public void MethodSignature_AsReadOnly() =>
TestMethodSignature(typeof(Array1), @"public:
generic <typename T>
static System::Collections::ObjectModel::ReadOnlyCollection<T> ^ AsReadOnly(cli::array <T> ^ array);",
nameof(Array1.AsReadOnly));
[Test]
[Category("Methods")]
public void MethodSignature_UseT() =>
TestMethodSignature(typeof(MyList<>.Helper<,>), @"public:
void UseT(T a, U b, V c);",
nameof(MyList<int>.Helper<int,int>.UseT));
[Test]
[Category("Methods")]
public void MethodSignature_s() =>
TestMethodSignature(typeof(Widget), @"public:
Func<System::String ^, System::Object ^> ^ Dynamic2(Func<System::String ^, System::Object ^> ^ value);",
nameof(Widget.Dynamic2));
[Test]
[Category("Methods")]
public void MethodSignature_M2() =>
TestMethodSignature(typeof(Widget), @"public:
void M2(cli::array <short> ^ x1, cli::array <int, 2> ^ x2, cli::array <cli::array <long> ^> ^ x3);",
nameof(Widget.M2));
[Test]
[Category("Methods")]
public void MethodSignature_PointersOnHat_JaggedArray_M5() =>
TestMethodSignature(typeof(Widget), @"protected:
void M5(void* pv, cli::array <cli::array <double, 2> ^> ^* pd);",
"M5");
[Test]
[Category("Methods")]
public void MethodSignature_PointersOnHat_ReferenceType_M55() =>
TestMethodSignature(typeof(Widget), @"protected:
void M55(void* pv, System::String ^* pd);",
"M55");
[Test]
[Category("Methods")]
public void MethodSignature_GenericRefParams_RefMethod() =>
TestMethodSignature(typeof(MyList<>), @"public:
generic <typename U>
void RefMethod(T % t, U % u);",
nameof(MyList<int>.RefMethod));
[Test]
[Category("Methods")]
public void MethodSignature_RefParams_M1() =>
TestMethodSignature(typeof(Widget), @"public:
void M1(long c, [Runtime::InteropServices::Out] float % f, Mono_DocTest::DocValueType % v);",
nameof(Widget.M1));
[Test]
[Category("Methods")]
public void MethodSignature_RefParamsWithHat_RefMethod() =>
TestMethodSignature(typeof(Array1), @"public:
generic <typename T>
static void Resize(cli::array <T> ^ % array, int newSize);",
nameof(Array1.Resize));
[Test]
[Category("Methods")]
public void MethodSignature_Reset() =>
TestMethodSignature(typeof(MyList1<,>), @"public:
virtual void Reset();",
nameof(MyList1<int,int>.Reset));
[Test]
[Category("Methods")]
public void MethodSignature_GetEnumerator1() =>
TestMethodSignature(typeof(MyList<>), @"public:
virtual System::Collections::IEnumerator ^ GetEnumerator1() = System::Collections::IEnumerable::GetEnumerator;",
nameof(MyList<int>.GetEnumerator1));
[Test]
[Category("Methods")]
public void MethodSignature_GetEnumeratorIEnumerable() =>
TestMethodSignature(typeof(MyList1<,>), @"public:
virtual System::Collections::IEnumerator ^ GetEnumerator1() = System::Collections::IEnumerable::GetEnumerator;",
nameof(MyList1<int,int>.GetEnumerator1));
[Test]
[Category("Methods")]
public void MethodSignature_GetEnumeratorGenericIEnumerable()
{
TestMethodSignature(
typeof(MyList1<,>), @"public:
virtual System::Collections::Generic::IEnumerator<A> ^ GetEnumerator() = System::Collections::Generic::IEnumerable<A>::GetEnumerator;",
nameof(MyList1<int, int>.GetEnumerator));
}
[Test]
[Category("Methods")]
public void MethodSignature_opAddition() =>
TestMethodSignature(typeof(Widget), @"public:
static Mono_DocTest::Widget ^ operator +(Mono_DocTest::Widget ^ x1, Mono_DocTest::Widget ^ x2);",
"op_Addition");
[Test]
[Category("Methods")]
[Category("NoSupport")]
public void MethodSignature_NoSupport_DefaultValue() =>
TestMethodSignature(CSharpTestLib, "Mono.DocTest.Widget", "Default",
null);
[Test]
[Category("NoSupport")]
public void NoSupport_Exception_NestedClassWithSameName()
{
TestTypeSignature(CSharpTestLib, "Mono.DocTest.Widget/NestedClass", null);
}
[Test]
[Category("Methods")]
public void MethodSignature_opExplicit() =>
TestMethodSignature(typeof(Widget), @"public:
static explicit operator int(Mono_DocTest::Widget ^ x);",
"op_Explicit");
[Test]
[Category("Methods")]
public void MethodSignature_opImplicit() =>
TestMethodSignature(typeof(Widget), @"public:
static operator long(Mono_DocTest::Widget ^ x);",
"op_Implicit");
[Test]
[Category("Methods")]
public void MethodSignature_constructor()
{
TestMethodSignature(typeof(Widget), @"public:
Widget(Converter<System::String ^, System::String ^> ^ c);",
".ctor");
}
[Test]
[Category("Methods")]
public void MethodSignature_ParamsKeyword_M6()
{
TestMethodSignature(typeof(Widget), @"protected:
void M6(int i, ... cli::array <System::Object ^> ^ args);",
"M6");
}
protected override TypeDefinition GetType(Type type)
{
var moduleName = type.Module.FullyQualifiedName;
var tref = GetType(moduleName, type.FullName.Replace("+", "/"));
return tref;
}
}
}
|