| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 
 | # uuid.test:  tests for the uuid package                       -*- tcl -*-
#
# $Id: uuid.test,v 1.3 2005/10/05 08:41:54 patthoyts Exp $
# -------------------------------------------------------------------------
# Initialize the test package
#
if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest
    namespace import ::tcltest::*
}
# -------------------------------------------------------------------------
# Ensure we test _this_ local copy and one installed somewhere else.
#
package forget uuid
catch {namespace delete ::uuid}
if {[catch {source [file join [file dirname [info script]] uuid.tcl]} msg]} {
    puts "skipped [file tail [info script]]: $msg"
    return
}
# -------------------------------------------------------------------------
# Handle multiple implementation testing
#
array set preserve [array get ::uuid::accel]
proc implementations {} {
    variable ::uuid::accel
    foreach {a v} [array get accel] {if {$v} {lappend r $a}}
    lappend r tcl; set r
}
proc select_implementation {impl} {
    variable ::uuid::accel
    foreach e [array names accel] { set accel($e) 0 }
    if {[string compare "tcl" $impl] != 0} {
        set accel($impl) 1
    }
}
proc reset_implementation {} {
    variable ::uuid::accel
    array set accel [array get ::preserve]
}
# -------------------------------------------------------------------------
# Setup any constraints
#
# -------------------------------------------------------------------------
# Now the package specific tests....
# -------------------------------------------------------------------------
if {[::uuid::LoadAccelerator critcl]} {
    puts "- uuid [package present uuid] (critcl based)"
}
puts "- uuid [package present uuid] (pure Tcl)"
# -------------------------------------------------------------------------
foreach impl [implementations] {
    select_implementation $impl
    test uuid-1.0-$impl "uuid requires args" {
        list [catch {uuid::uuid} msg]
    } {1}
    
    test uuid-1.1-$impl "uuid generate should create a 36 char string uuid" {
        list [catch {string length [uuid::uuid generate]} msg] $msg
    } {0 36}
    
    test uuid-1.2-$impl "uuid comparison of uuid with self should be true" {
        list [catch {
            set a [uuid::uuid generate]
            uuid::uuid equal $a $a
        } msg] $msg
    } {0 1}
    
    test uuid-1.3-$impl "uuid comparison of two different\
        uuids should be false" {
        list [catch {
            set a [uuid::uuid generate]
            set b [uuid::uuid generate]
            uuid::uuid equal $a $b
        } msg] $msg
    } {0 0}
    
    reset_implementation
}
# -------------------------------------------------------------------------
::tcltest::cleanupTests
# -------------------------------------------------------------------------
# Local Variables:
#   mode: tcl
#   indent-tabs-mode: nil
# End:
 |