[39309] branches/gsoc08-framework/MacPorts_Framework_Release

armahg at macports.org armahg at macports.org
Sun Aug 17 13:28:05 PDT 2008


Revision: 39309
          http://trac.macosforge.org/projects/macports/changeset/39309
Author:   armahg at macports.org
Date:     2008-08-17 13:28:05 -0700 (Sun, 17 Aug 2008)
Log Message:
-----------
Added first test case to MPPortManipulationTest class. Uninstall operation fails

Modified Paths:
--------------
    branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m
    branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m
    branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.h
    branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.m
    branches/gsoc08-framework/MacPorts_Framework_Release/MPRegistry.m
    branches/gsoc08-framework/MacPorts_Framework_Release/ToDo.txt

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m	2008-08-17 19:54:39 UTC (rev 39308)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPHelperTool.m	2008-08-17 20:28:05 UTC (rev 39309)
@@ -77,14 +77,14 @@
 	assert(logClient != NULL);
 	
 	
-	err = asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"Starting simplelog Logging");
-	assert( err == 0);
+	//err = asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"Starting simplelog Logging");
+	//assert( err == 0);
 	
 	++objv, --objc;
 	
 	if (objc) {
 		NSString * data = [NSString stringWithUTF8String:Tcl_GetString(*objv)];
-		err = asl_NSLog(logClient , logMsg, ASL_LEVEL_INFO, @" %@ " , data);
+		err = asl_NSLog(logClient , logMsg, ASL_LEVEL_INFO, @"MPHelperTool: %@ " , data);
 		assert(err == 0);
 		
 		returnCode = TCL_OK;
@@ -133,16 +133,10 @@
 	if (tclCmd == nil) {
 		retval = coreFoundationUnknownErr;
 	}
-	
-	//Get the tcl Interpreter pkg path
-	NSString * tclPkgPath = (NSString *) (CFStringRef) CFDictionaryGetValue(request, CFSTR(kTclInterpreterInitPath));
-	if (tclCmd == nil) {
-		retval == coreFoundationUnknownErr;
-	}
 	else
 		CFDictionaryAddValue(response, CFSTR("TclCommandInput"), (CFStringRef)tclCmd);
 	
-
+	
 	//Create Tcl Interpreter 
 	Tcl_Interp * interpreter = Tcl_CreateInterp();
 	if(interpreter == NULL) {
@@ -169,6 +163,15 @@
 	}
 	
 	
+	
+	//Get the tcl Interpreter pkg path
+	NSString * tclPkgPath = (NSString *) (CFStringRef) CFDictionaryGetValue(request, CFSTR(kTclInterpreterInitPath));
+	if (tclPkgPath == nil) {
+		retval == coreFoundationUnknownErr;
+	}
+	else
+		CFDictionaryAddValue(response, CFSTR("TclPkgPath"), (CFStringRef)tclPkgPath);
+		
 	//Load macports1.0 package
 	NSString * mport_fastload = [[@"source [file join \"" stringByAppendingString:tclPkgPath]
 								 stringByAppendingString:@"\" macports1.0 macports_fastload.tcl]"];

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m	2008-08-17 19:54:39 UTC (rev 39308)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPInterpreter.m	2008-08-17 20:28:05 UTC (rev 39309)
@@ -443,12 +443,7 @@
 		if( response != NULL)
 			result = (NSString *) (CFStringRef) CFDictionaryGetValue(response, CFSTR(kTclStringEvaluationResult));
 	}
-	
-	
-	
-	
-	//Try to recover
-	if ( (err != noErr) && (err != userCanceledErr) ) {
+	else { //Try to recover error
 		failCode = BASDiagnoseFailure(internalMacPortsAuthRef, (CFStringRef) bundleID);
 		
 		
@@ -474,7 +469,7 @@
 		
 		
 		//Making the following assumption in error handling. If we return
-		//a noErr then response cannot be nil since everything went ok. 
+		//a noErr then response dictionary cannot be nil since everything went ok. 
 		//Hence I'm only checking for errors WITHIN the following blocks ...
 		if (err == noErr) {
 			err = BASExecuteRequestInHelperTool(internalMacPortsAuthRef, 
@@ -486,10 +481,7 @@
 				if( response != NULL)
 					result = (NSString *) (CFStringRef) CFDictionaryGetValue(response, CFSTR(kTclStringEvaluationResult));
 			}
-			
-			
-			//If we executed unsuccessfully
-			if (err != noErr) {
+			else { //If we executed unsuccessfully
 				if (mportError != NULL) {
 					NSError * undError = [[[NSError alloc] initWithDomain:NSOSStatusErrorDomain 
 																	 code:err 
@@ -507,7 +499,6 @@
 																	NSLocalizedString(@"BASExecuteRequestInHelperTool execution failed", @""),
 																	NSLocalizedFailureReasonErrorKey,
 																	nil]] autorelease];
-					
 				}
 			}
 		}
@@ -534,30 +525,7 @@
 			}
 		}
 	}
