17_streams_test.rb #1

  • //
  • guest/
  • surajdolby/
  • p4ruby/
  • test/
  • 17_streams_test.rb
  • View
  • Commits
  • Open Download .zip Download (4 KB)
# vim:ts=2:sw=2:et:
#-------------------------------------------------------------------------------
# Copyright (c) 2010, 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_Streams < Test::Unit::TestCase

  include P4RubyTest

  def name
    "Test streams"
  end

  def test_streams
    assert( p4, "Failed to create Perforce client" )

    #	Create a streams depot
    begin
      assert( p4.connect, "Failed to connect to Perforce server" )
      depot = p4.fetch_depot( "Stream" )

      # Check server_level to ensure that the server support streams.
      if( p4.server_level >=30 && p4.api_level >= 70 )
        assert( p4.streams?, "Streams are not enabled" )

        # Create a new streams depot and make sure that it's listed.
        depot[ 'type' ] = "stream"
        p4.save_depot( depot )
        assert_equal( 2, p4.run_depots.length, "Streams depot not created" )

        #	Disable streams 
        assert( p4.api_level >= 70, "API level (#{p4.api_level}) too low" )
        p4.streams=false
        assert( !p4.streams?, "Failed to disable streams" )
        len = p4.run_depots.length
        assert_equal( 1, len, "Unexpected streams depot listed" )

        #	Enable streams and set the api_level < 70
        p4.streams=true
        assert( p4.streams?, "Failed to enable streams" )
        p4.api_level = 69
        assert( p4.api_level < 70, "API level (#{p4.api_level}) too high" )
        len = p4.run_depots.length
        assert_equal( 1, len, "Unexpected streams depot listed" )    

        # Fetch a stream from the server, check that
        # an 'extraTag' field (such as 'firmerThanParent' exists, and save
        # the spec
        s = p4.fetch_stream( "//Stream/MAIN" )
        assert(s.has_key?("firmerThanParent"), "'extraTag' field missing from spec." )
        s[ 'Type' ] = "mainline"
        o = p4.save_stream( s )
        assert( o.length == 1, "Unexpected output when creating a stream" )
        assert( o[0] =~ /saved/, "Failed to create a stream" )
      else
        puts "\tTest Skipped: Streams requires a 2011.1 or later Perforce Server and P4API."
      end
    ensure
      p4.disconnect
    end

    begin
      assert( p4.connect, "Failed to connect to Perforce server" )
      if( p4.server_level >=30 && p4.api_level >= 70 )
        len = p4.run_streams.length
        assert_equal( 1, len, "Failed to save stream spec" )
        p4.run_streams
      end
    ensure
      p4.disconnect
    end
  end
end
# Change User Description Committed
#1 15524 surajdolby Populate -o //guest/perforce_software/p4ruby/main/...
//guest/surajdolby/p4ruby/....
//guest/perforce_software/p4ruby/main/test/17_streams_test.rb
#1 14676 tony Rework P4Ruby unit tests so they they are actually units.
Now the
test order is irrelevant as all tests are standalone. Tidied up
the code formatting as well and removed all the tabs from the ruby
sources files. Added a modeline for vim users so consistent
indentation will be used.
//guest/perforce_software/p4ruby/main/test/17_streams.rb
#1 14622 jmistry Pull 10.2 changes to main

Pick up missing changes in p10.2 and integrate to main.

As part of the integrate I also moved the unit tests '16_streams.rb' and
'17_streaming_handler.rb' because the integration introduced collisions with
the unit test names. Updated MANIFEST with new names for unit tests and also
added '98_unicode.rb', which was missing from it.
//guest/perforce_software/p4ruby/main/test/16_streams.rb
#6 14610 jmistry Fix unlink error on unit tests

Wrap the connect/disconnect in begin/ensure blocks to
ensure that the client disconnect even if there are failures
in a unit test.

Fix unicode unit test for 1.9.  When the contents of a file
is stored in a String object, ruby 1.9 sets the String's
encoding to the current locale.  This is overridden in the
test case and set to the correct value.  This may need to
be documented.

user visible change.
#5 14609 jmistry Fix track error

P4Ruby now raises a P4Exception, instead of a Ruby warning if a user tries to
change track output after connecting. The test case has been updated to suppress
this because we expect the error.

Also removed debug message (accidently) left in streams test case.
#4 14607 jmistry Fix streams test case

Streams test case now checks api_level, as well as server_version
to make sure that we are using a new enough P4API.  If not, the
test is skipped and the following message is displayed:

"Test Skipped: Streams requires a 2011.1 or later Perforce Server and P4API."
#3 14597 jmistry Fix Streams Test

For some reason, the test harness wasn't running 'test_streams_depot'.  Renamed method
to 'test_streams' and it's now running!
#2 14596 jmistry Include 'extraTag' val in P4::Spec

The tagged output of a stream spec includes an 'extraTag<n>' field. 
This change ensures that the field pointed to by 'extraTag' (such as
'firmerThanParent') is added to the P4::Spec object and it points
to the correct value.

Test case updated to check for 'firmerThanParent' in stream P4::Spec.
The test case needs to disconnect/connect, otherwise P4.run_streams
returns with the warning 'No such streams'.
#1 14594 jmistry [P4Ruby] enable streams by default

Fixed S_STREAMS bit mask to 0x0040 and changed the initial
state S_INITIAL_STATE bit 0x0041 to enable streams by default.

Added logic to set streams for API levels greater than 69

Add streams test case - tests the output of 'P4::run_depots' for different
settings of 'P4::streams' and 'P4::api_level'