MACRO( ADD_SQL_FUNCTIONAL_TESTS sql_test_path)
    STRING( REGEX MATCH "^(([^\\/]*)\\/)?(.*)\\.[^.]*$" dummy ${sql_test_path} ) # remove sql extension
    SET( test_name ${CMAKE_MATCH_3})
    IF( CMAKE_MATCH_2 )
        SET( test_name ${CMAKE_MATCH_2}.${test_name} )
    ENDIF()
    SET( test_target test.functional.hive_fork_manager.${test_name} )
    SET( sources_under_tests_path ${CMAKE_SOURCE_DIR}/src/sql_fork_extension )
    ADD_TEST( NAME ${test_target}
            COMMAND test.sh ${sources_under_tests_path} ${sql_test_path}
            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    )
    MESSAGE( STATUS "Added functional tests '${test_target}'" )
ENDMACRO()

MACRO( ADD_AUTHORIZATION_FUNCTIONAL_TESTS sql_test_path)
    STRING( REGEX MATCH "^(([^\\/]*)\\/)?(.*)\\.[^.]*$" dummy ${sql_test_path} ) # remove sql extension
    SET( test_name ${CMAKE_MATCH_3})
    IF( CMAKE_MATCH_2 )
        SET( test_name ${CMAKE_MATCH_2}.${test_name} )
    ENDIF()
    SET( test_target test.functional.hive_fork_manager.${test_name} )
    SET( sources_under_tests_path ${CMAKE_SOURCE_DIR}/src/hive_fork_manager )
    ADD_TEST( NAME ${test_target}
            COMMAND test_authorization.sh ${sources_under_tests_path} ${sql_test_path}
            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
            )
    MESSAGE( STATUS "Added functional authorization tests '${test_target}'" )
ENDMACRO()

MACRO( ADD_EXAMPLES_FUNCTIONAL_TESTS example_test_path)
    STRING( REGEX MATCH "^(([^\\/]*)\\/)?(.*)\\.[^.]*$" dummy ${example_test_path} ) # remove py extension
    SET( test_name ${CMAKE_MATCH_3})
    IF( CMAKE_MATCH_2 )
        SET( test_name ${CMAKE_MATCH_2}.${test_name} )
    ENDIF()
    SET( test_target test.functional.hive_fork_manager.${test_name} )
    SET( sources_under_tests_path ${CMAKE_SOURCE_DIR}/src/hive_fork_manager/doc/examples )
    ADD_TEST( NAME ${test_target}
            COMMAND test_examples.sh ${sources_under_tests_path} ${example_test_path}
            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
            )
    MESSAGE( STATUS "Added functional authorization tests '${test_target}'" )
ENDMACRO()

