Fixed bugs found for the bitmap mask, JSON reader and wifi wrappers in the library.
This commit is contained in:
@@ -127,6 +127,23 @@ struct WrapperTests {
|
||||
#expect(UnsafePointer(Mock.tilesPointer) == storage)
|
||||
}
|
||||
|
||||
@Test func bitmapMaskIsFreedAndKeepsItsBitmapAlive() {
|
||||
weak var weakBitmap: Graphics.Bitmap?
|
||||
var mask: Graphics.Bitmap?
|
||||
do {
|
||||
let bitmap = Graphics.Bitmap(width: 8, height: 8)
|
||||
weakBitmap = bitmap
|
||||
mask = bitmap.mask
|
||||
}
|
||||
#expect(mask != nil)
|
||||
#expect(weakBitmap != nil) // the mask keeps it alive
|
||||
#expect(Mock.eventCount("freeBitmap") == 0)
|
||||
|
||||
mask = nil
|
||||
#expect(weakBitmap == nil)
|
||||
#expect(Mock.eventCount("freeBitmap") == 2) // the mask, then the bitmap
|
||||
}
|
||||
|
||||
// MARK: Sprite
|
||||
|
||||
@Test func spriteUserdataRecoversWrapperInCallbacks() {
|
||||
@@ -385,13 +402,14 @@ struct WrapperTests {
|
||||
}
|
||||
|
||||
@Test func jsonDecodeFileReadsThroughTheHandleAndClosesIt() throws {
|
||||
Mock.fileReadLimit = 5
|
||||
Mock.fileBytesRemaining = 20
|
||||
let value = try JSON.decodeFile(path: "save.json")
|
||||
guard case .null = value else {
|
||||
Issue.record("expected .null, got \(value)")
|
||||
return
|
||||
}
|
||||
#expect(Mock.events.contains("decode(5)"))
|
||||
// End of file reaches the decoder as 0, not -1.
|
||||
#expect(Mock.events.contains("decode(total:20,end:0)"))
|
||||
#expect(Mock.eventCount("close") == 1)
|
||||
}
|
||||
|
||||
@@ -417,6 +435,20 @@ struct WrapperTests {
|
||||
#expect(throws: PlaydateError.self) { try handle.read(length: 8) }
|
||||
}
|
||||
|
||||
// MARK: Network
|
||||
|
||||
@Test func networkDisableRegistersNoCallbackSoEnableGetsItsOwnResult() {
|
||||
var results: [String] = []
|
||||
Network.disable()
|
||||
#expect(Mock.events.last == "setEnabled(false,nil)")
|
||||
|
||||
Network.enable { error in results.append(error == nil ? "ok" : "failed") }
|
||||
#expect(Mock.events.last == "setEnabled(true,callback)")
|
||||
|
||||
Mock.networkEnabledCallback?(NET_OK)
|
||||
#expect(results == ["ok"])
|
||||
}
|
||||
|
||||
// MARK: JSON
|
||||
|
||||
@Test func jsonDecodeBuildsTheValueTree() throws {
|
||||
|
||||
Reference in New Issue
Block a user