def end_inner_iterator_if_required(active_iterator_handle):
    itr_result_obj = iterator_utils.get_leaf_iterator()
    root_result = iterator_utils.get_stm_test_result_throw()

    if itr_result_obj is None or \
            itr_result_obj.GetObjectHandle() == root_result.GetObjectHandle() or \
            itr_result_obj.Get(Iterator.get_stc_property_Iterator()) == active_iterator_handle:
        logger.debug('Either new iterator or leaf iterator.')
        return
    # find if new iterator or existing iterator with missing child end iterator
    while itr_result_obj is not None and \
            itr_result_obj.GetObjectHandle() != root_result.GetObjectHandle() and \
            itr_result_obj.Get(Iterator.get_stc_property_Iterator()) != active_iterator_handle:

        itr_result_obj = itr_result_obj.GetParent()
        logger.debug_result_object_info(itr_result_obj)
    if itr_result_obj.GetObjectHandle() == root_result.GetObjectHandle() or \
            itr_result_obj.Get(Iterator.get_stc_property_Iterator()) != active_iterator_handle:
        logger.debug('No existing iterator found with same handle')
        return
    # call end iterator for missing
    leaf_iterator = iterator_utils.get_leaf_iterator()
    while leaf_iterator.Get(Iterator.get_stc_property_Iterator()) != active_iterator_handle:
        logger.error('Missing end iterator for child iterator')
        end_iterator()
        leaf_iterator = iterator_utils.get_leaf_iterator()
def complete_iteration():
    logger.info('Complete iteration.')
    itr_result_obj = iterator_utils.get_leaf_iterator()
    if itr_result_obj is None:
        logger.error('There is no iterator running to complete iteration.')
        return
    logger.debug_result_object_info(itr_result_obj)
    iterator = Iterator(0, itr_result_obj)
    iterator.complete_active_iteration()
    logger.debug('Complete iteration completed.')
def test_iterato_utils_create_get(stc, resource_cleanup):
    # check there are no result objects to start with
    assert result_obj.get_stm_test_result() is None
    # create iterator result which should create StmTestResult as well
    iterator_result_1 = iterator_utils.create_iterator_result()
    assert iterator_result_1 is not None
    stm_result = result_obj.get_stm_test_result()
    assert stm_result is not None
    parent_1 = iterator_result_1.GetParent()
    assert parent_1 is not None
    assert stm_result.GetObjectHandle() == parent_1.GetObjectHandle()
    # check leaf iterator
    iterator_result_3 = iterator_utils.get_leaf_iterator()
    assert iterator_result_3 is not None
    assert iterator_result_3.GetObjectHandle() == iterator_result_1.GetObjectHandle()
    # create one more iterator
    child_1 = iterator_utils.create_iterator_result()
    assert child_1 is not None
    # check parent is previous iterator
    parent_2 = child_1.GetParent()
    assert parent_2 is not None
    assert parent_2.GetObjectHandle() == iterator_result_3.GetObjectHandle()
    # new child should be leaf now
    child_3 = iterator_utils.get_leaf_iterator()
    assert child_3 is not None
    assert child_3.GetObjectHandle() == child_1.GetObjectHandle()
    # active result is same as well
    active_1 = iterator_utils.get_active_result_object()
    assert active_1 is not None
    assert child_3.GetObjectHandle() == active_1.GetObjectHandle()
    # reset results
    result_obj.reset()
    stm_2 = iterator_utils.get_active_result_object()
    assert stm_2 is not None
    assert stm_result.GetObjectHandle() == stm_2.GetObjectHandle()
    # check there are no iterator results
    assert iterator_utils.get_leaf_iterator() is None
    assert stm_2.GetObject('StmIteratorResult') is None
def test_create_stm_get_stm(stc, resource_cleanup):
    mm = meth_man_utils.get_meth_manager()
    assert mm is not None
    assert result_obj.get_stm_test_result() is None
    stm_result = mm.GetObject('StmTestResult')
    assert stm_result is None
    stm_result = result_obj.create_stm_test_result_under_mm()
    assert stm_result is not None
    stm_mm = mm.GetObject('StmTestResult')
    assert stm_result.GetObjectHandle() == stm_mm.GetObjectHandle()
    stm3 = result_obj.get_stm_test_result()
    assert stm3 is not None
    assert stm_result.GetObjectHandle() == stm3.GetObjectHandle()
    # check leaf iterator is none
    assert iterator_utils.get_leaf_iterator() is None
    # check StmTestResult is active result
    stm4 = iterator_utils.get_active_result_object()
    assert stm4 is not None
    assert stm_result.GetObjectHandle() == stm4.GetObjectHandle()
def end_iterator(force_stop=False):
    logger.info('End iteration.')
    itr_result_obj = iterator_utils.get_leaf_iterator()
    if itr_result_obj is None:
        logger.error('There is no iterator running to end iterator.')
        return
    iterator = Iterator(0, itr_result_obj)
    data = iterator.complete(force_stop)
    parentIterator = iterator_utils.get_leaf_iterator_no_throw()
    if parentIterator is None:
        logger.info('Adding iteration result to Test.')
        data[pc.STATUS][pc.APPLY_VERDICT] = True
        test_result = TestResult()
        test_result.add_provider_data(data)
    else:
        logger.info('Adding iteration result to parent iterator.')
        logger.debug_result_object_info(itr_result_obj)
        parent_itr = Iterator(0, parentIterator)
        parent_itr.add_child_iterator_data(data)
    logger.debug('End iteration completed')
def end_all_iterators(force_stop):
    itr_result_obj = iterator_utils.get_leaf_iterator()
    while itr_result_obj is not None:
        logger.error('End iterator call is missing.')
        end_iterator(force_stop)
        itr_result_obj = iterator_utils.get_leaf_iterator()