1 // $Id: fbtest.m 1 2004-08-20 10:38:46Z znek $
3 #import <Foundation/Foundation.h>
4 #import <NGExtensions/NGExtensions.h>
5 #import <GDLAccess/EOAccess.h>
6 //#include "FBAdaptor.h"
8 #define ADAPTOR_LEVEL 1
10 unsigned txRepeatCount = 1;
12 static int doAdPersTest1(EOModel *m,EOAdaptorContext *ctx, EOAdaptorChannel *ch) {
13 NSAutoreleasePool *pool = [NSAutoreleasePool new];
19 /* fetch some person records */
21 e = [m entityNamed:@"Person"];
23 attrs = [e attributes];
25 NSLog(@"entity: %@", e);
26 NSLog(@"qual: %@", q);
27 NSLog(@"attrs: %@", attrs);
31 NSLog(@"missing Person attributes in entity %@ !!!", e);
35 NSCalendarDate *start;
38 q = [[EOSQLQualifier alloc] initWithEntity:e
39 qualifierFormat:@"%A=5010", @"personId"];
41 start = [NSCalendarDate date];
44 for (i = 0; i < count; i++) {
45 //NSCAssert(attrs, @"missing attributes !!!");
47 if ([ch selectAttributes:attrs
48 describedByQualifier:q
51 while ((record = [ch fetchAttributes:attrs withZone:nil])) {
53 NSLog(@"fetched %@ id %@",
54 [record valueForKey:@"pname"],
55 [record valueForKey:@"personId"]);
60 NSLog(@"select failed ...");
64 NSLog(@"duration: count %i %.3fs", count,
65 [[NSCalendarDate date] timeIntervalSinceDate:start]);
72 static int doAdTest1(EOModel *m,EOAdaptorContext *ctx, EOAdaptorChannel *ch) {
74 #if !LIB_FOUNDATION_BOEHM_GC
75 NSAutoreleasePool *pool = [NSAutoreleasePool new];
81 /* fetch some team records */
83 e = [m entityNamed:@"Team"];
85 attrs = [e attributes];
87 if ([ch selectAttributes:attrs
88 describedByQualifier:q
93 while ((record = [ch fetchAttributes:attrs withZone:nil])) {
94 NSLog(@"fetched %@ birthday %@",
95 [record valueForKey:@"description"],
96 [record valueForKey:@"companyId"]);
102 e = [m entityNamed:@"Person"];
103 attrs = [e attributes];
104 q = [[EOSQLQualifier alloc] initWithEntity:e
105 qualifierFormat:@"%A='helge'", @"login"];
109 if ([ch selectAttributes:attrs
110 describedByQualifier:q
113 NSDictionary *record;
115 while ((record = [ch fetchAttributes:attrs withZone:nil]))
119 /* fetch some expr */
122 if ([ch evaluateExpression:expr]) {
123 NSDictionary *record;
125 attrs = [ch describeResults];
126 //NSLog(@"results: %@", attrs);
128 while ((record = [ch fetchAttributes:attrs withZone:nil]))
129 NSLog(@"fetched %@", record);
139 static void runAdTests(NSDictionary *conDict) {
142 EOAdaptorContext *ctx;
143 EOAdaptorChannel *ch;
146 a = [EOAdaptor adaptorWithName:@"FrontBase2"];
147 //a = [[FrontBaseAdaptor alloc] initWithName:@"FrontBase"];
148 [a setConnectionDictionary:conDict];
149 NSLog(@"got adaptor[%@] %@", NSStringFromClass([a class]), a);
151 ctx = [a createAdaptorContext];
152 ch = [ctx createAdaptorChannel];
154 m = AUTORELEASE([[EOModel alloc] initWithContentsOfFile:@"test.eomodel"]);
156 [a setConnectionDictionary:conDict];
158 expr = [[NSUserDefaults standardUserDefaults] stringForKey:@"sql"];
160 NSLog(@"opening channel ..");
162 //[ch setDebugEnabled:NO];
164 if ([ch openChannel]) {
166 NSLog(@"channel is open");
168 for (txi = 0; txi < txRepeatCount; txi++) {
169 if ([ctx beginTransaction]) {
170 NSLog(@"began tx (%i) ..", txi);
173 if (!doAdPersTest1(m, ctx, ch))
176 NSLog(@"committing tx ..");
177 if ([ctx commitTransaction])
178 NSLog(@" could commit.");
180 NSLog(@" commit failed.");
183 NSLog(@"tx open failed ..");
187 NSLog(@"closing channel ..");
191 NSLog(@"open channel failed ...");
195 static void runDbTests(NSDictionary *conDict) {
199 EODatabaseContext *ctx;
200 EODatabaseChannel *ch;
203 a = [EOAdaptor adaptorWithName:@"FrontBase2"];
204 //a = [[FrontBaseAdaptor alloc] initWithName:@"FrontBase"];
205 [a setConnectionDictionary:conDict];
206 NSLog(@"got adaptor[%@] %@", NSStringFromClass([a class]), a);
208 db = [[EODatabase alloc] initWithAdaptor:a];
209 ctx = [db createContext];
210 ch = [ctx createChannel];
212 m = AUTORELEASE([[EOModel alloc] initWithContentsOfFile:@"test.eomodel"]);
214 [a setConnectionDictionary:conDict];
216 expr = [[NSUserDefaults standardUserDefaults] stringForKey:@"sql"];
218 NSLog(@"opening channel ..");
220 if ([ch openChannel]) {
222 NSLog(@"channel is open");
224 for (txi = 0; txi < txRepeatCount; txi++) {
225 if ([(EOAdaptorContext *)ctx beginTransaction]) {
226 NSLog(@"began tx ..");
230 #if !LIB_FOUNDATION_BOEHM_GC
231 NSAutoreleasePool *pool = [NSAutoreleasePool new];
238 /* fetch some person records */
240 e = [m entityNamed:@"Person"];
242 attrs = [e attributes];
244 if ([ch selectObjectsDescribedByQualifier:q fetchOrder:nil]) {
245 while ((record = [ch fetchWithZone:nil])) {
246 NSLog(@"fetched %@ birthday %@",
247 [record valueForKey:@"description"],
248 [record valueForKey:@"companyId"]);
252 /* fetch some team records */
254 e = [m entityNamed:@"Team"];
256 attrs = [e attributes];
260 e = [m entityNamed:@"Person"];
261 attrs = [e attributes];
262 q = [[EOSQLQualifier alloc] initWithEntity:e
263 qualifierFormat:@"%A='helge'", @"login"];
270 NSLog(@"committing tx ..");
271 if ([ctx commitTransaction])
272 NSLog(@" could commit.");
274 NSLog(@" commit failed.");
278 NSLog(@"closing channel ..");
282 NSLog(@"open channel failed ...");
286 int main(int argc, char **argv, char **env) {
287 NSAutoreleasePool *pool;
288 NSDictionary *conDict;
290 pool = [[NSAutoreleasePool alloc] init];
292 #if LIB_FOUNDATION_LIBRARY
293 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
296 conDict = [NSDictionary dictionaryWithContentsOfFile:@"condict.plist"];