Files
swift-atomics/Tests/AtomicsTests/UnsafeAtomicLazyReference.swift
T
Saleem Abdulrasool c711547ac1 Tests: add XCTest manifest for non-SPM based builds
This allows for testing without SPM on non-Darwin targets.  We
explicitly exclude the manifest in SPM based builds because we would
like to use the automatic test discovery functionality from SPM.
2021-04-29 14:43:21 -07:00

48 lines
1.4 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import XCTest
import Atomics
class UnsafeAtomicLazyReferenceTests: XCTestCase {
func test_create_destroy() {
let v = UnsafeAtomicLazyReference<LifetimeTracked>.create()
defer { v.destroy() }
XCTAssertNil(v.load())
}
func test_storeIfNilThenLoad() {
do {
let v = UnsafeAtomicLazyReference<LifetimeTracked>.create()
XCTAssertNil(v.load())
let ref = LifetimeTracked(42)
XCTAssertTrue(v.storeIfNilThenLoad(ref) === ref)
XCTAssertTrue(v.load() === ref)
let ref2 = LifetimeTracked(23)
XCTAssertTrue(v.storeIfNilThenLoad(ref2) === ref)
XCTAssertTrue(v.load() === ref)
v.destroy()
}
XCTAssertEqual(LifetimeTracked.instances, 0)
}
#if !SWIFT_PACKAGE
public static var allTests = [
("test_create_destroy", test_create_destroy),
("test_storeIfNilThenLoad", test_storeIfNilThenLoad),
]
#endif
}