-	else {
-		err = userCanceledErr;
-		if (mportError != NULL) {
-			NSError * undError = [[[NSError alloc] initWithDomain:NSOSStatusErrorDomain 
-															 code:err 
-														 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
-																   NSLocalizedString(@"Check error code for OSStatus returned",@""), 
-																   NSLocalizedDescriptionKey,
-																   nil]] autorelease];
-			
-			*mportError = [[[NSError alloc] initWithDomain:MPFrameworkErrorDomain 
-													  code:MPHELPUSERCANCELLED
-												  userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
-															NSLocalizedString(@"MPHelperTool was not executed successfully", @""), 
-															NSLocalizedDescriptionKey,
-															undError, NSUnderlyingErrorKey,
-															NSLocalizedString(@"User cancelled the operation", @""),
-															NSLocalizedFailureReasonErrorKey,
-															nil]] autorelease];
-		}
-	}
 	
-	
-	
 	NSLog(@"AFTER Tool Execution request is %@ , response is %@ \n\n", request, response);
 	
 	return result;

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.h	2008-08-17 19:54:39 UTC (rev 39308)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.h	2008-08-17 20:28:05 UTC (rev 39309)
@@ -19,5 +19,5 @@
 	MPMacPorts * mainPort;
 }
 
--(void) testSimpleSearch;
+-(void) testSimpleManipulation;
 @end

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.m	2008-08-17 19:54:39 UTC (rev 39308)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPPortManipulationTest.m	2008-08-17 20:28:05 UTC (rev 39309)
@@ -8,8 +8,90 @@
 
 #import "MPPortManipulationTest.h"
 
+ at interface PortManipulator : NSObject {
+	
+}
+-(BOOL) installUninstallManipulation:(NSString *)portName;
+ at end
 
+ at implementation PortManipulator
+-(BOOL) installUninstallManipulation:(NSString *)portName {
+	BOOL ret = NO;
+	
+	MPRegistry * registry = [MPRegistry sharedRegistry];
+	MPMacPorts * port = [MPMacPorts sharedInstance];
+	
+	// Check if portName is installed
+	unsigned int installed = [[registry installed:portName] count];
+	
+	// Search for it
+	NSDictionary * searchResult = [port search:portName];
+	NSArray * keyArray = [searchResult allKeys];
+	MPPort * foundPort = [searchResult objectForKey:[keyArray objectAtIndex:0]];
+	
+	// If it is installed
+	if (installed > 0) {
+		NSError * uError;
+		//Attempt to uninstall it
+		[foundPort uninstallWithOptions:nil version:nil error:&uError];
+		
+		//Check for error
+		if (uError != nil) {
+			NSLog(@"\n\nUninstallation of %@ failed with error %@", portName, uError);
+			//I guess we should just return here
+			return ret;
+		}
+		
+		//Uninstallation was successful ... now check registry to make sure its gone
+		installed = [[registry installed:portName] count];
+		if (installed > 0) { //Uh oh ... is this suppose to happen?
+			NSLog(@"%@ is still installed after successful uninstall operation ... double check this from commandline", portName);
+			//for now return
+			return ret;
+		}
+		else { // For now end here later on ... add more code to restore system to its original state ... hmm i could just
+				// call this method twice
+			ret = YES;
+			return ret;
+		}
+		
+	}
+	else {
+		NSError * uError;
+		//Attempt to install it
+		[foundPort installWithOptions:nil variants:nil error:&uError];
+		
+		//Check for error
+		if (uError != nil) {
+			NSLog(@"\n\nInstallation of %@ failed with error %@", portName, uError);
+			//I guess we should just return here
+			return ret;
+		}
+		
+		//Installation was successful ... now check registry to make sure its gone
+		installed = [[registry installed:portName] count];
+		if (installed == 0) { //Uh oh ... is this suppose to happen?
+			NSLog(@"%@ is not installed after successful install operation ... double check this from commandline", portName);
+			//for now return
+			return ret;
+		}
+		else { // For now end here later on ... add more code to restore system to its original state ... hmm i could just
+			// call this method twice
+			ret = YES;
+			return ret;
+		}
+	}
+	NSLog(@"We shouldn't be here");
+	return YES;
+}
 
