Skip to content

Add Tests for System.Drawing.Common #22130

Closed

Description

@mellinoe

This issue tracks porting some set of tests from mono's test suite, covering the portions of System.Drawing that we support on .NET Core.

Mono's test cases are in this folder: https://github.com/mono/mono/tree/master/mcs/class/System.Drawing/Test

We most likely want to convert the most useful tests from all of the sections here, with the exception of System.Drawing.Design, which we aren't going to support right now on .NET Core (it is mainly related to designer / WinForms support).

Mono's tests use NUnit, so we will need to convert them to Xunit when copying them.

Additionally, I've identified that there will need to be some functional changes made to the tests themselves, as they do not pass against the .NET Framework implementation. We consider the .NET Framework implementation to be the compatibility baseline, so we should change the tests to accomodate it, rather than the other way around. The test failures seemed mainly related to very small, subtle differences in things like floating-point precision, color values, offsets, etc. We should do the following when we have both Windows and Unix implementations up and running:

  • Ensure that all tests have enough "leniency" to accomodate floating-point differences (and other minor inconsistencies) where unavoidable.
  • Ensure that all minor inconsistencies are acceptable or otherwise very difficult / problematic to fix.
  • Ensure that all minor inconsistencies are listed somewhere, so that we can mention it both in the tests, and in the user documentation.

@hughbe @qmfrederik @marek-safar


Current Status

Code coverage:
Note that there is a large amount of internal and debug-only code which distorts these numbers. When the coverage is generally high, we can clean out a lot of dead code and then get more accurate data.

Date Branch Coverage Line Coverage
6/26/2017 33% 25%
7/11/2017 49% 54%
7/17/2017 55% 60%
8/2/2017 58% 66%
8/25/2017 62% 71%
9/21/2017 64.6% 75.3%

Namespaces and coverage, as of 9/21/2017:

  • System.Drawing: 76.3%
  • System.Drawing.Drawing2D: 93.8%
  • System.Drawing.Imaging: 86.1%
  • System.Drawing.Printing: 62.8%
  • System.Drawing.Text: 96%

