test/tc_managed_entries.rb in zip-container-3.0.0 vs test/tc_managed_entries.rb in zip-container-3.0.1

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (c) 2013, 2014 The University of Manchester, UK. +# Copyright (c) 2013-2015 The University of Manchester, UK. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -75,10 +75,15 @@ super(filename) valid = Proc.new { |contents| contents.match(/[Hh]ello/) } register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt", :required => true, :validation_proc => valid)) + + deep_greet = ZipContainer::ManagedFile.new("greet.txt", + :validation_proc => valid) + register_managed_entry(ZipContainer::ManagedDirectory.new("dir", + :entries => [deep_greet])) end def ExampleZipContainer2.create(filename, &block) super(filename, "application/example+zip", &block) end @@ -99,14 +104,10 @@ :required => true, :entries => [test_file])) register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt", :required => true, :validation_proc => valid)) end - #def ExampleDirContainer.create(filename, &block) - # super(filename, "application/example+zip", &block) - #end - end class TestManagedEntries < Test::Unit::TestCase # Check that the example ZipContainer file does not validate as a @@ -357,11 +358,11 @@ end end end end - # Check that a ExampleZipContainer2 will only verify when required objects + # Check that an ExampleZipContainer2 will only verify when required objects # are added with the correct contents. def test_create_subclassed_container_with_content_verification Dir.mktmpdir do |dir| filename = File.join(dir, "test.container") @@ -379,9 +380,55 @@ c.verify! end c.file.open("greeting.txt", "w") do |f| f.puts "Hello, Y'All!" + end + + assert_nothing_raised(ZipContainer::MalformedContainerError) do + c.verify! + end + end + end + + assert(ExampleZipContainer2.verify?(filename)) + assert_nothing_raised(ZipContainer::MalformedContainerError) do + ExampleZipContainer2.verify!(filename) + end + end + end + + # Check that an ExampleZipContainer2 will verify when deep objects are added + # with the correct contents. + def test_create_subclassed_container_with_deep_content_verification + Dir.mktmpdir do |dir| + filename = File.join(dir, "test.container") + + assert_nothing_raised do + ExampleZipContainer2.create(filename) do |c| + assert_raises(ZipContainer::MalformedContainerError) do + c.verify! + end + + c.file.open("greeting.txt", "w") do |f| + f.puts "Hello, Y'All!" + end + + assert_nothing_raised(ZipContainer::MalformedContainerError) do + c.verify! + end + + c.mkdir("dir") + c.file.open("dir/greet.txt", "w") do |f| + f.puts "Goodbye!" + end + + assert_raises(ZipContainer::MalformedContainerError) do + c.verify! + end + + c.file.open("dir/greet.txt", "w") do |f| + f.puts "hello everyone." end assert_nothing_raised(ZipContainer::MalformedContainerError) do c.verify! end