Skip to content

Commit

Permalink
Fix api surface test to not crash on overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Feb 15, 2024
1 parent c46e7b0 commit e6304e7
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 25 deletions.
64 changes: 39 additions & 25 deletions ValveKeyValue/ValveKeyValue.Test/ApiSurfaceTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,41 +142,55 @@ static bool IsHidingMember(MethodInfo method)
return false;
}

var baseMethod = baseType.GetMethod(method.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (baseMethod == null)
{
return false;
}
var baseMethods = baseType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

if (baseMethod.DeclaringType == method.DeclaringType)
foreach (var baseMethod in baseMethods)
{
return false;
}
if (baseMethod.Name != method.Name)
{
continue;
}

var methodDefinition = method.GetBaseDefinition();
var baseMethodDefinition = baseMethod.GetBaseDefinition();
if (baseMethod.DeclaringType == method.DeclaringType)
{
continue;
}

if (methodDefinition.DeclaringType == baseMethodDefinition.DeclaringType)
{
return false;
}
var methodDefinition = method.GetBaseDefinition();
var baseMethodDefinition = baseMethod.GetBaseDefinition();

var methodParameters = method.GetParameters();
var baseMethodParameters = baseMethod.GetParameters();
if (methodParameters.Length != baseMethodParameters.Length)
{
return false;
}
if (methodDefinition.DeclaringType == baseMethodDefinition.DeclaringType)
{
continue;
}

for (int i = 0; i < methodParameters.Length; i++)
{
if (methodParameters[i].ParameterType != baseMethodParameters[i].ParameterType)
var methodParameters = method.GetParameters();
var baseMethodParameters = baseMethod.GetParameters();
if (methodParameters.Length != baseMethodParameters.Length)
{
return false;
continue;
}

var hasMatchingParameters = true;

for (int i = 0; i < methodParameters.Length; i++)
{
if (methodParameters[i].ParameterType != baseMethodParameters[i].ParameterType)
{
hasMatchingParameters = false;
break;
}
}

if (!hasMatchingParameters)
{
continue;
}

return true;
}

return true;
return false;
}

static string GetTypeAsString(Type type)
Expand Down
73 changes: 73 additions & 0 deletions ValveKeyValue/ValveKeyValue.Test/Test Data/apisurface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,79 @@ public class ValveKeyValue.KeyValueException
public string ToString();
}

public class ValveKeyValue.KVArrayValue
{
public void Add(ValveKeyValue.KVValue value);
public void AddRange(System.Collections.Generic.IEnumerable`1[[ValveKeyValue.KVValue]] values);
public void Clear();
public bool Contains(ValveKeyValue.KVValue item);
public void CopyTo(ValveKeyValue.KVValue[] array, int arrayIndex);
public bool Equals(object obj);
protected void Finalize();
public int get_Count();
public bool get_IsReadOnly();
public ValveKeyValue.KVValue get_Item(int key);
public ValveKeyValue.KVValue get_Item(string key);
public ValveKeyValue.KVValueType get_ValueType();
public System.Collections.Generic.IEnumerator`1[[ValveKeyValue.KVValue]] GetEnumerator();
public int GetHashCode();
public Type GetType();
public TypeCode GetTypeCode();
public int IndexOf(ValveKeyValue.KVValue item);
public void Insert(int index, ValveKeyValue.KVValue item);
protected object MemberwiseClone();
public bool Remove(ValveKeyValue.KVValue item);
public void RemoveAt(int index);
public void set_Item(int key, ValveKeyValue.KVValue value);
public bool ToBoolean(IFormatProvider provider);
public byte ToByte(IFormatProvider provider);
public char ToChar(IFormatProvider provider);
public DateTime ToDateTime(IFormatProvider provider);
public decimal ToDecimal(IFormatProvider provider);
public double ToDouble(IFormatProvider provider);
public short ToInt16(IFormatProvider provider);
public int ToInt32(IFormatProvider provider);
public long ToInt64(IFormatProvider provider);
public sbyte ToSByte(IFormatProvider provider);
public float ToSingle(IFormatProvider provider);
public string ToString();
public string ToString(IFormatProvider provider);
public object ToType(Type conversionType, IFormatProvider provider);
public ushort ToUInt16(IFormatProvider provider);
public uint ToUInt32(IFormatProvider provider);
public ulong ToUInt64(IFormatProvider provider);
}

public class ValveKeyValue.KVBinaryBlob
{
public bool Equals(object obj);
protected void Finalize();
public Memory`1[[byte]] get_Bytes();
public ValveKeyValue.KVValue get_Item(string key);
public ValveKeyValue.KVValueType get_ValueType();
public int GetHashCode();
public Type GetType();
public TypeCode GetTypeCode();
protected object MemberwiseClone();
public bool ToBoolean(IFormatProvider provider);
public byte ToByte(IFormatProvider provider);
public char ToChar(IFormatProvider provider);
public DateTime ToDateTime(IFormatProvider provider);
public decimal ToDecimal(IFormatProvider provider);
public double ToDouble(IFormatProvider provider);
public short ToInt16(IFormatProvider provider);
public int ToInt32(IFormatProvider provider);
public long ToInt64(IFormatProvider provider);
public sbyte ToSByte(IFormatProvider provider);
public float ToSingle(IFormatProvider provider);
public string ToString();
public string ToString(IFormatProvider provider);
public object ToType(Type conversionType, IFormatProvider provider);
public ushort ToUInt16(IFormatProvider provider);
public uint ToUInt32(IFormatProvider provider);
public ulong ToUInt64(IFormatProvider provider);
}

public sealed class ValveKeyValue.KVIgnoreAttribute
{
public bool Equals(object obj);
Expand Down

0 comments on commit e6304e7

Please sign in to comment.