Dactyloidae iOS initial commit

This commit is contained in:
wuggy 2026-06-26 21:04:09 -07:00
commit 7154a0497e
2123 changed files with 197052 additions and 0 deletions

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>10.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View file

@ -0,0 +1,126 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@testable import ReadingList
import Foundation
import XCTest
class ReadingListClientRecordTestCase: XCTestCase {
func testInitWithRow() {
let now = ReadingListNow()
let row: [String: Any] = [
"client_id": Int64(1234),
"client_last_modified": now,
"id": "5DB5597A-8E60-454D-B1F5-51810C2A5FFE",
"last_modified": now,
"url": "http://localhost/article/1",
"title": "Article 1",
"added_by": "Stefan's iPhone",
"unread": true,
"archived": false,
"favorite": true
]
let record = ReadingListClientRecord(row: row)
XCTAssert(record != nil)
if let record = record {
XCTAssertEqual(record.url, "http://localhost/article/1")
XCTAssertEqual(record.title, "Article 1")
XCTAssertEqual(record.addedBy, "Stefan's iPhone")
XCTAssertEqual(record.unread, true)
XCTAssertEqual(record.archived, false)
XCTAssertEqual(record.favorite, true)
XCTAssert(record.clientMetadata.id == 1234)
XCTAssert(record.clientMetadata.lastModified == now)
XCTAssert(record.serverMetadata != nil)
XCTAssertEqual(record.serverMetadata!.guid, "5DB5597A-8E60-454D-B1F5-51810C2A5FFE")
XCTAssertEqual(record.serverMetadata!.lastModified, now)
}
}
func testInitWithRowWithoutServerMeta() {
let now = ReadingListNow()
let row: [String:Any] = [
"client_id": Int64(1234),
"client_last_modified": now,
"url": "http://localhost/article/1",
"title": "Article 1",
"added_by": "Stefan's iPhone",
"unread": true,
"archived": false,
"favorite": true
]
let record = ReadingListClientRecord(row: row)
XCTAssert(record != nil)
if let record = record {
XCTAssertEqual(record.url, "http://localhost/article/1")
XCTAssertEqual(record.title, "Article 1")
XCTAssertEqual(record.addedBy, "Stefan's iPhone")
XCTAssertEqual(record.unread, true)
XCTAssertEqual(record.archived, false)
XCTAssertEqual(record.favorite, true)
XCTAssert(record.clientMetadata.id == 1234)
XCTAssert(record.clientMetadata.lastModified == now)
XCTAssert(record.serverMetadata == nil)
}
}
func testInitWithEmptyRow() {
let row = NSDictionary()
let record = ReadingListClientRecord(row: row as! [String : Any])
XCTAssert(record == nil)
}
// func testInit() {
// let record = ReadingListClientRecord(url: "http://localhost/some/article", title: "Some Article", addedBy: "Stefan's iPad Mini")
// XCTAssertNil(record.clientMetadata.id)
// XCTAssert(record.clientMetadata.lastModified != 0)
// XCTAssert(record.serverMetadata == nil)
// XCTAssertEqual(record.url, "http://localhost/some/article")
// XCTAssertEqual(record.title, "Some Article")
// XCTAssertEqual(record.addedBy, "Stefan's iPad Mini")
// XCTAssertEqual(record.unread, ReadingListDefaultUnread)
// XCTAssertEqual(record.favorite, ReadingListDefaultFavorite)
// XCTAssertEqual(record.archived, ReadingListDefaultArchived)
// }
func testJSON() {
let now = ReadingListNow()
let row: [String:Any] = [
"client_id": Int64(1234),
"client_last_modified": now,
"id": "5DB5597A-8E60-454D-B1F5-51810C2A5FFE",
"last_modified": now,
"url": "http://localhost/article/1",
"title": "Article 1",
"added_by": "Stefan's iPhone 3GS",
"unread": true,
"archived": false,
"favorite": true
]
let record = ReadingListClientRecord(row: row)
XCTAssert(record != nil)
if let record = record {
let json: AnyObject = record.json
XCTAssertEqual(json.value(forKeyPath: "url") as? String, "http://localhost/article/1")
XCTAssertEqual(json.value(forKeyPath: "title") as? String, "Article 1")
XCTAssertEqual(json.value(forKeyPath: "added_by") as? String, "Stefan's iPhone 3GS")
XCTAssertEqual(json.value(forKeyPath: "unread") as? Bool, true)
XCTAssertEqual(json.value(forKeyPath: "archived") as? Bool, false)
XCTAssertEqual(json.value(forKeyPath: "favorite") as? Bool, true)
}
}
}

