aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMSystemVersion.m
diff options
context:
space:
mode:
authorGravatar thomasvl <thomasvl@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2008-04-14 17:21:02 +0000
committerGravatar thomasvl <thomasvl@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2008-04-14 17:21:02 +0000
commitcdf070c8d76ffc4eaa24e8671756cbbe9ceb2890 (patch)
treefaa9ae3a72a6591d6a6add7ceed7f91e92ade11f /Foundation/GTMSystemVersion.m
parent0aaecac6ff2bc89e58a0c8c6d6ad62e02fb2b011 (diff)
See the ReleaseNotes for the full details, highlights:
- bug fixes - code coverage support - more complete unittests - full support for unittesting UIs - support for the iphone sdk (include ui unittesting)
Diffstat (limited to 'Foundation/GTMSystemVersion.m')
-rw-r--r--Foundation/GTMSystemVersion.m107
1 files changed, 45 insertions, 62 deletions
diff --git a/Foundation/GTMSystemVersion.m b/Foundation/GTMSystemVersion.m
index d9b1923..a2e4d7b 100644
--- a/Foundation/GTMSystemVersion.m
+++ b/Foundation/GTMSystemVersion.m
@@ -17,88 +17,71 @@
//
#import "GTMSystemVersion.h"
-#import <Carbon/Carbon.h>
-#import <stdlib.h>
+
+static int sGTMSystemVersionMajor = 0;
+static int sGTMSystemVersionMinor = 0;
+static int sGTMSystemVersionBugFix = 0;
@implementation GTMSystemVersion
++ (void)initialize {
+ if (self == [GTMSystemVersion class]) {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSDictionary *systemVersionPlist = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
+ NSString *version = [systemVersionPlist objectForKey:@"ProductVersion"];
+ _GTMDevAssert(version, @"Unable to get version");
+ NSArray *versionInfo = [version componentsSeparatedByString:@"."];
+ int length = [versionInfo count];
+ _GTMDevAssert(length > 1 && length < 4, @"Unparseable version %@", version);
+ sGTMSystemVersionMajor = [[versionInfo objectAtIndex:0] intValue];
+ _GTMDevAssert(sGTMSystemVersionMajor != 0, @"Unknown version for %@", version);
+ sGTMSystemVersionMinor = [[versionInfo objectAtIndex:1] intValue];
+ if (length == 3) {
+ sGTMSystemVersionBugFix = [[versionInfo objectAtIndex:2] intValue];
+ }
+ [pool release];
+ }
+}
++ (void)getMajor:(long*)major minor:(long*)minor bugFix:(long*)bugFix {
+ if (major) {
+ *major = sGTMSystemVersionMajor;
+ }
+ if (minor) {
+ *minor = sGTMSystemVersionMinor;
+ }
+ if (major) {
+ *bugFix = sGTMSystemVersionBugFix;
+ }
+}
+
+#if GTM_MACOS_SDK
+ (BOOL)isPanther {
- long major, minor;
- [self getMajor:&major minor:&minor bugFix:nil];
- return major == 10 && minor == 3;
+ return sGTMSystemVersionMajor == 10 && sGTMSystemVersionMinor == 3;
}
+ (BOOL)isTiger {
- long major, minor;
- [self getMajor:&major minor:&minor bugFix:nil];
- return major == 10 && minor == 4;
+ return sGTMSystemVersionMajor == 10 && sGTMSystemVersionMinor == 4;
}
+ (BOOL)isLeopard {
- long major, minor;
- [self getMajor:&major minor:&minor bugFix:nil];
- return major == 10 && minor == 5;
+ return sGTMSystemVersionMajor == 10 && sGTMSystemVersionMinor == 5;
}
+ (BOOL)isPantherOrGreater {
- long major, minor;
- [self getMajor:&major minor:&minor bugFix:nil];
- return (major > 10) || (major == 10 && minor >= 3);
+ return (sGTMSystemVersionMajor > 10) ||
+ (sGTMSystemVersionMajor == 10 && sGTMSystemVersionMinor >= 3);
}
+ (BOOL)isTigerOrGreater {
- long major, minor;
- [self getMajor:&major minor:&minor bugFix:nil];
- return (major > 10) || (major == 10 && minor >= 4);
+ return (sGTMSystemVersionMajor > 10) ||
+ (sGTMSystemVersionMajor == 10 && sGTMSystemVersionMinor >= 4);
}
+ (BOOL)isLeopardOrGreater {
- long major, minor;
- [self getMajor:&major minor:&minor bugFix:nil];
- return (major > 10) || (major == 10 && minor >= 5);
+ return (sGTMSystemVersionMajor > 10) ||
+ (sGTMSystemVersionMajor == 10 && sGTMSystemVersionMinor >= 5);
}
-+ (void)getMajor:(long*)major minor:(long*)minor bugFix:(long*)bugFix {
- long binaryCodedDec;
-
- if (major) {
- require_noerr(Gestalt(gestaltSystemVersionMajor, major), failedGestalt);
- }
- if (minor) {
- require_noerr(Gestalt(gestaltSystemVersionMinor, minor), failedGestalt);
- }
- if (bugFix) {
- require_noerr(Gestalt(gestaltSystemVersionBugFix, bugFix), failedGestalt);
- }
- return;
-
-failedGestalt:
- // gestaltSystemVersionMajor et al are only on 10.4 and above, so they
- // could fail if we have this code on 10.3.
- if (Gestalt(gestaltSystemVersion, &binaryCodedDec)) {
- // not much else we can do...
- if (major) *major = 0;
- if (minor) *minor = 0;
- if (bugFix) *bugFix = 0;
- return;
- }
-
- // Note that this code will return x.9.9 for any system rev parts that are
- // greater than 9 (ie 10.10.10 will be 10.9.9. This shouldn't ever be a
- // problem as the code above takes care of this for any system above 10.4.
- if (major) {
- int msb = (binaryCodedDec & 0x0000F000L) >> 12;
- msb *= 10;
- int lsb = (binaryCodedDec & 0x00000F00L) >> 8;
- *major = msb + lsb;
- }
- if (minor) {
- *minor = (binaryCodedDec & 0x000000F0L) >> 4;
- }
- if (bugFix) {
- *bugFix = (binaryCodedDec & 0x0000000FL);
- }
-
-}
+#endif // GTM_IPHONE_SDK
@end