Fixes crash in tests (#20)
Fixes crash in tests (#20)

* Refactor: using field init shorthand in Notification::from_property_changed

* Refactor: As the std::fmt docs specify, to convert a single value to a string, use the .to_string() method

* Gave test data the proper retain count

In the test data for notification_from_property_changed, the CFString that was wrapping the CFStringRef for the .propertyName was releasing the CFStringRef at the end of notification_raw's instantiation (to a retain count of 0), so the CFStringRef that was returned was invalid. Instead, the CFString needs to live until after the call Notification::from has returned so its CFStringRef can be valid for the whole call.

* Fixing SIGILL in tests caused by over-release of CFStringRef

Because the MIDINotification struct is not owned by the callback function (it's just a pointer to the data), the CFStringRef that it contains comes into the callback with a reference count of 1. Therefore we should follow CoreFoundation's "The Get Rule" and increase the reference count before it is decreased again when the CFString is dropped after being converted to a Rust String. Otherwise the retain count goes below 0 as the test function ends, causing a panic.

* Fixed same error with test data retain count in different test

This CFString was also released immediately upon creation, though it didn't panic because the CFString was never actually used in the associated function being tested in the error case.
chris-zen/coremidi