Permalink
Browse files

More GNUstep compatibility. Unit tests pass now.

  • Loading branch information...
snej committed Mar 3, 2012
1 parent 82f4a7f commit 3881d67d5f4790f6af6c2f989d4152c37f39932e
View
@@ -3,6 +3,9 @@
*.perspectivev3
*.mode1v3
*.framework
+*~
xcuserdata/
build/
DerivedData/
+obj/
+derived_src/
View
@@ -7,3 +7,6 @@
[submodule "vendor/MYUtilities"]
path = vendor/MYUtilities
url = git://github.com/snej/MYUtilities.git
+[submodule "vendor/JSONKit"]
+ path = vendor/JSONKit
+ url = git://github.com/johnezang/JSONKit.git
View
@@ -12,6 +12,7 @@
#if DEBUG
#import "Logging.h"
+#import "Test.h"
#else
#define Warn NSLog
#define Log NSLog
@@ -23,18 +24,21 @@ int main (int argc, const char * argv[])
@autoreleasepool {
#if DEBUG
EnableLog(YES);
- EnableLogTo(TDListener, YES);
+ //EnableLogTo(TDDatabase, YES);
+ //EnableLogTo(TDDatabaseVerbose, YES);
+ RunTestCases(argc, argv);
#endif
-
+ /*
NSError* error;
TDServer* server = [[TDServer alloc] initWithDirectory: @"/tmp/touchdbserver" error: &error];
- if (error) {
- Warn(@"FATAL: Error initializing TouchDB: %@", error);
+ if (!server) {
+ Warn(@"FATAL: Error initializing TDServer: %@", error);
exit(1);
}
NSLog(@"Started server %@", server);
[[NSRunLoop currentRunLoop] run];
+ */
}
return 0;
View
@@ -0,0 +1,135 @@
+# TouchDB Makefile for GNUstep
+
+# Include the common variables defined by the Makefile Package
+include $(GNUSTEP_MAKEFILES)/common.make
+
+# Build a simple Objective-C program
+FRAMEWORK_NAME = TouchDB
+
+# The Objective-C files to compile
+TouchDB_OBJC_FILES = \
+ Source/TDDatabase.m \
+ Source/TDDatabase+Replication.m \
+ Source/TDDatabase+Attachments.m \
+ Source/TDDatabase+Insertion.m \
+ Source/TDDatabase+LocalDocs.m \
+ Source/TDBody.m \
+ Source/TDRevision.m \
+ Source/TDView.m \
+ Source/TDServer.m \
+ Source/TDBlobStore.m \
+ \
+ Source/TDRouter.m \
+ Source/TDRouter+Handlers.m \
+ Source/TDURLProtocol.m \
+ \
+ Source/TDReplicator.m \
+ Source/TDPuller.m \
+ Source/TDPusher.m \
+ Source/TDReplicatorManager.m \
+ Source/TDRemoteRequest.m \
+ Source/TDMultipartDownloader.m \
+ Source/TDMultipartReader.m \
+ Source/TDMultipartUploader.m \
+ Source/TDMultiStreamWriter.m \
+ Source/TDMultipartWriter.m \
+ Source/TDReachability_Stubs.m \
+ \
+ Source/TDBatcher.m \
+ Source/TDCollateJSON.m \
+ Source/TDGNUstep.m \
+ Source/TDBase64.m \
+ Source/TDJSON.m \
+ Source/TDMisc.m \
+ Source/TDSequenceMap.m \
+ \
+ Source/TDBlobStore_Tests.m \
+ Source/TDDatabase_Tests.m \
+ Source/TDReplicator_Tests.m \
+ Source/TDRouter_Tests.m \
+ Source/TDView_Tests.m \
+ Source/ChangeTracker/TDChangeTracker.m \
+ Source/ChangeTracker/TDSocketChangeTracker.m \
+ Source/ChangeTracker/TDConnectionChangeTracker.m \
+ \
+ vendor/fmdb/src/FMDatabaseAdditions.m \
+ vendor/fmdb/src/FMDatabase.m \
+ vendor/fmdb/src/FMResultSet.m \
+ \
+ vendor/MYUtilities/CollectionUtils.m \
+ vendor/MYUtilities/ExceptionUtils.m \
+ vendor/MYUtilities/Logging.m \
+ vendor/MYUtilities/MYBlockUtils.m \
+ vendor/MYUtilities/Test.m \
+ \
+ vendor/google-toolbox-for-mac/GTMNSData+zlib.m
+
+ # TEMPORARILY DISABLED:
+ #Source/TDMultiStreamWriter.m
+
+TouchDB_HEADER_FILES_DIR = Source
+TouchDB_HEADER_FILES = \
+ TouchDB.h \
+ TDBatcher.h \
+ TDBlobStore.h \
+ TDBody.h \
+ TDDatabase+Attachments.h \
+ TDDatabase.h \
+ TDDatabase+Insertion.h \
+ TDDatabase+LocalDocs.h \
+ TDDatabase+Replication.h \
+ TDJSON.h \
+ TDPuller.h \
+ TDPusher.h \
+ TDReplicator.h \
+ TDRevision.h \
+ TDRouter.h \
+ TDServer.h \
+ TDURLProtocol.h \
+ TDView.h \
+
+TouchDB_INCLUDE_DIRS = \
+ -ISource \
+ -ISource/ChangeTracker \
+ -Ivendor/MYUtilities \
+ -Ivendor/google-toolbox-for-mac \
+ -Ivendor/fmdb/src
+
+TouchDB_OBJCFLAGS = \
+ -include Source/TouchDBPrefix.h
+
+
+
+TOOL_NAME = TouchTool
+
+TouchTool_OBJC_FILES = Demo-Mac/EmptyGNUstepApp.m
+
+TouchTool_OBJCFLAGS = \
+ -include Source/TDGNUstep.h
+
+TouchTool_OBJC_LIBS = \
+ -lTouchDB -LTouchDB.framework \
+ -lsqlite3 \
+ -lcrypto \
+ -luuid
+
+TouchTool_INCLUDE_DIRS = \
+ -Ivendor/MYUtilities
+
+
+OBJCFLAGS = \
+ -fblocks \
+ -Werror \
+ -Wall \
+ -DDEBUG=1
+
+#LDFLAGS = -v
+
+-include GNUmakefile.preamble
+
+# Include in the rules for making GNUstep frameworks
+include $(GNUSTEP_MAKEFILES)/framework.make
+include $(GNUSTEP_MAKEFILES)/tool.make
+
+-include GNUmakefile.postamble
+
@@ -1,16 +0,0 @@
-//
-// TDBase64.h
-// TouchDB
-//
-// Created by Jens Alfke on 9/14/11.
-// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-@interface TDBase64 : NSObject
-+ (NSString*) encode:(const void*) input length:(size_t) length;
-+ (NSString*) encode:(NSData*) rawBytes;
-+ (NSData*) decode:(const char*) string length:(size_t) inputLength;
-+ (NSData*) decode:(NSString*) string;
-@end
@@ -1,115 +0,0 @@
-//
-// TDBase64.m
-// TouchDB
-//
-// Created by Jens Alfke on 9/14/11.
-// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
-// except in compliance with the License. You may obtain a copy of the License at
-// http://www.apache.org/licenses/LICENSE-2.0
-// Unless required by applicable law or agreed to in writing, software distributed under the
-// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
-// either express or implied. See the License for the specific language governing permissions
-// and limitations under the License.
-
-#import "TDBase64.h"
-
-// Based on public-domain source code by cyrus.najmabadi@gmail.com
-// taken from http://www.cocoadev.com/index.pl?BaseSixtyFour
-
-
-@implementation TDBase64
-
-
-static const uint8_t kEncodingTable[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static int8_t kDecodingTable[256];
-
-+ (void) initialize {
- if (self == [TDBase64 class]) {
- memset(kDecodingTable, 0xFF, sizeof(kDecodingTable));
- for (NSUInteger i = 0; i < sizeof(kEncodingTable); i++) {
- kDecodingTable[kEncodingTable[i]] = (int8_t)i;
- }
- }
-}
-
-
-+ (NSString*) encode: (const void*)input length: (size_t)length {
- if (input == NULL)
- return nil;
- NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
- uint8_t* output = (uint8_t*)data.mutableBytes;
-
- for (NSUInteger i = 0; i < length; i += 3) {
- NSInteger value = 0;
- for (NSUInteger j = i; j < (i + 3); j++) {
- value <<= 8;
-
- if (j < length) {
- value |= ((const uint8_t*)input)[j];
- }
- }
-
- NSInteger index = (i / 3) * 4;
- output[index + 0] = kEncodingTable[(value >> 18) & 0x3F];
- output[index + 1] = kEncodingTable[(value >> 12) & 0x3F];
- output[index + 2] = (i + 1) < length ? kEncodingTable[(value >> 6) & 0x3F] : '=';
- output[index + 3] = (i + 2) < length ? kEncodingTable[(value >> 0) & 0x3F] : '=';
- }
-
- return [[[NSString alloc] initWithData:data
- encoding:NSASCIIStringEncoding] autorelease];
-}
-
-
-+ (NSString*) encode: (NSData*)rawBytes {
- return [self encode: rawBytes.bytes length: rawBytes.length];
-}
-
-
-+ (NSData*) decode: (const char*)string length: (size_t)inputLength {
- if ((string == NULL) || (inputLength % 4 != 0)) {
- return nil;
- }
-
- while (inputLength > 0 && string[inputLength - 1] == '=') {
- inputLength--;
- }
-
- size_t outputLength = inputLength * 3 / 4;
- NSMutableData* data = [NSMutableData dataWithLength:outputLength];
- uint8_t* output = data.mutableBytes;
-
- NSUInteger inputPoint = 0;
- NSUInteger outputPoint = 0;
- while (inputPoint < inputLength) {
- uint8_t i0 = string[inputPoint++];
- uint8_t i1 = string[inputPoint++];
- uint8_t i2 = inputPoint < inputLength ? string[inputPoint++] : 'A'; /* 'A' will decode to \0 */
- uint8_t i3 = inputPoint < inputLength ? string[inputPoint++] : 'A';
-
- if (kDecodingTable[i0] < 0 || kDecodingTable[i1] < 0
- || kDecodingTable[i2] < 0 || kDecodingTable[i3] < 0)
- return nil;
-
- output[outputPoint++] = (uint8_t)((kDecodingTable[i0] << 2) | (kDecodingTable[i1] >> 4));
- if (outputPoint < outputLength) {
- output[outputPoint++] = (uint8_t)(((kDecodingTable[i1] & 0xf) << 4) | (kDecodingTable[i2] >> 2));
- }
- if (outputPoint < outputLength) {
- output[outputPoint++] = (uint8_t)(((kDecodingTable[i2] & 0x3) << 6) | kDecodingTable[i3]);
- }
- }
-
- return data;
-}
-
-
-+ (NSData*) decode:(NSString*) string {
- NSData* ascii = [string dataUsingEncoding: NSASCIIStringEncoding];
- return [self decode: ascii.bytes length: ascii.length];
-}
-
-
-@end
@@ -1,53 +0,0 @@
-//
-// TDRemoteRequest.h
-// TouchDB
-//
-// Created by Jens Alfke on 12/15/11.
-// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-
-/** The signature of the completion block called by a TDRemoteRequest.
- @param result On success, a 'result' object; by default this is the TDRemoteRequest iself, but subclasses may return something else. On failure, this will likely be nil.
- @param error The error, if any, else nil. */
-typedef void (^TDRemoteRequestCompletionBlock)(id result, NSError* error);
-
-
-/** Asynchronous HTTP request; a fairly simple wrapper around NSURLConnection that calls a completion block when ready. */
-@interface TDRemoteRequest : NSObject <NSURLConnectionDelegate
-#if TARGET_OS_IPHONE
- , NSURLConnectionDataDelegate
-#endif
- >
-{
- @protected
- NSMutableURLRequest* _request;
- TDRemoteRequestCompletionBlock _onCompletion;
- NSURLConnection* _connection;
- UInt8 _retryCount;
-}
-
-/** Creates and starts a request; when finished, the onCompletion block will be called. */
-- (id) initWithMethod: (NSString*)method URL: (NSURL*)url body: (id)body
- onCompletion: (TDRemoteRequestCompletionBlock)onCompletion;
-
-// protected:
-- (void) setupRequest: (NSMutableURLRequest*)request withBody: (id)body;
-- (void) start;
-- (void) clearConnection;
-- (void) cancelWithStatus: (int)status;
-- (void) respondWithResult: (id)result error: (NSError*)error;
-
-@end
-
-
-/** A request that parses its response body as JSON.
- The parsed object will be returned as the first parameter of the completion block. */
-@interface TDRemoteJSONRequest : TDRemoteRequest
-{
- @private
- NSMutableData* _jsonBuffer;
-}
-@end
Oops, something went wrong.

0 comments on commit 3881d67

Please sign in to comment.