ADD_SQL_FUNCTIONAL_TESTS( context_rewind/schema_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( context_rewind/register_table_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/register_table_edit_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/register_table_edit_negative_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/register_table_edit_negative_rowid_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/register_table_drop_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/detach_table_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/attach_table_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/detach_negative_unregistered_table_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/detach_negative_not_empty_shadow_table_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/detach_all_tables_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/detach_all_negative_tables_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/detach_constraint_fk_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/attach_negative_unregistered_table_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/attach_all_tables_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/attach_all_negative_tables_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/drop_registered_table_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/register_table_no_context_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/register_table_public_schema_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/register_table_to_two_contexts_negative_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( context_rewind/create_context_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/create_context_negative.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/context_next_block_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( context_rewind/trigger_on_insert_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/trigger_on_delete_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/trigger_on_update_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/trigger_on_truncate_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/trigger_on_insert_update_delete_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/trigger_on_multi_rows_insert_update_delete_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/trigger_3_tables_on_insert_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/trigger_3_tables_on_update_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/trigger_3_tables_on_delete_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/trigger_3_tables_on_truncate_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_insert_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_delete_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_update_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_truncate_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_insert_delete_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_insert_next_delete_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_update_delete_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_update_next_delete_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_update_some_rows_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_delete_insert_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_delete_next_insert_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_3_tables_insert_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_3_tables_delete_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_3_tables_update_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_3_tables_truncate_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_2_tables_schemas_insert_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_2_contexts_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_to_block_num_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_constraint_fk_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_constraint_unique_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_constraint_pk_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_complex_type_update_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_complex_type_insert_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/back_from_fork_complex_type_delete_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( context_rewind/set_irreversible_block_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/set_irreversible_block_negative_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( context_rewind/performance_insert_rows_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/performance_back_from_insert_rows_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/performance_delete_rows_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/performance_back_from_delete_rows_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/performance_update_rows_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/performance_back_from_update_rows_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/performance_truncate_rows_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/performance_back_from_truncate_rows_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/performance_insert_rows_one_by_one_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/performance_delete_rows_one_by_one_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( context_rewind/performance_update_rows_one_by_one_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( hived_api/schema_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/back_from_fork_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/push_block_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/set_irreversible_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/copy_blocks_to_irreversible.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/copy_transactions_to_irreversible_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/copy_operations_to_irreversible_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/copy_signatures_to_irreversible_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/remove_obsolete_blocks_with_set_irreversible.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/remove_obsolete_blocks_with_set_irreversible_3_contexts.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/remove_obsolete_blocks_with_set_irreversible_no_contexts.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/end_massive_sync_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/set_irreversible_cleaning_events_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/disable_indexes_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/enable_indexes_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/remove_obsolete_end_massive_sync_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/remove_obsolete_end_massive_sync_with_app_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/set_irreversible_not_copy_reversible_data_from_old_fork_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( hived_api/set_irreversible_not_copy_reversible_data_from_top_fork_test.sql )

ADD_SQL_FUNCTIONAL_TESTS( app_api/create_context_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_remove_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_remove_negative_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_re_create_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_blocks_view_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_blocks_view_nonforking_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_transactions_view_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_transactions_view_non_forking_app_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_signatures_view_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_signatures_view_non_forking_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_operations_view_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_operations_view_non_forking_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_is_attached.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_is_attached_negative.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_detached_save_block_num.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_detached_get_block_num.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_detached_save_block_num_negative.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_detached_get_block_num_negative.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_process_new_block_event.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_negative.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_process_new_block_event_2_contexts.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_process_BFF_event.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_process_BFF_event_2_contexts.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_process_SET_IRREVERSIBLE_event.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_process_SET_IRREVERSIBLE_event_2_contexts.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_attach.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_attach_negative.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_detach.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_process_MASSIVE_SYNC_event.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_process_squash_MASSIVE_SYNC_event.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_series_of_MASSIVE_SYNC.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_process_negative_MASSIVE_SYNC_event.sql)
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_non_forking_app.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_exists.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/register_already_existed_table.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/register_already_registered_table_negative.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_get_irreversible_block_forking.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_get_irreversible_block_non_forking.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_unregister_table.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_blocks_view_nonforking_detach_context_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_blocks_view_detach_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_signatures_view_non_forking_detach_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_signatures_view_detach_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_operations_view_non_forking_detach_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_operations_view_detach_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_transactions_view_non_forking_detach_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/context_transactions_view_detach_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_next_block_after_attach.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/app_context_remove_detached_test.sql )
ADD_SQL_FUNCTIONAL_TESTS( app_api/empty_blocks_and_views.sql )

ADD_SQL_FUNCTIONAL_TESTS( scenarios/massive_sync_live_blocks_and_fork.sql )
ADD_SQL_FUNCTIONAL_TESTS( scenarios/massive_sync_live_blocks_and_fork_non_forking_app.sql )

ADD_SQL_FUNCTIONAL_TESTS( state_providers/import_state_provider_negative.sql )
ADD_SQL_FUNCTIONAL_TESTS( state_providers/import_state_provider.sql )
ADD_SQL_FUNCTIONAL_TESTS( state_providers/accounts_start_state_provider.sql )
ADD_SQL_FUNCTIONAL_TESTS( state_providers/accounts_update_state_provider.sql )
ADD_SQL_FUNCTIONAL_TESTS( state_providers/update_state_provider.sql )
ADD_SQL_FUNCTIONAL_TESTS( state_providers/update_state_provider_attached.sql )
ADD_SQL_FUNCTIONAL_TESTS( state_providers/update_state_provider_negative.sql )
ADD_SQL_FUNCTIONAL_TESTS( state_providers/context_remove_and_state_provider.sql )
ADD_SQL_FUNCTIONAL_TESTS( state_providers/import_state_provider_non_fork.sql )
ADD_SQL_FUNCTIONAL_TESTS( state_providers/switch_state_provider_to_forkable.sql )

ADD_AUTHORIZATION_FUNCTIONAL_TESTS( authorization/alice_access_to_bob_negative.sql )
ADD_AUTHORIZATION_FUNCTIONAL_TESTS( authorization/alice_access_events_infrustructure.sql )
ADD_AUTHORIZATION_FUNCTIONAL_TESTS( authorization/hived_access_alice_context_data.sql )
ADD_AUTHORIZATION_FUNCTIONAL_TESTS( authorization/api_protection.sql )
ADD_AUTHORIZATION_FUNCTIONAL_TESTS( authorization/massive_sync_live_blocks_and_fork.sql )
ADD_AUTHORIZATION_FUNCTIONAL_TESTS( authorization/alice_grant_to_hive_applications_group.sql )
ADD_AUTHORIZATION_FUNCTIONAL_TESTS( authorization/hived_to_api_access.sql )

ADD_EXAMPLES_FUNCTIONAL_TESTS( examples/forking_application.py )
ADD_EXAMPLES_FUNCTIONAL_TESTS( examples/non_forking_application.py )
ADD_EXAMPLES_FUNCTIONAL_TESTS( examples/accounts_provider_application.py )
ADD_EXAMPLES_FUNCTIONAL_TESTS( examples/accounts_provider_non_fork_application.py )

ADD_SQL_FUNCTIONAL_TESTS( shared_lib/get_impacted_accounts.sql )
