1
0
Fork 0
gobject-generator/regression/tier2/InterfaceSmoke.swift

51 lines
2.3 KiB
Swift

// InterfaceSmoke.swift
// Tier-2-only runtime smoke tests for Gio interface value construction
// (Phase E1). Proves against the REAL libgio, linked at runtime that:
// 1. a C call returning an interface-typed value (`GFile*` via
// `g_vfs_get_file_for_path`) is bound as `any File`, backed by the
// concrete `FileRef` wrapper (`init(retaining:)` / `init(takingOwnership:)`
// / `isolated deinit` around `g_object_ref`/`g_object_unref`);
// 2. calling an interface method through that value (`File.getPath()`, a
// protocol-extension DEFAULT implementation dispatching through
// `self.pointer`) reaches the real C symbol and returns the correct
// result.
//
// Not generated. `scripts/smoke-test.sh <tier>` copies tier 1 and the selected
// tier's fixtures for tiers 2 through 5. Tier 6/all copies every tier's fixtures
// into one full-stack SmokeTests target. Only installed for tier >= 2.
import Testing
import GLib
import GObject
import Gio
@Suite("Tier 2 interface smoke tests")
struct InterfaceSmokeTests {
@Test("Vfs.getFileForPath returns an any File backed by FileRef, and getPath() round-trips through the real C call")
func fileInterfaceValueConstructionAndDispatch() throws {
let vfs = Vfs.getDefault()
let file: File = vfs.getFileForPath(path: "/tmp/x")
// Interface value construction: `any File` was constructed from a raw
// C pointer via the concrete `FileRef` wrapper this compiles and
// runs only because Phase E1 gives interfaces a constructible type.
#expect(file is FileRef)
// Interface method dispatch: `getPath()` is a protocol-extension
// default implementation, not a witness on a concrete class it
// must still reach `g_file_get_path` through `self.pointer` and
// return the real path.
#expect(file.getPath() == "/tmp/x")
}
@Test("File.getUri() also dispatches through the protocol extension default")
func fileInterfaceSecondMethodDispatch() throws {
let vfs = Vfs.getDefault()
let file = vfs.getFileForPath(path: "/tmp/y")
// Any URI Gio assigns for a local path always carries the path
// itself, proving the call reached the real GVfs/GFile machinery
// rather than returning a stub/placeholder.
#expect(file.getUri().contains("/tmp/y"))
}
}