From a98293327fc5bd10c345cef8d5b55decdd0dee5e Mon Sep 17 00:00:00 2001 From: znek Date: Fri, 21 May 2004 09:16:49 +0000 Subject: [PATCH] Added znek's tests git-svn-id: http://svn.opengroupware.org/SOGo/trunk@1 d1b88da0-ebda-0310-925b-ed51d893ca5b --- db/tests/znek/GNUmakefile | 19 +++++++ db/tests/znek/GNUmakefile.preamble | 5 ++ db/tests/znek/lmail.m | 46 +++++++++++++++ db/tests/znek/lpe.m | 91 ++++++++++++++++++++++++++++++ db/tests/znek/pfinserts.m | 70 +++++++++++++++++++++++ 5 files changed, 231 insertions(+) create mode 100644 db/tests/znek/GNUmakefile create mode 100644 db/tests/znek/GNUmakefile.preamble create mode 100644 db/tests/znek/lmail.m create mode 100644 db/tests/znek/lpe.m create mode 100644 db/tests/znek/pfinserts.m diff --git a/db/tests/znek/GNUmakefile b/db/tests/znek/GNUmakefile new file mode 100644 index 00000000..4e140e57 --- /dev/null +++ b/db/tests/znek/GNUmakefile @@ -0,0 +1,19 @@ +# $Id: GNUmakefile,v 1.2 2003/10/13 08:37:36 helge Exp $ + +include $(GNUSTEP_MAKEFILES)/common.make + +TOOL_NAME = \ + ldapPersonExporter \ + findLongestEMailAddress \ + personalFolderInfoInserts + +ldapPersonExporter_OBJC_FILES = lpe.m +ldapPersonExporter_TOOL_LIBS += -lNGLdap + +findLongestEMailAddress_OBJC_FILES = lmail.m + +personalFolderInfoInserts_OBJC_FILES = pfinserts.m + +-include GNUmakefile.preamble +include $(GNUSTEP_MAKEFILES)/tool.make +-include GNUmakefile.postamble diff --git a/db/tests/znek/GNUmakefile.preamble b/db/tests/znek/GNUmakefile.preamble new file mode 100644 index 00000000..b587e50f --- /dev/null +++ b/db/tests/znek/GNUmakefile.preamble @@ -0,0 +1,5 @@ +# $Id: GNUmakefile.preamble,v 1.1.1.1 2003/07/09 22:57:26 cvs Exp $ + +ADDITIONAL_TOOL_LIBS += \ + -lNGExtensions \ + -lEOControl diff --git a/db/tests/znek/lmail.m b/db/tests/znek/lmail.m new file mode 100644 index 00000000..5fb42715 --- /dev/null +++ b/db/tests/znek/lmail.m @@ -0,0 +1,46 @@ +/* + @DISCLAIMER@ +*/ +// $Id$ + +#import + +#define DEBUG 0 + +#define ALL_RECORDS @"/tmp/all.nsarray" + +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) +#endif + + +int main(int argc, char **argv, char **env) { + NSAutoreleasePool *pool; + NSArray *records; + unsigned int i, count, maxLength; + NSString *longestMailto; + + pool = [[NSAutoreleasePool alloc] init]; +#if LIB_FOUNDATION_LIBRARY + [NSProcessInfo initializeWithArguments:argv count:argc environment:env]; +#endif + + records = [NSArray arrayWithContentsOfFile:ALL_RECORDS]; + count = [records count]; + maxLength = 0; + + for(i = 0; i < count; i++) { + NSString *mailto; + unsigned length; + + mailto = [[records objectAtIndex:i] objectForKey:@"mailto"]; + length = [mailto length]; + maxLength = MAX(maxLength, length); + if(length == maxLength) + longestMailto = mailto; + } + printf("\nTotal: %d\nMaxlength: %d\nlongest: %s\n", count, maxLength, [longestMailto cString]); + [pool release]; + exit(0); + return 0; +} diff --git a/db/tests/znek/lpe.m b/db/tests/znek/lpe.m new file mode 100644 index 00000000..07f87e6a --- /dev/null +++ b/db/tests/znek/lpe.m @@ -0,0 +1,91 @@ +/* + @DISCLAIMER@ +*/ +// $Id$ + +#include +#include + +#define DEBUG 0 + +#define LDAP_HOST @"localhost" +#if DEBUG +#define LDAP_BASE_DN @"ou=Informatique,ou=SPAG,ou=DDE 32,ou=DDE,ou=melanie,ou=organisation,dc=equipement,dc=gouv,dc=fr" +#else +#define LDAP_BASE_DN @"dc=equipement,dc=gouv,dc=fr" +#endif + +/* +scope = ldap.SCOPE_SUBTREE +filter = '(mineqTypeEntree=BALI)' +attrlist = ["mail", "sn", "givenName"] +*/ + +int main(int argc, char **argv, char **env) { + NSAutoreleasePool *pool; + EOQualifier *q; + NSArray *attrs; + NGLdapConnection *conn; + NSEnumerator *resultEnum; + NSMutableArray *allResults; + id obj; + int totalCount = 0; + + pool = [[NSAutoreleasePool alloc] init]; +#if LIB_FOUNDATION_LIBRARY + [NSProcessInfo initializeWithArguments:argv count:argc environment:env]; +#endif + + q = [EOQualifier qualifierWithQualifierFormat:@"mineqTypeEntree = BALI"]; + + attrs = [[NSArray alloc] initWithObjects:@"sn", @"givenName", @"mail", +nil]; + + conn = [[NGLdapConnection alloc] initWithHostName:LDAP_HOST]; + [conn setUseCache:NO]; + resultEnum = [conn deepSearchAtBaseDN:LDAP_BASE_DN + qualifier:q + attributes:attrs]; + + allResults = [[NSMutableArray alloc] initWithCapacity:60000]; + while((obj = [resultEnum nextObject]) != nil) { + NSAutoreleasePool *lpool; + NSMutableDictionary *resultDict; + NSDictionary *attrDict; + NSString *dir, *cn; + NGLdapAttribute *mail, *sn, *givenName; + + lpool = [[NSAutoreleasePool alloc] init]; + attrDict = [obj attributes]; + resultDict = + [[NSMutableDictionary alloc] initWithCapacity:[attrDict count] + 1]; + dir = [NSString stringWithFormat:@"SOGo://%@", [obj dn]]; +#if DEBUG + NSLog(@"obj = %@", obj); +#endif + [resultDict setObject:dir forKey:@"DIR"]; + mail = [attrDict objectForKey:@"mail"]; + [resultDict setObject:[mail stringValueAtIndex:0] forKey:@"mailto"]; + sn = [attrDict objectForKey:@"sn"]; + givenName = [attrDict objectForKey:@"givenName"]; + cn = [NSString stringWithFormat:@"%@ %@", + [givenName stringValueAtIndex:0], + [sn stringValueAtIndex:0]]; + [resultDict setObject:cn forKey:@"CN"]; + [allResults addObject:resultDict]; + [resultDict release]; + totalCount += 1; + if(totalCount % 10 == 0) + printf("."); + [lpool release]; + } + + [allResults writeToFile:@"/tmp/all.nsarray" atomically:NO]; + [allResults release]; + printf("\ndone.\n"); + [attrs release]; + [conn release]; + [pool release]; + exit(0); + return 0; +} diff --git a/db/tests/znek/pfinserts.m b/db/tests/znek/pfinserts.m new file mode 100644 index 00000000..00d8a5d4 --- /dev/null +++ b/db/tests/znek/pfinserts.m @@ -0,0 +1,70 @@ +/* + @DISCLAIMER@ +*/ +// $Id$ + +#import + +#define DEBUG 0 + +#define ALL_RECORDS @"/home/znek/all-BALI.plist" + +/* + CREATE_TABLE personalfolderinfo ( + c_email VARCHAR(128) NOT NULL, // index drauf + c_tablename VARCHAR(128) NOT NULL, + c_dbname VARCHAR(128) NOT NULL, + c_dbport INT NOT NULL + // kann man spaeter mit condict erweitern (user/login?) + ); + */ + +#define PREAMBLE @"BEGIN;\n" +#define INSERT_FORMAT @"INSERT INTO personalfolderinfo VALUES ('%@', 'I%06d', 'SOGo1', 0);\n" +#define POSTAMBLE @"COMMIT;\n" + + +int main(int argc, char **argv, char **env) { + NSAutoreleasePool *pool; + NSArray *records; + unsigned int i, count, maxLength; + NSString *longestMailto; + int sequence; + + pool = [[NSAutoreleasePool alloc] init]; +#if LIB_FOUNDATION_LIBRARY + [NSProcessInfo initializeWithArguments:argv count:argc environment:env]; +#endif + + records = [NSArray arrayWithContentsOfFile:ALL_RECORDS]; +#if DEBUG + count = 5; +#else + count = [records count]; +#endif + sequence = 0; + + printf([PREAMBLE cString]); + for(i = 0; i < count; i++) { + NSString *format, *mailto; + NSDictionary *d; + d = [records objectAtIndex:i]; + + mailto = [d objectForKey:@"mailto"]; + if([mailto rangeOfString:@"'"].location != NSNotFound) { + NSArray *exploded; + + exploded = [mailto componentsSeparatedByString:@"'"]; + mailto = [exploded componentsJoinedByString:@"\\'"]; + } + format = [[NSString alloc] initWithFormat:INSERT_FORMAT, + mailto, + sequence++]; + printf([format cString]); + [format release]; + } + printf([POSTAMBLE cString]); + [pool release]; + exit(0); + return 0; +} -- 2.39.5