|
8 | 8 |
|
9 | 9 | import UIKit
|
10 | 10 | import XCTest
|
| 11 | +import YTKKeyValueStore_Swift |
11 | 12 |
|
12 | 13 | class YTKKeyValueStore_SwiftTests: XCTestCase {
|
13 | 14 |
|
| 15 | + private var _store : YTKKeyValueStore_Swift? |
| 16 | + private var _tableName : String? |
| 17 | + |
14 | 18 | override func setUp() {
|
15 | 19 | super.setUp()
|
16 |
| - // Put setup code here. This method is called before the invocation of each test method in the class. |
| 20 | + _tableName = "test_table" |
| 21 | + _store = YTKKeyValueStore_Swift() |
| 22 | + _store?.createTable(tableName: _tableName!) |
| 23 | + _store?.clearTable(tableName: _tableName!) |
17 | 24 | }
|
18 | 25 |
|
19 | 26 | override func tearDown() {
|
20 |
| - // Put teardown code here. This method is called after the invocation of each test method in the class. |
| 27 | + _store?.clearTable(tableName: _tableName) |
| 28 | + _store?.close() |
| 29 | + _store = nil |
21 | 30 | super.tearDown()
|
22 | 31 | }
|
23 | 32 |
|
24 |
| - func testExample() { |
25 |
| - // This is an example of a functional test case. |
26 |
| - XCTAssert(true, "Pass") |
| 33 | + func testSaveString(){ |
| 34 | + |
| 35 | + let str1 = "abc" |
| 36 | + let key1 = "key1" |
| 37 | + let str2 = "abc2" |
| 38 | + let key2 = "key2" |
| 39 | + |
| 40 | + _store?.putString(str1, withId: key1, intoTable: _tableName) |
| 41 | + _store?.putString(str2, withId: key2, intoTable: _tableName) |
| 42 | + |
| 43 | + var result : String? |
| 44 | + |
| 45 | + result = _store?.getStringById(key1, fromTable: _tableName) |
| 46 | + XCTAssertNotNil(result) |
| 47 | + XCTAssertEqual(str1, result!) |
| 48 | + |
| 49 | + result = _store?.getStringById(key2, fromTable: _tableName) |
| 50 | + XCTAssertNotNil(result) |
| 51 | + XCTAssertEqual(str2, result!) |
| 52 | + |
| 53 | + result = _store?.getStringById("key3", fromTable: _tableName) |
| 54 | + XCTAssertNil(result) |
| 55 | + |
27 | 56 | }
|
28 | 57 |
|
29 |
| - func testPerformanceExample() { |
30 |
| - // This is an example of a performance test case. |
31 |
| - self.measureBlock() { |
32 |
| - // Put the code you want to measure the time of here. |
33 |
| - } |
| 58 | + func testSaveCGFloat(){ |
| 59 | + |
| 60 | + let num1 : CGFloat = 1 |
| 61 | + let key1 = "key1" |
| 62 | + let num2 : CGFloat = 2 |
| 63 | + let key2 = "key2" |
| 64 | + |
| 65 | + _store?.putNumber(num1, withId: key1, intoTable: _tableName) |
| 66 | + _store?.putNumber(num2, withId: key2, intoTable: _tableName) |
| 67 | + |
| 68 | + var result : CGFloat? |
| 69 | + |
| 70 | + result = _store?.getNumberById(key1, fromTable: _tableName) |
| 71 | + XCTAssertNotNil(result) |
| 72 | + XCTAssertEqual(num1, result!) |
| 73 | + |
| 74 | + result = _store?.getNumberById(key2, fromTable: _tableName) |
| 75 | + XCTAssertNotNil(result) |
| 76 | + XCTAssertEqual(num2, result!) |
| 77 | + |
| 78 | + result = _store?.getNumberById("key3", fromTable: _tableName) |
| 79 | + XCTAssertNil(result) |
| 80 | + |
34 | 81 | }
|
35 | 82 |
|
36 | 83 | }
|
0 commit comments