# -*- tcl -*- # xsxp.test: tests for the xsxp package. # This file contains a collection of tests for the xsxp # package. Sourcing this file into Tcl runs the tests and generates # output for errors. No output means no errors were found. # Copyright (c) 2006,2008 Darren New. All Rights Reserved. # Copyright (c) 2008 Andreas Kupries # (Boilerplate stuff (header, footer)) # All rights reserved. # # RCS: @(#) $Id: xsxp.test,v 1.3 2008/09/04 02:11:13 andreas_kupries Exp $ # ------------------------------------------------------------------------- source [file join \ [file dirname [file dirname [file join [pwd] [info script]]]] \ devtools testutilities.tcl] testsNeedTcl 8.5 testsNeedTcltest 2.0 if {[catch {package require xml}]} { puts " Aborting the tests found in \"[file tail [info script]]\"" puts " Requiring xml package, not found." return } support { # Requires xml (TclXML) } testing { useLocal xsxp.tcl xsxp } # ------------------------------------------------------------------------- package require -exact xsxp 1.0 tcltest::configure -verbose {body error pass} tcltest::configure -debug 1 set setup_one { set xml { 9fb13c24488e3d7556693247d5a463c1837c3c8ede28f4094228e6c4eb5d70bddnew@san.rr.com9fb13c24488e3d7556693247d5a463c1837c3c8ede28f4094228e6c4eb5d70bddnew@san.rr.comFULL_CONTROL} } tcltest::test xsxp-1.10 {Basic parsing} -setup $setup_one -body { set pxml [::xsxp::parse $xml] return [lindex $pxml 0] } -result {AccessControlPolicy} tcltest::test xsxp-1.20 {Precision parsing} -setup $setup_one -body { return [::xsxp::parse $xml] } -result {AccessControlPolicy {} {Owner {} {ID {} {%PCDATA {} 9fb13c24488e3d7556693247d5a463c1837c3c8ede28f4094228e6c4eb5d70bd}} {DisplayName {} {%PCDATA {} dnew@san.rr.com}}} {AccessControlList {} {Grant {} {Grantee {xsi:type CanonicalUser} {ID {} {%PCDATA {} 9fb13c24488e3d7556693247d5a463c1837c3c8ede28f4094228e6c4eb5d70bd}} {DisplayName {} {%PCDATA {} dnew@san.rr.com}}} {Permission {} {%PCDATA {} FULL_CONTROL}}}}} tcltest::test xsxp-1.30 {Test pretty printing} -setup $setup_one -body { ::xsxp::prettyprint [::xsxp::parse $xml] } -output {AccessControlPolicy Owner ID %PCDATA: 9fb13c24488e3d7556693247d5a463c1837c3c8ede28f4094228e6c4eb5d70bd DisplayName %PCDATA: dnew@san.rr.com AccessControlList Grant Grantee xsi:type='CanonicalUser' ID %PCDATA: 9fb13c24488e3d7556693247d5a463c1837c3c8ede28f4094228e6c4eb5d70bd DisplayName %PCDATA: dnew@san.rr.com Permission %PCDATA: FULL_CONTROL } tcltest::test xsxp-1.40 {Access via path string} -setup $setup_one -body { set pxml [::xsxp::parse $xml] return [::xsxp::fetch $pxml "Owner/DisplayName" %PCDATA] } -result {dnew@san.rr.com} tcltest::test xsxp-1.50 {Access via path list} -setup $setup_one -body { set pxml [::xsxp::parse $xml] return [::xsxp::fetch $pxml "Owner DisplayName" %PCDATA] } -result {dnew@san.rr.com} set setup_two { set xml { darren1000falset1.jpg2006-10-27T23:19:07.000Z"a251eabc2e69e9716878924b6ec291c7"15125459fb13c24488e3d7556693247d5a463c1837c3c8ede28f4094228e6c4eb5d70bddnew@san.rr.comSTANDARDt2.jpg2006-10-27T23:19:44.000Z"ebc9b242811239ada85f202346353f31"18260629fb13c24488e3d7556693247d5a463c1837c3c8ede28f4094228e6c4eb5d70bddnew@san.rr.comSTANDARD} set pxml [::xsxp::parse $xml] } tcltest::test xsxp-2.10 {Fetch top-level item} -setup $setup_two -body { ::xsxp::fetch $pxml MaxKeys } -result {MaxKeys {} {%PCDATA {} 1000}} set c0 {Contents {} {Key {} {%PCDATA {} t1.jpg}} {LastModified {} {%PCDATA {} 2006-10-27T23:19:07.000Z}} {ETag {} {%PCDATA {} {"a251eabc2e69e9716878924b6ec291c7"}}} {Size {} {%PCDATA {} 1512545}} {Owner {} {ID {} {%PCDATA {} 9fb13c24488e3d7556693247d5a463c1837c3c8ede28f4094228e6c4eb5d70bd}} {DisplayName {} {%PCDATA {} dnew@san.rr.com}}} {StorageClass {} {%PCDATA {} STANDARD}}} tcltest::test xsxp-2.20 {Fetch another top-level item} -setup $setup_two -body { ::xsxp::fetch $pxml Contents } -result $c0 tcltest::test xsxp-2.30 {Fetch #0 item} -setup $setup_two -body { ::xsxp::fetch $pxml Contents } -result $c0 set c1 {Contents {} {Key {} {%PCDATA {} t2.jpg}} {LastModified {} {%PCDATA {} 2006-10-27T23:19:44.000Z}} {ETag {} {%PCDATA {} {"ebc9b242811239ada85f202346353f31"}}} {Size {} {%PCDATA {} 1826062}} {Owner {} {ID {} {%PCDATA {} 9fb13c24488e3d7556693247d5a463c1837c3c8ede28f4094228e6c4eb5d70bd}} {DisplayName {} {%PCDATA {} dnew@san.rr.com}}} {StorageClass {} {%PCDATA {} STANDARD}}} tcltest::test xsxp-2.40 {Fetch #1 item} -setup $setup_two -body { ::xsxp::fetch $pxml Contents#1 } -result $c1 tcltest::test xsxp-2.50 {Fetch item past end} -setup $setup_two -body { ::xsxp::fetch $pxml Contents#2 } -result {} tcltest::test xsxp-2.60 {Check %TAGNAME} -setup $setup_two -body { ::xsxp::fetch $pxml #4 %TAGNAME } -result {IsTruncated} tcltest::test xsxp-2.70 {check merge of PCDATA} -setup $setup_two -body { ::xsxp::fetch $pxml Contents/ETag %PCDATA } -result {"a251eabc2e69e9716878924b6ec291c7"} tcltest::test xsxp-2.80 {Check lack of PCDATA} -setup $setup_two -body { ::xsxp::fetch $pxml Prefix %PCDATA } -returnCodes 1 -result "xsxp::fetch did not find requested PCDATA" tcltest::test xsxp-2.90 {Check lack of PCDATA?} -setup $setup_two -body { ::xsxp::fetch $pxml Prefix %PCDATA? } -result "" tcltest::test xsxp-3.10 {only} -setup $setup_two -body { set only [::xsxp::only $pxml Contents] return [list [llength $only] [lindex $only 0 0] [lindex $only 1 0]] } -result {2 Contents Contents} tcltest::test xsxp-4.10 {fetchall basic} -setup $setup_two -body { set only [::xsxp::only $pxml Contents] ::xsxp::fetchall $only Key %PCDATA } -result {t1.jpg t2.jpg} tcltest::test xsxp-5.10 {only} -setup $setup_two -body { set only [::xsxp::only $pxml Contents] ::xsxp::fetch $pxml Contents#1/Key/%PCDATA %CHILDREN } -result {t2.jpg} if {0} { foreach file [glob -directory xml *] { puts $file if {".xml" != [string range $file end-3 end]} continue set in [open $file r] set xml [read $in] close $in set pxml [::xsxp::parse $xml] set out [open [string range $file 0 end-4].txt w] ; #lazy ::xsxp::prettyprint $pxml $out close $out } } #---------------------------------------------------------------------- testsuiteCleanup puts "Done!" ; after 5000