forked from ccgus/fmdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFMDatabaseAdditionsTests.m
132 lines (98 loc) · 3.75 KB
/
FMDatabaseAdditionsTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
// FMDatabaseAdditionsTests.m
// fmdb
//
// Created by Graham Dennis on 24/11/2013.
//
//
#import <XCTest/XCTest.h>
#import "FMDatabaseAdditions.h"
#if FMDB_SQLITE_STANDALONE
#import <sqlite3/sqlite3.h>
#else
#import <sqlite3.h>
#endif
@interface FMDatabaseAdditionsTests : FMDBTempDBTests
@end
@implementation FMDatabaseAdditionsTests
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testFunkyTableNames
{
[self.db executeUpdate:@"create table '234 fds' (foo text)"];
XCTAssertFalse([self.db hadError], @"table creation should have succeeded");
FMResultSet *rs = [self.db getTableSchema:@"234 fds"];
XCTAssertTrue([rs next], @"Schema should have succeded");
[rs close];
XCTAssertFalse([self.db hadError], @"There shouldn't be any errors");
}
- (void)testBoolForQuery
{
BOOL result = [self.db boolForQuery:@"SELECT ? not null", @""];
XCTAssertTrue(result, @"Empty strings should be considered true");
result = [self.db boolForQuery:@"SELECT ? not null", [NSMutableData data]];
XCTAssertTrue(result, @"Empty mutable data should be considered true");
result = [self.db boolForQuery:@"SELECT ? not null", [NSData data]];
XCTAssertTrue(result, @"Empty data should be considered true");
}
- (void)testIntForQuery
{
[self.db executeUpdate:@"create table t1 (a integer)"];
[self.db executeUpdate:@"insert into t1 values (?)", [NSNumber numberWithInt:5]];
XCTAssertEqual([self.db changes], 1, @"There should only be one change");
int ia = [self.db intForQuery:@"select a from t1 where a = ?", [NSNumber numberWithInt:5]];
XCTAssertEqual(ia, 5, @"foo");
}
- (void)testDateForQuery
{
NSDate *date = [NSDate date];
[self.db executeUpdate:@"create table datetest (a double, b double, c double)"];
[self.db executeUpdate:@"insert into datetest (a, b, c) values (?, ?, 0)" , [NSNull null], date];
NSDate *foo = [self.db dateForQuery:@"select b from datetest where c = 0"];
XCTAssertEqualWithAccuracy([foo timeIntervalSinceDate:date], 0.0, 1.0, @"Dates should be the same to within a second");
}
- (void)testTableExists
{
XCTAssertTrue([self.db executeUpdate:@"create table t4 (a text, b text)"]);
XCTAssertTrue([self.db tableExists:@"t4"]);
XCTAssertFalse([self.db tableExists:@"thisdoesntexist"]);
FMResultSet *rs = [self.db getSchema];
while ([rs next]) {
XCTAssertEqualObjects([rs stringForColumn:@"type"], @"table");
}
}
- (void)testColumnExists
{
[self.db executeUpdate:@"create table nulltest (a text, b text)"];
XCTAssertTrue([self.db columnExists:@"a" inTableWithName:@"nulltest"]);
XCTAssertTrue([self.db columnExists:@"b" inTableWithName:@"nulltest"]);
XCTAssertFalse([self.db columnExists:@"c" inTableWithName:@"nulltest"]);
}
- (void)testUserVersion {
[[self db] setUserVersion:12];
XCTAssertTrue([[self db] userVersion] == 12);
}
- (void)testApplicationID {
#if SQLITE_VERSION_NUMBER >= 3007017
uint32_t appID = NSHFSTypeCodeFromFileType(NSFileTypeForHFSTypeCode('fmdb'));
[self.db setApplicationID:appID];
uint32_t rAppID = [self.db applicationID];
XCTAssertEqual(rAppID, appID);
[self.db setApplicationIDString:@"acrn"];
NSString *s = [self.db applicationIDString];
XCTAssertEqualObjects(s, @"acrn");
#else
NSString *errorMessage = NSLocalizedString(@"Application ID functions require SQLite 3.7.17", nil);
XCTFail("%@", errorMessage);
if (self.db.logsErrors) NSLog(@"%@", errorMessage);
#endif
}
@end