swig/Examples/test-suite/schemerunme/cpp11_std_unique_ptr.scm

75 lines
2.1 KiB
Scheme

(define checkCount
(lambda (expected-count)
(define actual-count (Klass-getTotal-count))
(unless (= actual-count expected-count) (error (format "Counts incorrect, expected:~a actual:~a" expected-count actual-count)))))
; Test raw pointer handling involving virtual inheritance
(define kini (new-KlassInheritance "KlassInheritanceInput"))
(checkCount 1)
(define s (useKlassRawPtr kini))
(unless (string=? s "KlassInheritanceInput")
(error "Incorrect string: " s))
(delete-Klass kini)
(checkCount 0)
; unique_ptr as input
(define kin (new-Klass "KlassInput"))
(checkCount 1)
(define s (takeKlassUniquePtr kin))
(checkCount 0)
(unless (string=? s "KlassInput")
(error "Incorrect string: " s))
(unless (is-nullptr kin)
(error "is_nullptr failed"))
(delete-Klass kin) ; Should not fail, even though already deleted
(checkCount 0)
(define kin (new-Klass "KlassInput"))
(checkCount 1)
(define s (takeKlassUniquePtr kin))
(checkCount 0)
(unless (string=? s "KlassInput")
(error "Incorrect string: " s))
(unless (is-nullptr kin)
(error "is_nullptr failed"))
(expect-throw 'misc-error
(takeKlassUniquePtr kin))
; TODO: check the exception message
(delete-Klass kin) ; Should not fail, even though already deleted
(checkCount 0)
(define kin (new-Klass "KlassInput"))
(define notowned (get-not-owned-ptr kin))
(expect-throw 'misc-error
(takeKlassUniquePtr notowned))
; TODO: check the exception message
(checkCount 1)
(delete-Klass kin)
(checkCount 0)
(define kini (new-KlassInheritance "KlassInheritanceInput"))
(checkCount 1)
(define s (takeKlassUniquePtr kini))
(checkCount 0)
(unless (string=? s "KlassInheritanceInput")
(error "Incorrect string: " s))
(unless (is-nullptr kini)
(error "is_nullptr failed"))
(delete-Klass kini) ; Should not fail, even though already deleted
(checkCount 0)
; unique_ptr as output
(define k1 (makeKlassUniquePtr "first"))
(define k2 (makeKlassUniquePtr "second"))
(checkCount 2)
(delete-Klass k1)
(checkCount 1)
(unless (string=? (Klass-getLabel k2) "second")
(error "wrong object label" ))
(delete-Klass k2)
(checkCount 0)
(exit 0)