Skip to content

Refactoring & fix a bug & add tests to increase code coverage. #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 17, 2020

Conversation

ledyba-z
Copy link
Collaborator

Hi.

I separate SDWebImageAVIFCoder.m to 3 files. And also, I write some new tests to increase code coverage. After that, I found a crash bug about ICC profile and fix it.

Could you take a look?

@ledyba-z ledyba-z requested a review from dreampiggy March 15, 2020 07:13
@ledyba-z ledyba-z self-assigned this Mar 15, 2020
@codecov
Copy link

codecov bot commented Mar 15, 2020

Codecov Report

Merging #18 into master will increase coverage by 18.87%.
The diff coverage is 86.74%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #18       +/-   ##
===========================================
+ Coverage   67.13%   86.01%   +18.87%     
===========================================
  Files           4        6        +2     
  Lines        1494     1494               
===========================================
+ Hits         1003     1285      +282     
+ Misses        491      209      -282     
Impacted Files Coverage Δ
SDWebImageAVIFCoder/Classes/ColorSpace.m 84.97% <84.97%> (ø)
SDWebImageAVIFCoder/Classes/Conversion.m 87.62% <87.62%> (ø)
SDWebImageAVIFCoder/Classes/SDImageAVIFCoder.m 81.75% <100.00%> (+14.85%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 501b702...27372a5. Read the comment docs.

@dreampiggy
Copy link
Collaborator

dreampiggy commented Mar 15, 2020

Wait me for review...

Does these method should be public APIs ? If not, you should move them into a private folder (for example, make folder strcuture looks SDWebImage/Classes/Private and update it for 3 different Packages:

  • CocoaPods:

Modify Podspec and use s.private_header_files = 'SDWebImageAVIFCoder/Classes/Private/*.{h,m}'

  • Carthage:

Update the Xcode's File Attribute and mark the ColorSpace.h into Project or Private.

  • SwiftPM:

Update the Package.swift to only expose the publicHeadersPath arg point to the SDWebImageAVIFCoder/Classes/Public/*.

@dreampiggy
Copy link
Collaborator

dreampiggy commented Mar 15, 2020

Or I can do this myself after merging, since I'm more familiar with all these suck Package Manager :)

@ledyba-z
Copy link
Collaborator Author

Yeah, ColorSpace.h and Conversion.h must be private.

Or I can do this myself after merging, since I'm more familiar with all these suck Package Manager :)

Haha, thanks! I tried to do it myself... Could you check it?

@ledyba-z
Copy link
Collaborator Author

ledyba-z commented Mar 15, 2020

I think I can make ColorSpace.h and Conversion.h private, but tests became to fail because of it...

How should I do?

@dreampiggy
Copy link
Collaborator

dreampiggy commented Mar 16, 2020

Because you access the private header outside framework. In the test case:

image

You should use some tricks on the Test Case target, update the HEADER_SEARCH_PATH in SDWebImageAVIFCoder_Tests target (Open that Example/SDWebImageAVIFCoder.xcworkspace and choose the Test Target):

HEADER_SEARCH_PATH = $(inherited) ${PODS_ROOT}/Headers/Private

I can merge it and check each Package Manager and Project Settings again, to avoid some extra issues.

#import "avif/avif.h"
#endif

CGColorSpaceRef CreateColorSpaceMono(avifNclxColourPrimaries const colorPrimaries, avifNclxTransferCharacteristics const transferCharacteristics);
Copy link
Collaborator

@dreampiggy dreampiggy Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These C function share the global symbol, which may cause conflict. Can we add some prefix here, like AVIFCreateColorSpaceMono ? Or use SDCreateAVIFColorSpaceMono this sounds better ?

And the visibility should be marked as __attribute__((visibility("hidden"))).

The same applies to others C function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I renamed functions and added __attribute__((visibility("hidden"))), _Nonnull , _Nullable.

Copy link
Collaborator

@dreampiggy dreampiggy Mar 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ledyba-z This final function name now is SDCreateAVIFCreateColorSpaceRGB, note there are two Create 🤣

Can this be SDCreateAVIFColorSpaceRGB ? Or like SDCreateColorSpaceRGBAVIF ?

If we follows the Core Foundation Naming, the Create words is important because this means the caller should call release or free the the function call result.

Actually I prefer the prefix one SDCreateAVIFXXXX but not the suffix one SDCreateXXXXAVIF, because it's more clear for the usage, like Apple's C funtion naming (they don't usually use suffix). But since this is a private API, actually it's OK...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! 😆
I missed two "Create" (it might be too long function names for me!)

I renamed the functions.

I see... thanks. > Core Foundation Naming

@ledyba-z
Copy link
Collaborator Author

Thanks to approve!

I will merge after CI passed.

@ledyba-z ledyba-z merged commit 08ca46f into SDWebImage:master Mar 17, 2020
@ledyba-z ledyba-z deleted the feature/refactor branch March 17, 2020 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants