File: imei.test

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (85 lines) | stat: -rw-r--r-- 2,490 bytes parent folder | download | duplicates (8)
1
2
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
# -------------------------------------------------------------------------
# imei.test -*- tcl -*-
# (C) 2011 Andreas Kupries. BSD licensed.
# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.5
testsNeedTcltest 2.0

support {
    use      snit/snit2.tcl snit            ;# snit v2 fixed, due Tcl 8.5
    useLocal valtype.tcl    valtype::common
    useLocal luhn.tcl valtype::luhn
}
testing {
    useLocal imei.tcl valtype::imei
}

# -------------------------------------------------------------------------

test valtype-imei-1.0 {imei validation wrong\#args} -body {
    valtype::imei validate
} -returnCodes error \
    -result {wrong # args: should be "valtype::imei validate value"}

test valtype-imei-1.1 {imei validation wrong\#args} -body {
    valtype::imei validate A B C
} -returnCodes error \
    -result {wrong # args: should be "valtype::imei validate value"}

# -------------------------------------------------------------------------

test valtype-imei-2.0 {imei validation failure, bad char} -body {
    valtype::imei validate ABCDEFGHIJKLMNO
} -returnCodes error \
    -result {Not an IMEI number, expected only digits}

test valtype-imei-2.1 {imei validation failure, bad length} -body {
    valtype::imei validate 32
} -returnCodes error \
    -result {Not an IMEI number, incorrect length, expected 15 characters}

foreach {n in} {
    1  000000000000001
    2  100000000000000
    3  000000000000010
    4  012345678901230
    5  321098765432100
} {
    test valtype-imei-3.1 {imei validation failure, bad check} -body {
	valtype::imei validate $in
    } -returnCodes error \
	-result {Not an IMEI number, the check digit is incorrect}
}

# -------------------------------------------------------------------------

foreach {n in check} {
    1 00000000000000  0
    2 10000000000000  9
    3 00000000000001  8
    4 01234567890123  7
    5 32109876543210  5
} {
    test valtype-imei-4.$n {imei validation} -body {
	valtype::imei validate $in$check
    } -result $in$check

    test valtype-imei-6.$n {imei checkdigit} -body {
	# IMEI = luhn check of 15-digit number (incl. check digit)
	valtype::luhn checkdigit $in
    } -result $check
}

# -------------------------------------------------------------------------
testsuiteCleanup
return

# Local Variables:
#  mode: tcl
#  indent-tabs-mode: nil
# End: