<commit_before>############################################################################
## 
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 
## All rights reserved. 
## Contact: Nokia Corporation (<EMAIL>) 
## 
## This file is part of Testability Driver. 
## 
## If you have questions regarding the use of this file, please contact 
## Nokia at <EMAIL> . 
## 
## This library is free software; you can redistribute it and/or 
## modify it under the terms of the GNU Lesser General Public 
## License version 2.1 as published by the Free Software Foundation 
## and appearing in the file LICENSE.LGPL included in the packaging 
## of this file. 
## 
############################################################################

module MobyBase

  # Static representation of the state of a TestObject or SUT. 
  # StateObject are not refreshed or synchronize etc.
  class StateObject

    include MobyBehaviour::ObjectComposition

    # The test object factory is needed for populating child object accessor methods
    #@test_object_factory

    # == description
    # attr_accessor
    #
    # == returns
    # Test Object
    #  description: test object that was used as parent when this object was created. Can also be of type SUT if sut was the parent (ie. application objects)
    #  example: "@sut"
    attr_accessor :parent

    # TODO: document me
    attr_reader(
        :type,      # object type
        :name,      # object name
        :id         # object id
    )

    # Creation of a new StateObject from source data.
    # === params
    # options:: Hash containing source data describing the object and all other required configuration values e.g. test object factory, -adapter etc.
    # === returns
    # StateObject:: new StateObject instance
    # === raises
    def initialize( *options )

      # clone original options array; array is modified below
      options = options.clone

      # determine is method called with new or deprecated API
      if options.count > 1

        # print warning if deprecated API is used
        warn_caller '$1:$2 warning: deprecated API; use hash with :source_data, :parent, :test_object_adapter as argument instead of StateObject.new( source_data, parent, test_object_adapter )'

        # retrieve source data
        source_data = options.shift

        # retrieve reference to parent object
        parent = options.shift

        # retrieve reference to test object adapter
        test_object_adapter = options.shift

      else

        # retrieve first array element
        options = options.shift

        # verify options argument type
        options.check_type Hash, 'wrong argument type $1 for StateObject options (expected $2)'

        # verify that :source_data key exists in hash       
        source_data = options.require_key :source_data

        # retrieve reference to parent object
        parent = options[ :parent ]

        # retrieve reference to test object adapter
        test_object_adapter = options[ :test_object_adapter ]

      end

      # verify that parent argument type is correct
      parent.check_type [ NilClass, MobyBase::StateObject, MobyBase::TestObject, MobyBase::SUT ], 'wrong argument type $1 for parent object (expected $2)'

      # verify that test object adapter argument type is correct
      test_object_adapter.check_type [ NilClass, Class ], 'wrong argument type $1 for test object adapter (expected $2)'

      # verify that source data argument type is correct<commit_msg>tdriver#base/state_object.rb: bug fixed; log changed how to determine when old deprecated API is used...<commit_after>############################################################################
## 
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 
## All rights reserved. 
## Contact: Nokia Corporation (<EMAIL>) 
## 
## This file is part of Testability Driver. 
## 
## If you have questions regarding the use of this file, please contact 
## Nokia at <EMAIL> . 
## 
## This library is free software; you can redistribute it and/or 
## modify it under the terms of the GNU Lesser General Public 
## License version 2.1 as published by the Free Software Foundation 
## and appearing in the file LICENSE.LGPL included in the packaging 
## of this file. 
## 
############################################################################

module MobyBase

  # Static representation of the state of a TestObject or SUT. 
  # StateObject are not refreshed or synchronize etc.
  class StateObject

    include MobyBehaviour::ObjectComposition

    # The test object factory is needed for populating child object accessor methods
    #@test_object_factory

    # == description
    # attr_accessor
    #
    # == returns
    # Test Object
    #  description: test object that was used as parent when this object was created. Can also be of type SUT if sut was the parent (ie. application objects)
    #  example: "@sut"
    attr_accessor :parent

    # TODO: document me
    attr_reader(
        :type,      # object type
        :name,      # object name
        :id         # object id
    )

    # Creation of a new StateObject from source data.
    # === params
    # options:: Hash containing source data describing the object and all other required configuration values e.g. test object factory, -adapter etc.
    # === returns
    # StateObject:: new StateObject instance
    # === raises
    def initialize( *options )

      # clone original options array; array is modified below
      options = options.clone

      # determine is method called with new or deprecated API
      
      if options.count == 1 and options.first.kind_of?( Hash )

        # retrieve first array element
        options = options.shift

        # verify options argument type
        options.check_type Hash, 'wrong argument type $1 for StateObject options (expected $2)'

        # verify that :source_data key exists in hash       
        source_data = options.require_key :source_data

        # retrieve reference to parent object
        parent = options[ :parent ]

        # retrieve reference to test object adapter
        test_object_adapter = options[ :test_object_adapter ]
      
      else
      
        # print warning if deprecated API is used
        warn_caller '$1:$2 warning: deprecated API; use hash with :source_data, :parent, :test_object_adapter as argument instead of StateObject.new( source_data, parent, test_object_adapter )'

        # retrieve source data
        source_data = options.shift

        # retrieve reference to parent object
        parent = options.shift

        # retrieve reference to test object adapter
        test_object_adapter = options.shift

      end

      # verify that parent argument type is correct
      parent.check_type [ NilClass, MobyBase::StateObject, MobyBase::TestObject, MobyBase::SUT ], 'wrong argument type $1 for parent object (expected $2)'

      # verify that test object adapter argument type is correct
      test_object_adapter.check_type [ NilClass, Class ], 'wrong argument type $1 for test object adapter (expected $2)'

      # verify that source data argument type is correct
{'fraction_non_alphanumeric': 0.10612813370473538, 'fraction_numerical': 0.004178272980501393, 'mean_word_length': 3.029741863075196, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '646699', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1717, 'n_words': 763}