Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -804,13 +804,16 @@ public void ObsoletedOSPlatformAttributeUnneededSupport ()
generator.WriteType (iface, string.Empty, new GenerationInfo ("", "", "MyAssembly"));
generator.Context.ContextTypes.Pop ();

// These should use [Obsolete] because they have always been obsolete in all currently supported versions (21+)
// These should use [Obsolete] because they have always been obsolete in all currently supported versions (24+)
Assert.True (writer.ToString ().Contains ("[global::System.Obsolete (@\"This is a field deprecated since 0!\")]"), writer.ToString ());
Assert.True (writer.ToString ().Contains ("[global::System.Obsolete (@\"This is a constructor deprecated since empty string!\")]"), writer.ToString ());

// getCount/setCount were deprecated-since 22, which is below MINIMUM_API_LEVEL (24), so they
// should use [Obsolete] rather than [ObsoletedOSPlatform] since they have always been obsolete.
Assert.True (writer.ToString ().Contains ("[global::System.Obsolete (@\"deprecated\")]"), writer.ToString ());

// This should not have a message because the default "deprecated" message isn't useful
Assert.True (writer.ToString ().Contains ("[global::System.Runtime.Versioning.ObsoletedOSPlatform (\"android25.0\")]"), writer.ToString ());
Assert.True (writer.ToString ().Contains ("[global::System.Runtime.Versioning.ObsoletedOSPlatform (\"android22.0\")]"), writer.ToString ());

// This should use [Obsolete] because the 'deprecated-since' attribute could not be parsed
Assert.True (writer.ToString ().Contains ("[global::System.Obsolete (@\"This method has an invalid deprecated-since!\")]"), writer.ToString ());
Expand Down Expand Up @@ -1450,6 +1453,31 @@ public void SupportedOSPlatformConstFields ()
StringAssert.Contains ("[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain SupportedOSPlatform!");
}

[Test]
// MINIMUM_API_LEVEL is 24 (matches $(AndroidMinimumDotNetApiLevel) in Configuration.props), so
// there's no sense writing [SupportedOSPlatform] for an API available at or below that floor:
// it's available in every version we support. Only API levels above the floor need it.
[TestCase (22, false)]
[TestCase (23, false)]
[TestCase (24, false)]
[TestCase (25, true)]
public void SupportedOSPlatformOmittedAtOrBelowMinimumApiLevel (int apiLevel, bool expectAttribute)
{
var klass = SupportTypeBuilder.CreateClass ("java.code.MyClass", options);
klass.ApiAvailableSince = new AndroidSdkVersion (apiLevel);

generator.Context.ContextTypes.Push (klass);
generator.WriteType (klass, string.Empty, new GenerationInfo ("", "", "MyAssembly"));
generator.Context.ContextTypes.Pop ();

var attribute = $"[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android{apiLevel}.0\")]";

if (expectAttribute)
StringAssert.Contains (attribute, builder.ToString (), $"Should contain SupportedOSPlatform for android{apiLevel}!");
else
StringAssert.DoesNotContain (attribute, builder.ToString (), $"Should NOT contain SupportedOSPlatform for android{apiLevel}!");
}
Comment on lines +1456 to +1479

[Test]
public void UnsupportedOSPlatform ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace generator.SourceWriters
{
public static class SourceWriterExtensions
{
const int MINIMUM_API_LEVEL = 21;
// Must match $(AndroidMinimumDotNetApiLevel) in Configuration.props.
const int MINIMUM_API_LEVEL = 24;

public static void AddField (TypeWriter tw, GenBase type, Field field, CodeGenerationOptions opt)
{
Expand Down
Loading