File: testcopy.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 (40 lines) | stat: -rw-r--r-- 1,665 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
#import "ObjectTesting.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <AppKit/NSApplication.h>
#import <AppKit/NSBitmapImageRep.h>
#import <AppKit/NSGraphics.h>

int main()
{
  NSAutoreleasePool *arp = [NSAutoreleasePool new];
  NSBitmapImageRep *origBitmap, *copy1Bitmap, *copy2Bitmap;

  origBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL
                                                       pixelsWide: 4
                                                       pixelsHigh: 4
                                                    bitsPerSample: 8
                                                  samplesPerPixel: 4
                                                         hasAlpha: YES
                                                         isPlanar: NO
                                                   colorSpaceName: NSCalibratedRGBColorSpace
                                                      bytesPerRow: 0
                                                     bitsPerPixel: 0];

  copy1Bitmap = [origBitmap copy];

  // Copying immutable NSData reuses the data pointer instead of allocating new memory, so 
  // copying a bitmap with immutable _imageData causes both bitmaps to point to the same memory;
  // Writing to either copy's pixels will overwrite both, corrupting the image data
  
  copy2Bitmap = [copy1Bitmap copy];
    
  pass([copy1Bitmap bitmapData] != [copy2Bitmap bitmapData],
       "Copied bitmaps have a different image data pointer - could cause image data corruption.");
  
  DESTROY(copy1Bitmap);
  DESTROY(copy2Bitmap);
  DESTROY(origBitmap);
  [arp release];
  return 0;
}