Frank Shearar uploaded a new version of CompressionTests to project The Trunk:
http://source.squeak.org/trunk/CompressionTests-fbs.1.mcz ==================== Summary ==================== Name: CompressionTests-fbs.1 Author: fbs Time: 14 June 2013, 6:58:44.913 pm UUID: 4f559835-8a97-48a7-ab68-aa33ce04ee55 Ancestors: Pulling out Compression's tests into a separate package means that Compression no longer depends on SUnit. ==================== Snapshot ==================== SystemOrganization addCategory: #CompressionTests! TestCase subclass: #ZipArchiveTests instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'CompressionTests'! ----- Method: ZipArchiveTests>>testCreateWithRelativeNames (in category 'tests') ----- testCreateWithRelativeNames "Test creating a zip with a relative tree of files, so that the tree will be created whereever the ." | subdir zip | subdir := FileDirectory default / '_test-zip-dir'. self deny: subdir exists. subdir assureExistence. [ subdir fileNamed: '_test-zip-file' do: [ : stream | stream nextPutAll: 'file contents' ]. zip := ZipArchive new. zip addDirectory: subdir fullName as: subdir localName. zip addFile: (subdir fullNameFor: '_test-zip-file') as: '_test-zip-dir' , FileDirectory slash , '_test-zip-file'. zip writeToFileNamed: (FileDirectory default fullNameFor: '_test.zip') ] ensure:[ zip close. subdir ifNotNil: [ subdir recursiveDelete ]. FileDirectory default deleteFileNamed: '_test.zip'. ]! ----- Method: ZipArchiveTests>>testDate29Feb2000 (in category 'tests') ----- testDate29Feb2000 "Ensure that dates with leap years don't screw up in the conversion" | archive mbr theDate | theDate := Date year: 2000 month: 2 day: 29. archive := ZipArchive new. mbr := archive addDeflateString:'foo' as: 'bar'. mbr setLastModFileDateTimeFrom: theDate asSeconds. self shouldnt:[mbr lastModTime] raise: Error. self assert: (Date fromSeconds: mbr lastModTime) = theDate.! TestCase subclass: #ZipCrcTests instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'CompressionTests'! ----- Method: ZipCrcTests>>testInvalidGZipCrc (in category 'tests') ----- testInvalidGZipCrc "See that a wrong CRC raises an appropriate error" | reader writer bytes crcByte | writer := GZipWriteStream on: String new. writer nextPutAll: 'Hello World'. writer close. bytes := writer encodedStream contents. crcByte := bytes byteAt: bytes size-5. "before the length" bytes byteAt: bytes size-5 put: (crcByte + 1 bitAnd: 255). reader := GZipReadStream on: bytes. self should:[reader upToEnd] raise: CRCError. reader := GZipReadStream on: bytes. self should:[reader contents] raise: CRCError. reader := GZipReadStream on: bytes. self should:[reader next: 100] raise: CRCError. ! ----- Method: ZipCrcTests>>testInvalidZLibCrc (in category 'tests') ----- testInvalidZLibCrc "See that a wrong CRC raises an appropriate error" | reader writer bytes crcByte | writer := ZLibWriteStream on: String new. writer nextPutAll: 'Hello World'. writer close. bytes := writer encodedStream contents. crcByte := bytes byteAt: bytes size-2. bytes byteAt: bytes size-2 put: (crcByte + 1 bitAnd: 255). reader := ZLibReadStream on: bytes. self should:[reader upToEnd] raise: CRCError. reader := ZLibReadStream on: bytes. self should:[reader contents] raise: CRCError. reader := ZLibReadStream on: bytes. self should:[reader next: 100] raise: CRCError. ! ----- Method: ZipCrcTests>>testInvalidZipCrc (in category 'tests') ----- testInvalidZipCrc "See that a wrong CRC raises an appropriate error" | reader writer bytes | writer := ZipWriteStream on: String new. writer nextPutAll: 'Hello World'. writer close. bytes := writer encodedStream contents. reader := ZipReadStream on: bytes. reader expectedCrc: writer crc - 1. self should:[reader upToEnd] raise: CRCError. reader := ZipReadStream on: bytes. reader expectedCrc: writer crc - 1. self should:[reader contents] raise: CRCError. reader := ZipReadStream on: bytes. reader expectedCrc: writer crc - 1. self should:[reader next: 100] raise: CRCError. ! ----- Method: ZipCrcTests>>testMissingGZipCrc (in category 'tests') ----- testMissingGZipCrc "See that the lack of a CRC raises an appropriate error" | reader writer bytes | writer := GZipWriteStream on: String new. writer nextPutAll: 'Hello World'. writer close. bytes := writer encodedStream contents. bytes := bytes copyFrom: 1 to: bytes size-6. reader := GZipReadStream on: bytes. self should:[reader upToEnd] raise: CRCError. reader := GZipReadStream on: bytes. self should:[reader contents] raise: CRCError. reader := GZipReadStream on: bytes. self should:[reader next: 100] raise: CRCError. ! ----- Method: ZipCrcTests>>testMissingZLibCrc (in category 'tests') ----- testMissingZLibCrc "See that the lack of a CRC raises an appropriate error" | reader writer bytes | writer := ZLibWriteStream on: String new. writer nextPutAll: 'Hello World'. writer close. bytes := writer encodedStream contents. bytes := bytes copyFrom: 1 to: bytes size-2. reader := ZLibReadStream on: bytes. self should:[reader upToEnd] raise: CRCError. reader := ZLibReadStream on: bytes. self should:[reader contents] raise: CRCError. reader := ZLibReadStream on: bytes. self should:[reader next: 100] raise: CRCError. ! ----- Method: ZipCrcTests>>testMissingZipCrc (in category 'tests') ----- testMissingZipCrc "See that the lack of a CRC does not raise an error" | reader writer bytes readBytes | writer := ZipWriteStream on: String new. writer nextPutAll: 'Hello World'. writer close. bytes := writer encodedStream contents. reader := ZipReadStream on: bytes. self shouldnt:[readBytes := reader upToEnd] raise: CRCError. self assert: readBytes = 'Hello World'. reader := ZipReadStream on: bytes. self shouldnt:[reader contents] raise: CRCError. reader := ZipReadStream on: bytes. self shouldnt:[reader next: 100] raise: CRCError. ! ----- Method: ZipCrcTests>>testValidGZipCrc (in category 'tests') ----- testValidGZipCrc | reader writer bytes | writer := GZipWriteStream on: String new. writer nextPutAll: 'Hello World'. writer close. bytes := writer encodedStream contents. reader := GZipReadStream on: bytes. self assert: reader upToEnd = 'Hello World'.! ----- Method: ZipCrcTests>>testValidZLibCrc (in category 'tests') ----- testValidZLibCrc | reader writer bytes | writer := ZLibWriteStream on: String new. writer nextPutAll: 'Hello World'. writer close. bytes := writer encodedStream contents. reader := ZLibReadStream on: bytes. self assert: reader upToEnd = 'Hello World'. bytes := writer encodedStream contents. reader := ZLibReadStream on: bytes. self assert: (reader next: 100) = 'Hello World'.! ----- Method: ZipCrcTests>>testValidZipCrc (in category 'tests') ----- testValidZipCrc "See that a correct CRC does not raise an error and that we can read what we wrote." | reader writer bytes readBytes | writer := ZipWriteStream on: String new. writer nextPutAll: 'Hello World'. writer close. bytes := writer encodedStream contents. reader := ZipReadStream on: bytes. reader expectedCrc: writer crc. self shouldnt:[ readBytes := reader upToEnd] raise: CRCError. self assert: readBytes = 'Hello World'. reader := ZipReadStream on: bytes. reader expectedCrc: writer crc. self shouldnt:[ readBytes := reader contents] raise: CRCError. self assert: readBytes = 'Hello World'. reader := ZipReadStream on: bytes. reader expectedCrc: writer crc. self shouldnt:[ readBytes := reader next: 11 ] raise: CRCError. self assert: readBytes = 'Hello World'. reader := ZipReadStream on: bytes. reader expectedCrc: writer crc. self shouldnt:[ readBytes := reader next: 100 ] raise: CRCError. self assert: readBytes = 'Hello World'.! |
Free forum by Nabble | Edit this page |