Moved CFDate.m from test/Analysis-Apple to test/Analysis, and added the necessary declarations from Foundation.h to CFDate.m so that the test case can be exercised on all platforms.

llvm-svn: 52343
This commit is contained in:
Ted Kremenek 2008-06-16 18:34:22 +00:00
parent 9995302b02
commit 7056bb1f21
1 changed files with 39 additions and 13 deletions

View File

@ -1,13 +1,40 @@
// RUN: clang -checker-cfref -verify %s
#include <CoreFoundation/CFDate.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSCalendarDate.h>
#include <Foundation/NSString.h>
//===----------------------------------------------------------------------===//
// The following code is reduced using delta-debugging from
// Foundation.h (Mac OS X).
//
// It includes the basic definitions for the test cases below.
// Not including Foundation.h directly makes this test case both svelt and
// portable to non-Mac platforms.
//===----------------------------------------------------------------------===//
typedef const struct __CFAllocator * CFAllocatorRef;
typedef double CFTimeInterval;
typedef CFTimeInterval CFAbsoluteTime;
typedef const struct __CFDate * CFDateRef;
extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at);
typedef struct objc_object {} *id;
typedef signed char BOOL;
typedef unsigned int NSUInteger;
typedef struct _NSZone NSZone;
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
@protocol NSObject - (BOOL)isEqual:(id)object; - (id)retain; - (oneway void)release; @end
@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end
@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
@interface NSObject <NSObject> {} @end
extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
typedef double NSTimeInterval;
@interface NSDate : NSObject <NSCopying, NSCoding> - (NSTimeInterval)timeIntervalSinceReferenceDate; @end
@class NSString, NSArray, NSTimeZone;
//===----------------------------------------------------------------------===//
// Test cases.
//===----------------------------------------------------------------------===//
CFAbsoluteTime f1() {
CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
CFDateRef date = CFDateCreate(NULL, t);
CFDateRef date = CFDateCreate(0, t);
CFRetain(date);
CFRelease(date);
CFDateGetAbsoluteTime(date); // no-warning
@ -18,7 +45,7 @@ CFAbsoluteTime f1() {
CFAbsoluteTime f2() {
CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
CFDateRef date = CFDateCreate(NULL, t);
CFDateRef date = CFDateCreate(0, t);
[((NSDate*) date) retain];
CFRelease(date);
CFDateGetAbsoluteTime(date); // no-warning
@ -35,7 +62,7 @@ NSDate* global_x;
CFAbsoluteTime f3() {
CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
CFDateRef date = CFDateCreate(NULL, t);
CFDateRef date = CFDateCreate(0, t);
[((NSDate*) date) retain];
CFRelease(date);
CFDateGetAbsoluteTime(date); // no-warning
@ -56,7 +83,7 @@ CFAbsoluteTime f4() {
struct foo x;
CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
CFDateRef date = CFDateCreate(NULL, t);
CFDateRef date = CFDateCreate(0, t);
[((NSDate*) date) retain];
CFRelease(date);
CFDateGetAbsoluteTime(date); // no-warning
@ -70,7 +97,7 @@ CFAbsoluteTime f4() {
CFAbsoluteTime f5(int x) {
CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
CFDateRef date = CFDateCreate(NULL, t);
CFDateRef date = CFDateCreate(0, t);
if (x)
CFRelease(date);
@ -81,7 +108,7 @@ CFAbsoluteTime f5(int x) {
// Test a leak involving the return.
CFDateRef f6(int x) {
CFDateRef date = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());
CFRetain(date);
return date; // expected-warning{{leak}}
}
@ -89,9 +116,9 @@ CFDateRef f6(int x) {
// Test a leak involving an overwrite.
CFDateRef f7() {
CFDateRef date = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());
CFRetain(date); //expected-warning{{leak}}
date = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());
return date;
}
@ -106,4 +133,3 @@ CFDateRef f8() {
return date; // expected-warning{{leak}}
}