testing additions

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@37774 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2014-03-28 08:07:59 +00:00
parent 1e32f3b7a1
commit 1207d5fd02
5 changed files with 268 additions and 1 deletions

View file

@ -1,6 +1,17 @@
2014-03-28 Richard Frith-Macdonald <rfm@gnu.org>
* EcTest.h:
* EcTest.m:
* EcProcess.m:
* GNUmakefile:
Add a few simple functions to connect to a process, set/get the
config of a running process, and issue commands (and get back
the response) so that regression test software can relatively
easily exercie an entire system.
2014-03-26 Richard Frith-Macdonald <rfm@gnu.org>
EcControl.m: Add option to allow any user to log in.
* EcControl.m: Add option to allow any user to log in.
2014-03-25 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -4294,3 +4294,61 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval);
@end
@implementation EcProcess (Test)
- (bycopy NSString*) ecTestCommand: (in bycopy NSString*)command
{
NSEnumerator *enumerator;
NSMutableArray *words;
NSString *word;
command = [command stringByTrimmingSpaces];
words = [NSMutableArray arrayWithCapacity: 16];
enumerator = [[command componentsSeparatedByString: @" "] objectEnumerator];
while ((word = [enumerator nextObject]) != nil)
{
[words addObject: [word stringByTrimmingSpaces]];
}
if ([words count] == 0)
{
return nil;
}
return [self cmdMesg: words];
}
- (bycopy NSData*) ecTestConfigForKey: (in bycopy NSString*)key
{
id result = [cmdDefs objectForKey: key];
if (nil != result)
{
result = [NSPropertyListSerialization
dataFromPropertyList: result
format: NSPropertyListBinaryFormat_v1_0
errorDescription: 0];
}
return result;
}
- (void) ecTestSetConfig: (in bycopy NSData*)data
forKey: (in bycopy NSString*)key
{
id val;
if (nil == data)
{
val = data;
}
else
{
val = [NSPropertyListSerialization
propertyListWithData: data
options: NSPropertyListMutableContainers
format: 0
error: 0];
}
[cmdDefs setCommand: val forKey: key];
}
@end

88
EcTest.h Normal file
View file

@ -0,0 +1,88 @@
/** Enterprise Control Configuration and Logging
Copyright (C) 2014 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <rfm@gnu.org>
Date: March 2014
Originally developed from 1996 to 2014 by Brainstorm, and donated to
the FSF.
This file is part of the GNUstep project.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#import <Foundation/NSObject.h>
@class NSData;
@class NSString;
/* The EcTest protocol provides remote diagnostic tools to use from
* one program to test the operation of an EcProcess based server.
*/
@protocol EcTest <NSObject>
/** Sends a command to the remote process and returns the string output.<br />
* Similar to issueing the command string at the console.
*/
- (bycopy NSString*) ecTestCommand: (in bycopy NSString*)command;
/* Gets the current configuration value in use by the process for the
* specified key.
*/
- (bycopy NSData*) ecTestConfigForKey: (in bycopy NSString*)key;
/* Sets a configuration value to be used by the remote process, overriding
* any existing value. Changes to the process configuration in Control.plist
* will NOT override this for the running process, though changes explicitly
* made from the Console may.<br />
* The supplied data is a serialised property list.<br />
* NB. This method is NOT oneway, it waits for the remote process to handle
* the configuration change before it returns, so the caller knows that the
* configuration update has taken place.
*/
- (void) ecTestSetConfig: (in bycopy NSData*)data
forKey: (in bycopy NSString*)key;
@end
/** This function obtains a Distributed Objects proxy to the EcProcess
* instance controlling the server with the specified name and host.<br />
* A nil or empty string for the host is taken to mean the local host,
* while an asterisk denotes any host on the local network.<br />
* The timeout is a time limit on how long it may take to get the
* connection (a value less than or equal to zero wiull cause the
* function to keep on trying indefinitely).
*/
extern id<EcTest>
EcTestConnect(NSString *name, NSString *host, NSTimeInterval timeout);
/** This function gets process configuration for the specified key
* and deserialises it to a property list object (returned) or nil
* if no value is configured for the specified key.
*/
extern id
EcTestGetConfig(id<EcTest> process, NSString *key);
/** This function sets process configuration by serialising the property
* list value and passing the resulting data to the remote process.<br />
* If the value is nil then the configuration for the remote process
* reverts to its default setting.
*/
extern void
EcTestSetConfig(id<EcTest> process, NSString *key, id value);

107
EcTest.m Normal file
View file

@ -0,0 +1,107 @@
/** Enterprise Control Configuration and Logging
Copyright (C) 2014 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <rfm@gnu.org>
Date: March 2014
Originally developed from 1996 to 2012 by Brainstorm, and donated to
the FSF.
This file is part of the GNUstep project.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#import <Foundation/Foundation.h>
#import "EcProcess.h"
#import "EcTest.h"
id<EcTest>
EcTestConnect(NSString *name, NSString *host, NSTimeInterval timeout)
{
CREATE_AUTORELEASE_POOL(pool);
id<EcTest> proxy = nil;
NSDate *when;
if (nil == host) host = @"";
if (timeout > 0)
{
when = [NSDate dateWithTimeIntervalSinceNow: timeout];
}
else
{
when = [NSDate distantFuture];
}
while (nil == proxy && [when timeIntervalSinceNow] > 0.0)
{
NS_DURING
{
proxy = (id<EcTest>)[NSConnection
rootProxyForConnectionWithRegisteredName: name
host: @""
usingNameServer: [NSSocketPortNameServer sharedInstance]];
}
NS_HANDLER
{
proxy = nil;
}
NS_ENDHANDLER
if (nil == proxy)
{
[NSThread sleepForTimeInterval: 0.1];
}
}
[proxy retain];
DESTROY(pool);
return [proxy autorelease];
}
id
EcTestGetConfig(id<EcTest> process, NSString *key)
{
id val;
NSCAssert([key isKindOfClass: [NSString class]], NSInvalidArgumentException);
val = [process ecTestConfigForKey: key];
if (nil != val)
{
val = [NSPropertyListSerialization
propertyListWithData: val
options: NSPropertyListMutableContainers
format: 0
error: 0];
}
return val;
}
void
EcTestSetConfig(id<EcTest> process, NSString *key, id value)
{
NSCAssert([key isKindOfClass: [NSString class]], NSInvalidArgumentException);
if (nil != value)
{
value = [NSPropertyListSerialization
dataFromPropertyList: value
format: NSPropertyListBinaryFormat_v1_0
errorDescription: 0];
}
[process ecTestSetConfig: value forKey: key];
}

View file

@ -46,6 +46,7 @@ ECCL_OBJC_FILES = \
EcHost.m \
EcLogger.m \
EcProcess.m \
EcTest.m \
EcUserDefaults.m \
ECCL_HEADER_FILES = \
@ -57,6 +58,7 @@ ECCL_HEADER_FILES = \
EcHost.h \
EcLogger.h \
EcProcess.h \
EcTest.h \
EcUserDefaults.h \
@ -109,6 +111,7 @@ ECCL_AGSDOC_FILES = ECCL.h \
EcHost.h \
EcLogger.h \
EcProcess.h \
EcTest.h \
EcUserDefaults.h \
EcCommand.m \
EcControl.m \