# # 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.2 2002/04/02 02:29:43 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