Activity

  1. norek commented on Jun 5, 2017

    @norek
    Contributor

    Hi I can grab some part of those tests for example System.Drawing.Printing, on start. Then when all will be fine i can port next part. What do you think?

  2. mellinoe commented on Jun 5, 2017

    @mellinoe
    ContributorAuthor

    @norek Splitting up the work sounds like a good idea to me. I've created separate items above for each of the folders in mono's test bed. I've put your name next to System.Drawing.Printing.

    Looking over the tests in that folder, I think they are fairly straightforward, with a couple of exceptions. I would ignore the following tests for now:

    • PrintingPermissionAttributeTest
    • PrintingPermissionTest

    We don't care about any of this permissions stuff in .NET Core, nor do we enforce it.

    • PrintingServicesUnixTest

    This one isn't going to work outside of Unix or the libgdiplus implemetation, so don't bother with it for now.

  3. norek commented on Jun 6, 2017

    @norek
    Contributor

    @mellinoe insln file is reference to test project but it is missing in source code. Did you forgot push it?

  4. mellinoe commented on Jun 6, 2017

    @mellinoe
    ContributorAuthor

    @norek Oops -- it was a mistake to include it in the solution file. I had a couple of tests written on my local machine, but they weren't worth merging.

  5. norek commented on Jun 8, 2017

    @norek
    Contributor

    I have little question about moving tests from Nunit to Xunit. In mono tests, very often Assert is used with description,prabobly beacuse there are more than one assert in test and description provide better debug (i think). What should I do with this case. Xunit doesn't provide description for Assert.Equal.
    Should I remove this description?

  6. mellinoe commented on Jun 8, 2017

    @mellinoe
    ContributorAuthor

    Yes -- remove the description. If really necessary, just provide the message in a comment next to the assertion.

  7. hughbe commented on Jun 9, 2017

    @hughbe
    Contributor

    @norek a test project has been merged so feel free to get started. Mind if I ask what you're working on so we avoid conflicts?

    Note that I'm gonna put some effort into beautifying and modernising these tests using xunit's features like parameter names in exceptions and theory/member data

    Keep me up to date :)

  8. norek commented on Jun 9, 2017

    @norek
    Contributor

    @hughbe Thanks! Im working on System.Drawing.Printing namespace. In description of this issue You can see list of assigned items.

  9. norek commented on Jun 12, 2017

    @norek
    Contributor

    How about testing PageSettings class? In mono's test i found comment:

    // Check for installed printers, because we need
    // to have at least one to test
    if (PrinterSettings.InstalledPrinters.Count == 0)
    

    I dont know what to do with this.

  10. mellinoe commented on Jun 12, 2017

    @mellinoe
    ContributorAuthor

    @norek We certainly don't have any printers attached to the machines that run our CI tests, if that is what you are alluding to. You can just keep that check in the test code. Are you asking about something else?

  11. mellinoe commented on Jun 12, 2017

    @mellinoe
    ContributorAuthor

    @hughbe Could you post something here as you start writing/porting tests for individual components? It would be good to have a list of "in-progress" work so that we know what's being covered.

  12. norek commented on Jun 13, 2017

    @norek
    Contributor

    @mellinoe yup, this is what I meant. Thanks

  13. norek commented on Jun 13, 2017

    @norek
    Contributor

    @hughbe Can you tell me what is this?
    public static IEnumerable<(int, Color)> SystemColors_TestData() in ColorTranslatorTests.cs
    build is passing, but VS highlight this syntax. I see this syntax for first time ;o

    second: In my machine after pull your changes, I have failing your tests for example:
    do you have idea why? clean, build on root completed.

    <failure exception-type="Xunit.Sdk.ThrowsException">
    <message><![CDATA[Assert.Throws() Failure\r\nExpected: typeof(System.ArgumentException)\r\nActual:   typeof(System.Exception): 1,256,3 is not a valid value for Int32.]]></message>
    <stack-trace><![CDATA[at System.Drawing.ColorConverterCommon.IntFromString(String text, CultureInfo culture) in C:\Projects\corefx\src\Common\src\System\Drawing\ColorConverterCommon.cs:line 131
    at System.Drawing.ColorConverterCommon.ConvertFromString(String strValue, CultureInfo culture) in C:\Projects\corefx\src\Common\src\System\Drawing\ColorConverterCommon.cs:line 64
    at System.Drawing.ColorTranslator.FromHtml(String htmlColor) in C:\Projects\corefx\src\System.Drawing.Common\src\System\Drawing\ColorTranslator.cs:line 271
    at System.Drawing.Tests.ColorTranslatorTests.<>c__DisplayClass10_0.<FromHtml_Invalid_Throws>b__0() in C:\Projects\corefx\src\System.Drawing.Common\tests\ColorTranslatorTests.cs:line 222]]></stack-trace>
    </failure>
    </test>```
    
  14. mellinoe commented on Jun 13, 2017

    @mellinoe
    ContributorAuthor

    Those are ValueTuples, a new C#7 feature. You will need VS 2017 to edit that, I believe...

  15. mellinoe commented on Jun 13, 2017

    @mellinoe
    ContributorAuthor

    @norek As for the test failure: what language settings does your computer use? We might be assuming that English is used, and number parsing could fail with other culture settings.

  16. 90 remaining items

  17. KostaVlev commented on Aug 2, 2017

    @KostaVlev
    Contributor

    I moved on System.Drawing.Printing.

  18. hughbe commented on Aug 2, 2017

    @hughbe
    Contributor

    <3 good stuff

  19. mellinoe commented on Aug 25, 2017

    @mellinoe
    ContributorAuthor

    Code coverage numbers are looking really good to me (updated at the top), considering there are a few large files full of dead code (or code that doesn't really need to be tested). Thanks for all of the contributions, everyone!

  20. norek commented on Sep 19, 2017

    @norek
    Contributor

    How nice, a lot of work was made since my "vacation". I just bought new computer and i'm ready to go!

  21. mellinoe commented on Sep 21, 2017

    @mellinoe
    ContributorAuthor

    Some more steady progress was made in the past month. I think @qmfrederik's current effort will give us enough coverage to fill in the remaining gaps and let us close this issue out.

  22. transferred this issue fromdotnet/corefxon Jan 31, 2020
  23. added this to the Future milestone on Jan 31, 2020
  24. ghost added
    backlog-cleanup-candidate
    on Feb 10, 2023
  25. ghost closed this as completedon Feb 24, 2023
  26. ghost locked as resolved and limited conversation to collaborators on Mar 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Drawingbacklog-cleanup-candidatehelp wantedincrease-code-coverageno-recent-activitytest-enhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions