#------------------------------------------------------------------------------- # Copyright (c) 1997-2007, Perforce Software, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE # SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. #------------------------------------------------------------------------------- class TC_Resolve < Test::Unit::TestCase include P4RubyTest def name "Test resolve operations" end def test_resolve assert( p4, "Failed to create Perforce client" ) begin test_dir = "test_resolve" Dir.mkdir( test_dir ) file = "foo" fname = File.join( test_dir, file ) assert( p4.connect, "Failed to connect to Perforce server" ) assert( p4.run_opened.length == 0, "Shouldn't have any open files" ) # Create the file to test resolve File.open( fname, 'w' ) { |fd| fd.puts( "First Line!" ) } p4.run_add( fname ) assert( p4.run_opened.length == 1, "Unexpected number of open files" ) change = p4.fetch_change assert( change.kind_of?( P4::Spec ), "Change form is not a P4::Spec" ) change._description = "First resolve submit" assert( change._description == "First resolve submit", "Change description not set properly" ) assert_submit( "Failed to add file", change ) assert( p4.run_opened.length == 0, "Unexpected number of open files" ) # Create a second revision of the file p4.run_edit( fname ) File.open( fname, "a" ) { |fd| fd.puts( "Second Line." ) } assert( p4.run_opened.length == 1, "Unexpected number of open files" ) change = p4.fetch_change assert( change.kind_of?( P4::Spec ), "Change form is not a P4::Spec" ) change._description = "Second resolve submit" assert( change._description == "Second resolve submit", "Change description not set properly" ) assert_submit( "Failed to add file", change ) assert( p4.run_opened.length == 0, "Unexpected number of open files" ) assert_nothing_raised( "Problem scheduling resolve for {#fname}" ) do # Now sync to rev #1 p4.run_sync( fname + "#1" ) # open the file for edit and sync to schedule a resolve p4.run_edit( fname ) p4.run_sync( fname ) end # Ensure that exceptions raised in the block # are raised upwards if they are not rescued. assert_raise (RuntimeError) do p4.run_resolve do |md| raise RuntimeError, "Raising a RuntimeError during a resolve!" end end # ...and test a standard resolve p4.run_resolve do |md| client = p4.client assert( md.class == P4::MergeData, "Merge data wasn't a P4::MergeData object" ) assert_equal( "//#{client}/#{fname}", md.your_name, "Unexpected Your name: #{md.your_name}" ) assert_equal( "//depot/#{fname}#2", md.their_name, "Unexpected Their name: #{md.their_name}" ) assert_equal( "//depot/#{fname}#1", md.base_name, "Unexpected Base name: #{md.base_name}" ) assert_equal( "at", md.merge_hint, "Unexpected merge hint: #{md.merge_hint}" ) "at" end change = p4.fetch_change assert( change.kind_of?( P4::Spec ), "Change form is not a P4::Spec" ) change._description = "Third resolve submit" assert( change._description == "Third resolve submit", "Change description not set properly" ) assert_submit( "Failed to add file", change ) assert( p4.run_opened.length == 0, "Unexpected number of open files" ) ensure p4.run_revert( '//...' ) unless( p4.run_opened.empty? ) p4.disconnect end end # # Local method to help ensure submits are working # def assert_submit( msg, *args ) assert_block( msg ) do begin result = @p4.run_submit( args ) if( result[-1].has_key?( 'submittedChange' ) ) true else false end rescue P4Exception false end end end end