File: encoding.m

package info (click to toggle)
gnustep-gui 0.32.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,348 kB
  • sloc: objc: 178,763; ansic: 24,089; cpp: 664; yacc: 464; sh: 90; makefile: 72
file content (87 lines) | stat: -rw-r--r-- 2,127 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#import "ObjectTesting.h"

#import <Foundation/NSData.h>
#import <Foundation/NSValue.h>
#import <AppKit/NSApplication.h>
#import <AppKit/NSEvent.h>
#import <AppKit/NSButtonCell.h>

int main()
{
  START_SET("NSButtonCell encoding tests")

  NS_DURING
    {
      [NSApplication sharedApplication];
    }
  NS_HANDLER
    {
      if ([[localException name]
	isEqualToString: NSInternalInconsistencyException ])
	{
	  SKIP("It looks like GNUstep backend is not yet installed")
	}
    }
  NS_ENDHANDLER

  NSString	*mask = @"NSButtonFlags2";
  NSButtonCell	*item = [[NSButtonCell alloc] init];

  item.keyEquivalent = @"A";
  item.keyEquivalentModifierMask = NSShiftKeyMask;

  NSMutableData		*data = [NSMutableData data];
  NSKeyedArchiver	*archiver;

  archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: data];

  [archiver encodeRootObject: item];
  [archiver finishEncoding];

  NSError	*error;
  NSDictionary	*archive;

  archive = [NSPropertyListSerialization
    propertyListWithData: data
    options: NSPropertyListImmutable
    format: nil
    error: &error];

  NSArray	*topLevelObjects = [archive objectForKey: @"$objects"];
  NSEnumerator	*enumerator = [topLevelObjects objectEnumerator];
  NSDictionary	*dict;
  id		element;

  while ((element = [enumerator nextObject]) != nil)
    {
      if ([element isKindOfClass: [NSDictionary class]])
        {
          dict = (NSDictionary*)element;
          
          if ([[dict allKeys] containsObject: mask])
            {
              break;
            }
          else
            {
              dict = nil;
            }
	}
    }

  PASS(dict != nil, "Found a dict with a NSButtonFlags2 entry");

  NSNumber	*encodedKeyMask = [dict valueForKey: mask];
  int		expect = (NSShiftKeyMask << 8);
  int		modMask = (NSEventModifierFlagDeviceIndependentFlagsMask << 8);
  int		found = [encodedKeyMask intValue] & modMask;

  PASS(encodedKeyMask != nil, "Retrieved the NSButtonFlags2 value");
  PASS(found == expect,
    "Encoded key mask 0x%x matches expected key mask 0x%x",
    found, expect);
  
  END_SET("NSButtonCell encoding tests")

  return 0;
}