Skip to content
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

Added round-trip tests #49

Closed
wants to merge 11 commits into from
Closed

Added round-trip tests #49

wants to merge 11 commits into from

Conversation

bgorven
Copy link
Contributor

@bgorven bgorven commented Mar 16, 2016

Continuing the discussion from https://github.com/bgorven/ez-vcard/commit/15813248e5b833cefdc6fb53892a529ccf42a938#commitcomment-16689669

Why did you make copies of the .vcf files from the "ezcard.io.text" package? Why not use the existing files?

The vcards look different after converting them to jcard and then back. I did it this way initially just to see if doing an exact string comparison of the converted files would work.

One benefit of having output files in the repo can be that if the output format changes at any time, you can see that in your repo. But it would be just as easy to create the files in a temp dir, which would keep the repo a lot tidier.

bgorven and others added 2 commits March 16, 2016 19:18
Instances of \r\n in the outlook vcards were being converted to \n on linux
@codecov-io
Copy link

Current coverage is 80.62%

Merging #49 into master will increase coverage by +0.18% as of 7850ee6

@@            master     #49   diff @@
======================================
  Files          210     210       
  Stmts         8366    8366       
  Branches      1498    1498       
  Methods                          
======================================
+ Hit           6730    6745    +15
  Partial        236     236       
+ Missed        1400    1385    -15

Review entire Coverage Diff as of 7850ee6

Powered by Codecov. Updated on successful CI builds.

@bgorven
Copy link
Contributor Author

bgorven commented Mar 16, 2016

To elaborate on the second commit message, the outlook samples weren't working because, for instance,

NOTE;ENCODING=QUOTED-PRINTABLE:This is the note field!!=0D=0ASecond line=0D=0A=0D=0AThird line is empty=0D=

in the original sample was being converted to

["note",{},"text","This is the note field!!\r\nSecond line\r\n\r\nThird line is empty\r\n"]

in the jcard, which was then being written as

NOTE:This is the note field!!\nSecond line\n\nThird line is empty\n

when it was converted back to vcard format on Linux.

This was causing the test to fail when it would read the second vcard in, convert it to jcard, and do an exact string comparison with the original jcard.

File[] dir = input.listFiles(new ExtensionFilter(".vcf"));
for (File vcf : dir) {
String file = vcf.getName().toString();
if (file.startsWith("John_Doe_EVOLUTION") || file.startsWith("John_Doe_IPHONE")
Copy link
Owner

Choose a reason for hiding this comment

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

Can you add a short comment here explaining why this "if" statement is here?

Is it here because of the problem with escaped characters in extended properties not being unescaped? I guess I will fix this issue once I merge your pull request. Then, I can remove this if statement.

@mangstadt
Copy link
Owner

Thank you for noticing the issue with the newlines. I understand why you need to make copies of the vCard samples now.

@Test
public void convert_from_jcard() throws Throwable {
File input = new File(JCardRoundTripTest.class.getResource("").toURI());
File[] dir = input.listFiles(new ExtensionFilter(".json"));
Copy link
Owner

Choose a reason for hiding this comment

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

You could refactor lines 82 and 83 into a reusable method: getFilesWithExtension(".json")

@bgorven bgorven changed the title Added round-trip tests to jcard and back Added round-trip tests Apr 23, 2016
Can now exclude test cases from specific checks, rather than excluding them from the entire test class.
@bgorven
Copy link
Contributor Author

bgorven commented Apr 24, 2016

I've refactored this to make it easier to add round-trip tests to other formats, and added tests to roundtrip from xcard to vcard v4.0 and from xcard to vcard v3.0 as proof of concept.

I've added a note next to each excluded test case; apart from the character encoding issues, there are a couple of things causing some of the tests to fail that aren't necessarily bugs in the library; the vcards are semantically identical but not textually identical, e.g. <parameters><type><text>JPEG... when encoded one way or <parameters><type><text>jpeg... when encoded another.

I've added a way to compare the deserialized objects using VCard.equals, which doesn't have the same issues, but for the tests that did fail it's not as easy to see why (compared to string comparisons, where you can doubleclick the failure message in Eclipse for a diff).

@bgorven
Copy link
Contributor Author

bgorven commented Apr 24, 2016

There were a couple of issues relating to xml serialization: the outlook-2003 file was serialized with an &#12; entity that is apparently not valid xml, as it causes a SAX exception when trying to read that xcard in, and if you enable indentation (change getTargetWriter to return new XCardWriter(sw, 2)), the formatting of some properties gets read back in as the property text. For instance:

    <x-phonetic-first-name>
      <unknown>Grregg</unknown>
    </x-phonetic-first-name>

after converting to vcard and back, becomes

    <x-phonetic-first-name>
      <unknown>\n      Grregg\n    </unknown>
    </x-phonetic-first-name>


private Filter(String extension, String... excludes) {
this.extension = "." + extension;
if (excludes != null) {
Copy link
Owner

Choose a reason for hiding this comment

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

This null check is not necessary. If no vararg parameters are passed in, then the "excludes" variable will be an empty array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks.

"evolution", "mac_address_book", // string escape issue
"iphone", "lotus_notes", // groups are reordered
"outlook-2007", // label got lost
"rfc6350", // tel uri got lost
Copy link
Owner

Choose a reason for hiding this comment

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

tel uri got lost

Only vCard version 4.0 (and xCard) supports tel URIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the comment for this exclusion to clarify that.

@Test
public void compare_vcard_3_to_xcard() throws Exception {
convertAllFromVCard(VCardVersion.V3_0, false, true,
"android", // <pref><integer>1</integer></pref> removed from the ÑÑÑÑÑÑÑÑÑÑÑÑ email
Copy link
Owner

Choose a reason for hiding this comment

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

<pref><integer>1</integer></pref> removed from the ÑÑÑÑÑÑÑÑÑÑÑÑ email

vCard versions 2.1 and 3.0 do not have a PREF parameter. Instead, they have a TYPE=PREF parameter. ez-vcard converts between the two.

@mangstadt
Copy link
Owner

Closing due to age.

Sorry this got neglected. I wasn't comfortable merging it due to the large number of complex changes it involved.

@mangstadt mangstadt closed this Jun 12, 2020
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.

3 participants