diff options
| author | Tomáš Znamenáček | 2014-08-07 10:47:34 +0200 |
|---|---|---|
| committer | Tomáš Znamenáček | 2015-01-07 15:42:21 +0100 |
| commit | 942bbe849ed245d8b2e9afcb0a61d66b23beaef9 (patch) | |
| tree | 2cc9e066d84355099d2334bceac6fa1fb7f5d1b8 /Framework/MASDictionaryTransformerTests.m | |
| parent | 756601488fe195b0b14a8ac9c3c418140d5845f0 (diff) | |
| download | MASShortcut-942bbe849ed245d8b2e9afcb0a61d66b23beaef9.tar.bz2 | |
Added a custom transformer to store shortcuts as dictionaries.
The MASDictionaryTransformer class is used to save shortcuts to
user defaults (and load them back) using a simple dictionary. The
value stored in the user defaults looks like this:
$ defaults read com.shpakovski.mac.Demo
{
MASDemoShortcut = {
keyCode = 15;
modifierFlags = 1048576;
};
…
}
This storage format has got the distinct advantage of being compatible
with the format used by Shortcut Recorder. In order to use it, you
have to set proper binding options for MASShortcutBinder and the
recorder control (MASShortcutView).
Diffstat (limited to 'Framework/MASDictionaryTransformerTests.m')
| -rw-r--r-- | Framework/MASDictionaryTransformerTests.m | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Framework/MASDictionaryTransformerTests.m b/Framework/MASDictionaryTransformerTests.m new file mode 100644 index 0000000..78dfa25 --- /dev/null +++ b/Framework/MASDictionaryTransformerTests.m @@ -0,0 +1,25 @@ +#import "Shortcut.h" + +@interface MASDictionaryTransformerTests : XCTestCase +@end + +@implementation MASDictionaryTransformerTests + +- (void) testErrorHandling +{ + MASDictionaryTransformer *transformer = [MASDictionaryTransformer new]; + XCTAssertNil([transformer transformedValue:nil], + @"Decoding a shortcut from a nil dictionary returns nil."); + XCTAssertNil([transformer transformedValue:(id)@"foo"], + @"Decoding a shortcut from a invalid-type dictionary returns nil."); + XCTAssertNil([transformer transformedValue:@{}], + @"Decoding a shortcut from an empty dictionary returns nil."); + XCTAssertNil([transformer transformedValue:@{@"keyCode":@"foo"}], + @"Decoding a shortcut from a wrong-typed dictionary returns nil."); + XCTAssertNil([transformer transformedValue:@{@"keyCode":@1}], + @"Decoding a shortcut from an incomplete dictionary returns nil."); + XCTAssertNil([transformer transformedValue:@{@"modifierFlags":@1}], + @"Decoding a shortcut from an incomplete dictionary returns nil."); +} + +@end |
