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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#
# msgcat.test
#
# Tests for the XPG/3 message catalog commands.
#---------------------------------------------------------------------------
# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies. Karl Lehenbauer and
# Mark Diekhans make no representations about the suitability of this
# software for any purpose. It is provided "as is" without express or
# implied warranty.
#------------------------------------------------------------------------------
# $Id: msgcat.test,v 1.3 2002/04/04 06:10:30 hobbs Exp $
#------------------------------------------------------------------------------
if {[cequal [info procs Test] {}]} {
source [file join [file dirname [info script]] testlib.tcl]
}
#
# This only tests default strings, since its difficult to setup and rely on
# a message catalog being present. This will work on systems without message
# catalogs, as the stubs return default strings.
#
test message-cat-1.1 {catopen tests} {
set msgcat [catopen "FOOBAZWAP"]
catclose $msgcat
crange $msgcat 0 5
} {msgcat}
test message-cat-1.2 {catopen tests} {
set msgcat [catopen -nofail "FOOBAZWAP"]
catclose $msgcat
crange $msgcat 0 5
} {msgcat}
test message-cat-1.3 {catopen tests} {
list [catch {catopen -fail "FOOBAZWAP"} msg] $msg
switch -exact $msg {
"open of message catalog failed" -
"the message catalog facility is not available, default string is always returned" {concat "OK"}
default {
# This will fail on Linux and FreeBSD, where the catopen libc
# function exhibits non-standard behavior. This is should not be
# a problem for most developers, so fake the OK.
if {[regexp Linux|FreeBSD $::tcl_platform(os)] && \
($msg == "msgcat0")} {
concat "OK"
} else {
concat "Bad catopen return: $msg"
}
}
}
} {OK}
test message-cat-2.1 {catclose tests} {
set msgcat [catopen "FOOBAZWAP"]
catclose $msgcat
list [catch {catgets $msgcat} msg] $msg
} {1 {wrong # args: catgets catHandle setnum msgnum defaultstr}}
test message-cat-2.2 {catclose tests} {
set msgcat [catopen "FOOBAZWAP"]
catclose $msgcat
} {}
test message-cat-2.3 {catclose tests} {
set msgcat [catopen "FOOBAZWAP"]
catclose -nofail $msgcat
} {}
test message-cat-2.4 {catclose tests} {
set msgcat [catopen "FOOBAZWAP"]
catclose $msgcat
list [catch {catclose -fail $msgcat} msg] $msg
} {1 {msgcat is not open}}
test message-cat-2.5 {catclose tests} {
list [catch {catclose baz} msg] $msg
} {1 {invalid msgcat handle "baz"}}
test message-cat-2.6 {catclose tests} {
list [catch {catclose} msg] $msg
} {1 {wrong # args: catclose ?-fail|-nofail? catHandle}}
test message-cat-3.1 {catgets tests} {
set msgcat [catopen "FOOBAZWAP"]
catgets $msgcat 1 12 "This is a test"
} {This is a test}
catch {catclose $msgcat}
test message-cat-3.2 {catgets tests} {
set msgcat [catopen "FOOBAZWAP"]
catgets $msgcat 101 12 "This is an actual emergency"
} {This is an actual emergency}
catch {catclose $msgcat}
test message-cat-3.3 {catgets tests} {
set msgcat [catopen "FOOBAZWAP"]
catclose $msgcat
list [catch {catgets $msgcat 101 12 "This is an actual emergency"} msg] \
$msg
} {1 {msgcat is not open}}
test message-cat-3.4 {catgets tests} {
set msgcat [catopen "FOOBAZWAP"]
list [catch {catgets $msgcat xx 12 "This is an actual emergency"} msg] $msg
} {1 {expected integer but got "xx"}}
catch {catclose $msgcat}
test message-cat-3.5 {catgets tests} {
set msgcat [catopen "FOOBAZWAP"]
list [catch {catgets $msgcat 102 "This is an actual emergency"} msg] $msg
} {1 {wrong # args: catgets catHandle setnum msgnum defaultstr}}
catch {catclose $msgcat}
# cleanup
::tcltest::cleanupTests
return
|