+ at end
+
+
+
+
+
+
 @implementation MPPortManipulationTest
 
 -(void) setUp {
@@ -20,38 +102,32 @@
 	
 }
 
--(void) testSimpleSearch {
-	NSDictionary * searchResult = [mainPort search:@"pngcrush"];
-	NSArray * keyArray = [searchResult allKeys];
-	//NSLog(@"\n\nPrinting search results for \"sphinx\"");
+-(void) testSimpleManipulation {
 	
-	//NSLog(@" %@ ", keyArray);
-	//NSLog(@" %@ ", [searchResult allValues]);
+	//NSDictionary * searchResult = [mainPort search:@"pngcrush"];
+//	NSArray * keyArray = [searchResult allKeys];
+//		
+//	NSLog(@"\n\n Installing first result from search %@ \n\n", [searchResult objectForKey:[keyArray objectAtIndex:0]]);
+//	NSError * iError;
+//	[[searchResult objectForKey:[keyArray objectAtIndex:0]] installWithOptions:nil variants:nil error:&iError];
+//	
+//	//How do we check if a port is installed? Should the methods return BOOL's instead?
+//	if (iError != nil) {
+//		NSLog(@"\n\n Installation of %@ failed with error %@\n\n", [keyArray objectAtIndex:0], iError);
+//	}
+//	else{
+//		NSLog(@"\n\n Installation successful \n\n");
+//		
+//		
+//	}
+//	
+//	//Double check somehow
+//	MPRegistry * registry = [MPRegistry sharedRegistry];
+//	NSLog(@"\n\n Result from registry is %@ \n\n", [registry installed:[keyArray objectAtIndex:0]]);
 	
-	id key;
-	NSEnumerator * k = [searchResult keyEnumerator];
-	while ( key = [k nextObject]) {
-		//NSLog(@"\n\n Key: %@ \n\n MPPort object: %@ \n\n", key, [searchResult objectForKey:key]);
-	}
-	
-	//NSLog(@"\n\nDone searching for \"sphinx\"\n\n");
-	
-	NSLog(@"\n\n Installing first result from search %@ \n\n", [searchResult objectForKey:[keyArray objectAtIndex:0]]);
-	NSError * iError;
-	[[searchResult objectForKey:[keyArray objectAtIndex:0]] installWithOptions:nil variants:nil error:&iError];
-	
-	//How do we check if a port is installed? Should the methods return BOOL's instead?
-	if (iError != nil) {
-		NSLog(@"\n\n Installation of %@ failed \n\n", [keyArray objectAtIndex:0]);
-	}
-	else{
-		NSLog(@"\n\n Installation successful \n\n");
-		//Double check somehow
-		MPRegistry * registry = [MPRegistry sharedRegistry];
-		NSLog(@"\n\n Result from registry is %@ \n\n", [registry installed:[keyArray objectAtIndex:0]]);
-		
-	}
-	
+	PortManipulator * pm = [[PortManipulator alloc] init];
+	STAssertTrue([pm installUninstallManipulation:@"pngcrush"] , @"This test should always return true on success");
+	[pm release];
 }
 
 @end

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MPRegistry.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MPRegistry.m	2008-08-17 19:54:39 UTC (rev 39308)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MPRegistry.m	2008-08-17 20:28:05 UTC (rev 39309)
@@ -127,9 +127,6 @@
 	}
 	
 	return [interpreter arrayFromTclListAsString:result];
-	
-	
-	
 }
 
 - (NSArray *)filesForPort:(NSString *)name {

Modified: branches/gsoc08-framework/MacPorts_Framework_Release/ToDo.txt
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/ToDo.txt	2008-08-17 19:54:39 UTC (rev 39308)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/ToDo.txt	2008-08-17 20:28:05 UTC (rev 39309)
@@ -28,4 +28,4 @@
 Also, we could throw in bindings support. How would this work? Don't know
 yet ...
 
-
+Fix bug in uninstall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080817/53cb23f9/attachment.html 


More information about the macports-changes mailing list