View file

@ -0,0 +1,195 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@testable import ReadingList
import Foundation
import Shared
import XCTest
class ReadingListStorageTestCase: XCTestCase {
var storage: ReadingListStorage!
override func setUp() {
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
if FileManager.default.fileExists(atPath: "\(path)/ReadingList.db") {
do {
try FileManager.default.removeItem(atPath: "\(path)/ReadingList.db")
} catch _ {
XCTFail("Cannot remove old \(path)/ReadingList.db")
}
}
storage = ReadingListSQLStorage(path: "\(path)/ReadingList.db")
}
func testCreateRecord() {
let result = storage.createRecordWithURL("http://www.anandtech.com/show/9117/analyzing-intel-core-m-performance", title: "Analyzing Intel Core M Performance: How 5Y10 can beat 5Y71 & the OEMs' Dilemma", addedBy: "Stefan's iPhone")
switch result {
case .failure(let error):
XCTFail(error.description)
case .success(let result):
XCTAssertEqual(result.value.url, "http://www.anandtech.com/show/9117/analyzing-intel-core-m-performance")
XCTAssertEqual(result.value.title, "Analyzing Intel Core M Performance: How 5Y10 can beat 5Y71 & the OEMs' Dilemma")
XCTAssertEqual(result.value.addedBy, "Stefan's iPhone")
XCTAssertEqual(result.value.unread, true)
XCTAssertEqual(result.value.archived, false)
XCTAssertEqual(result.value.favorite, false)
}
}
func testGetRecordWithURL() {
let result1 = storage.createRecordWithURL("http://www.anandtech.com/show/9117/analyzing-intel-core-m-performance", title: "Analyzing Intel Core M Performance: How 5Y10 can beat 5Y71 & the OEMs' Dilemma", addedBy: "Stefan's iPhone")
switch result1 {
case .failure(let error):
XCTFail(error.description)
case .success( _):
break
}
let result2 = storage.getRecordWithURL("http://www.anandtech.com/show/9117/analyzing-intel-core-m-performance")
switch result2 {
case .failure(let error):
XCTFail(error.description)
case .success( _):
XCTAssert(result1.successValue == result2.successValue!)
}
}
func testGetUnreadRecords() {
// Create 3 records, mark the 2nd as read.
let _ = createRecordWithURL("http://localhost/article1", title: "Test 1", addedBy: "Stefan's iPhone")
let createResult2 = createRecordWithURL("http://localhost/article2", title: "Test 2", addedBy: "Stefan's iPhone")
let _ = createRecordWithURL("http://localhost/article3", title: "Test 3", addedBy: "Stefan's iPhone")
if let record = createResult2.successValue {
let _ = updateRecord(record, unread: false)
}
// Get all unread records, make sure we only get the first and last
let getUnreadResult = storage.getUnreadRecords()
if let records = getUnreadResult.successValue {
XCTAssertEqual(2, records.count)
for record in records {
XCTAssert(record.title == "Test 1" || record.title == "Test 3")
XCTAssertEqual(record.unread, true)
}
}
}
func testGetAllRecords() {
let _ = createRecordWithURL("http://localhost/article1", title: "Test 1", addedBy: "Stefan's iPhone")
let createResult2 = createRecordWithURL("http://localhost/article2", title: "Test 2", addedBy: "Stefan's iPhone")
let _ = createRecordWithURL("http://localhost/article3", title: "Test 3", addedBy: "Stefan's iPhone")
if let record = createResult2.successValue {
let _ = updateRecord(record, unread: false)
}
let getAllResult = storage.getAllRecords()
if let records = getAllResult.successValue {
XCTAssertEqual(3, records.count)
}
}
func testGetNewRecords() {
let _ = createRecordWithURL("http://localhost/article1", title: "Test 1", addedBy: "Stefan's iPhone")
let _ = createRecordWithURL("http://localhost/article2", title: "Test 2", addedBy: "Stefan's iPhone")
let _ = createRecordWithURL("http://localhost/article3", title: "Test 3", addedBy: "Stefan's iPhone")
let getAllResult = getAllRecords()
if let records = getAllResult.successValue {
XCTAssertEqual(3, records.count)
}
// TODO When we are able to create records coming from the server, we can extend this test to see if we query correctly
}
func testDeleteRecord() {
let result1 = storage.createRecordWithURL("http://www.anandtech.com/show/9117/analyzing-intel-core-m-performance", title: "Analyzing Intel Core M Performance: How 5Y10 can beat 5Y71 & the OEMs' Dilemma", addedBy: "Stefan's iPhone")
switch result1 {
case .failure(let error):
XCTFail(error.description)
case .success(_):
break
}
let result2 = storage.deleteRecord(result1.successValue!)
switch result2 {
case .failure(let error):
XCTFail(error.description)
case .success:
break
}
let result3 = storage.getRecordWithURL("http://www.anandtech.com/show/9117/analyzing-intel-core-m-performance")
switch result3 {
case .failure(let error):
XCTFail(error.description)
case .success(let result):
XCTAssert(result.value == nil)
}
}
func testDeleteAllRecords() {
let _ = createRecordWithURL("http://localhost/article1", title: "Test 1", addedBy: "Stefan's iPhone")
let _ = createRecordWithURL("http://localhost/article2", title: "Test 2", addedBy: "Stefan's iPhone")
let _ = createRecordWithURL("http://localhost/article3", title: "Test 3", addedBy: "Stefan's iPhone")
let getAllResult1 = storage.getAllRecords()
if let records = getAllResult1.successValue {
XCTAssertEqual(3, records.count)
}
let _ = deleteAllRecords()
let getAllResult2 = getAllRecords()
if let records = getAllResult2.successValue {
XCTAssertEqual(0, records.count)
}
}
func testUpdateRecord() {
let result = createRecordWithURL("http://www.anandtech.com/show/9117/analyzing-intel-core-m-performance", title: "Analyzing Intel Core M Performance: How 5Y10 can beat 5Y71 & the OEMs' Dilemma", addedBy: "Stefan's iPhone")
if let record = result.successValue {
XCTAssertEqual(record.url, "http://www.anandtech.com/show/9117/analyzing-intel-core-m-performance")
XCTAssertEqual(record.title, "Analyzing Intel Core M Performance: How 5Y10 can beat 5Y71 & the OEMs' Dilemma")
XCTAssertEqual(record.addedBy, "Stefan's iPhone")
XCTAssertEqual(record.unread, true)
XCTAssertEqual(record.archived, false)
XCTAssertEqual(record.favorite, false)
let result = updateRecord(record, unread: false)
if let record = result.successValue! {
XCTAssertEqual(record.url, "http://www.anandtech.com/show/9117/analyzing-intel-core-m-performance")
XCTAssertEqual(record.title, "Analyzing Intel Core M Performance: How 5Y10 can beat 5Y71 & the OEMs' Dilemma")
XCTAssertEqual(record.addedBy, "Stefan's iPhone")
XCTAssertEqual(record.unread, false)
XCTAssertEqual(record.archived, false)
XCTAssertEqual(record.favorite, false)
}
}
}
// Helpers that croak if the storage call was not successful
func createRecordWithURL(_ url: String, title: String, addedBy: String) -> Maybe<ReadingListClientRecord> {
let result = storage.createRecordWithURL(url, title: title, addedBy: addedBy)
XCTAssertTrue(result.isSuccess)
return result
}
func deleteAllRecords() -> Maybe<Void> {
let result = storage.deleteAllRecords()
XCTAssertTrue(result.isSuccess)
return result
}
func getAllRecords() -> Maybe<[ReadingListClientRecord]> {
let result = storage.getAllRecords()
XCTAssertTrue(result.isSuccess)
return result
}
func updateRecord(_ record: ReadingListClientRecord, unread: Bool) -> Maybe<ReadingListClientRecord?> {
let result = storage.updateRecord(record, unread: unread)
XCTAssertTrue(result.isSuccess)
return result
}
}