Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ccgus/fmdb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorRobert M. Ryan <robert.ryan@mindspring.com>2017-05-23 09:51:03 +0300
committerRobert M. Ryan <robert.ryan@mindspring.com>2017-05-23 09:51:03 +0300
commit07e0362e60a6cb881efe1cda7e616bf04baf2a84 (patch)
treec3d962274674dd149219a5861c8aadc4b3112b76 /Tests
parent3c4cf5ad84ff167cdb0e7ce61df14ae7979bdc58 (diff)
Implement properties
There were several properties that were implemented as simple getter and setter methods, with no formal property definitions, but with manually defined ivars. In Objective-C this isn't problematic (as the Objective-C "dot" notation is merely syntactic sugar), but it leads to an unintuitive interface for Swift. By shifting these manually implemented getter/setters with manual ivars to properties makes the code a little more intuitive, and leads to more natural looking code in Swift (e.g. rather than `let timeout = db.maxBusyRetryTimeInterval()` and `db.setMaxBusyRetryTimeInterval(value)`, we can just do more natural `let timeout = db.maxBusyRetryTimeoutInterval` and `db.maxBusyRetryTimeInterval = value`. Affected properties include `databasePath`, `maxBusyRetryTimeInterval`, `shouldCacheStatements`, `sqliteHandle`, `hasOpenResultSets`, `lastInsertRowId`, `changes`, `goodConnection`, `columnCount`, `resultDictionary`, `applicationID`, `applicationIDString`, `userVersion`, `countOfCheckedInDatabases`, `countOfCheckedOutDatabases`, and `countOfOpenDatabases`. Also updated documentation for the file URL based methods. Also a few deprecated methods have been updated with `__deprecated_msg` so that the app developers have a fighting chance to see what the replacement method should be. Renamed `isInTransaction`. Fixed a few nullability definitions, e.g. `stringForColumn` (and all the other similar ones that return pointers), `columnNameForIndex`, etc. The `objectForColumn` (and the associated subscript operator) now returns `nil` if an invalid column name/index is passed to it. It used to return `NSNull`. I've created unit tests that test that. Updated README
Diffstat (limited to 'Tests')
-rw-r--r--Tests/FMDatabaseTests.m38
1 files changed, 33 insertions, 5 deletions
diff --git a/Tests/FMDatabaseTests.m b/Tests/FMDatabaseTests.m
index 40ba2a4..2194570 100644
--- a/Tests/FMDatabaseTests.m
+++ b/Tests/FMDatabaseTests.m
@@ -184,17 +184,45 @@
XCTAssertFalse([self.db hadError], @"Shouldn't have any errors");
}
-- (void)testSelectWithIndexedAndKeyedSubscript
+- (void)testInvalidColumnNames
{
FMResultSet *rs = [self.db executeQuery:@"select rowid, a, b, c from test"];
XCTAssertNotNil(rs, @"Should have a non-nil result set");
+ NSString *invalidColumnName = @"foobar";
+
+ while ([rs next]) {
+ XCTAssertNil(rs[invalidColumnName], @"Invalid column name should return nil");
+ XCTAssertNil([rs stringForColumn:invalidColumnName], @"Invalid column name should return nil");
+ XCTAssertEqual([rs UTF8StringForColumn:invalidColumnName], (const unsigned char *)0, @"Invalid column name should return nil");
+ XCTAssertNil([rs dateForColumn:invalidColumnName], @"Invalid column name should return nil");
+ XCTAssertNil([rs dataForColumn:invalidColumnName], @"Invalid column name should return nil");
+ XCTAssertNil([rs dataNoCopyForColumn:invalidColumnName], @"Invalid column name should return nil");
+ XCTAssertNil([rs objectForColumn:invalidColumnName], @"Invalid column name should return nil");
+ }
+
+ [rs close];
+ XCTAssertFalse([self.db hasOpenResultSets], @"Shouldn't have any open result sets");
+ XCTAssertFalse([self.db hadError], @"Shouldn't have any errors");
+}
+
+- (void)testInvalidColumnIndexes
+{
+ FMResultSet *rs = [self.db executeQuery:@"select rowid, a, b, c from test"];
+
+ XCTAssertNotNil(rs, @"Should have a non-nil result set");
+
+ int invalidColumnIndex = 999;
+
while ([rs next]) {
- XCTAssertEqualObjects(rs[0], rs[@"rowid"], @"Column zero should be equal to 'rowid'");
- XCTAssertEqualObjects(rs[1], rs[@"a"], @"Column 1 should be equal to 'a'");
- XCTAssertEqualObjects(rs[2], rs[@"b"], @"Column 2 should be equal to 'b'");
- XCTAssertEqualObjects(rs[3], rs[@"c"], @"Column 3 should be equal to 'c'");
+ XCTAssertNil(rs[invalidColumnIndex], @"Invalid column name should return nil");
+ XCTAssertNil([rs stringForColumnIndex:invalidColumnIndex], @"Invalid column name should return nil");
+ XCTAssertEqual([rs UTF8StringForColumnIndex:invalidColumnIndex], (const unsigned char *)0, @"Invalid column name should return nil");
+ XCTAssertNil([rs dateForColumnIndex:invalidColumnIndex], @"Invalid column name should return nil");
+ XCTAssertNil([rs dataForColumnIndex:invalidColumnIndex], @"Invalid column name should return nil");
+ XCTAssertNil([rs dataNoCopyForColumnIndex:invalidColumnIndex], @"Invalid column name should return nil");
+ XCTAssertNil([rs objectForColumnIndex:invalidColumnIndex], @"Invalid column name should return nil");
}
[rs close];