<commit_before>/*ckwg +5
 * Copyright 2011 by Kitware, Inc. All Rights Reserved. Please refer to
 * KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
 * Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
 */

#include <test_common.h>

#include <vistk/pipeline/config.h>
#include <vistk/pipeline/modules.h>
#include <vistk/pipeline/pipeline.h>
#include <vistk/pipeline/pipeline_exception.h>
#include <vistk/pipeline/process.h>
#include <vistk/pipeline/process_exception.h>

#include <exception>
#include <iostream>
#include <string>

static void run_test(std::string const& test_name);

int
main(int argc, char* argv[])
{
  if (argc != 2)
  {
    TEST_ERROR("Expected one argument");

    return 1;
  }

  std::string const test_name = argv[1];

  try
  {
    run_test(test_name);
  }
  catch (std::exception& e)
  {
    TEST_ERROR("Unexpected exception: " << e.what());

    return 1;
  }

  return 0;
}

static void test_null_config();
static void test_null_process();
static void test_add_process();
static void test_add_group();
static void test_duplicate_process_process();
static void test_duplicate_process_group();
static void test_duplicate_group_process();
static void test_duplicate_group_group();
static void test_map_input_no_group();
static void test_map_output_no_group();
static void test_map_input_no_process();
static void test_map_output_no_process();
static void test_map_input();
static void test_map_output();
static void test_connect_no_upstream();
static void test_connect_no_downstream();
static void test_connect_type_mismatch();
static void test_connect_flag_mismatch();
static void test_connect();
static void test_connect_input_map();
static void test_connect_output_map();
static void test_setup_pipeline_no_processes();
static void test_setup_pipeline_orphaned_process();
static void test_setup_pipeline_missing_required_input_connection();
static void test_setup_pipeline_missing_required_output_connection();
static void test_setup_pipeline_missing_required_group_input_connection();
static void test_setup_pipeline_missing_required_group_output_connection();
static void test_setup_pipeline();

void
run_test(std::string const& test_name)
{
  if (test_name == "null_config")
  {
    test_null_config();
  }
  else if (test_name == "null_process")
  {
    test_null_process();
  }
  else if (test_name == "add_process")
  {
    test_add_process();
  }
  else if (test_name == "add_group")
  {
    test_add_group();
  }
  else if (test_name == "duplicate_process_process")
  {
    test_duplicate_process_process();
  }
  else if (test_name == "duplicate_process_group")
  {
    test_duplicate_process_group();
  }
  else if (test_name == "duplicate_group_process")
  {
    test_duplicate_group_process();
  }
  else if (test_name == "duplicate_group_group")
  {
    test_duplicate_group_group();
  }
  else if (test_name == "map_input_no_group")
  {
    test_map_input_no_group();
  }
  else if (test_name == "map_output_no_group")
  {
    test_map_output_no_group();
  }
  else if (test_name == "map_input_no_process")
  {
    test_map_input_no_process();
  }
  else if (test_name == "map_output_no_process")
  {
    test_map_output_no_process();
  }
  else if (test_name == "map_input")
  {
    test_map_input();
  }
  else if (test_name == "map_output")
  {
    test_map_output();
  }
  else if (test_name == "connect_no_upstream")
  {
    test_connect_no_upstream();
  }
  else if (test_name == "connect_no_downstream")
  {
    test_connect_no_downstream();
  }
  else if (test_name == "connect_type_mismatch")
  {
    test_connect_type_mismatch();
  }
  else if (test_name == "connect_flag_mismatch")
  {
    test_connect_flag_mismatch();
  }
  else if (test_name == "connect")
  {
    test_connect();
  }
  else if (test_name == "connect_input_map")
  {
    test_connect_input_map();
  }
  else if (test_name == "connect_output_map")
  {
    test_connect_output_map();
  }
  else if (test_name == "setup_pipeline_no_processes")
  {
    test_setup_pipeline_no_processes();
  }
  else if (test_name == "setup_pipeline_orphaned_process")
  {
    test_setup_pipeline_orphaned_process();
  }
  else if (test_name == "setup_pipeline_missing_required_input_connection")
  {
    test_setup_pipeline_missing_required_input_connection();
  }
  else if (test_name == "setup_pipeline_missing_required_output_connection")
  {
    test_setup_pipeline_missing_required_output_connection();
  }
  else if (test_name == "setup_pipeline_missing_required_group_input_connection")
  {
    test_setup_pipeline_missing_required_group_input_connection();
  }
  else if (test_name == "setup_pipeline_missing_required_group_output_connection")
  {
    test_setup_pipeline_missing_required_group_output_connection();
  }
  else if (test_name == "setup_pipeline")
  {
    test_setup_pipeline();
  }
  else
  {
    TEST_ERROR("Unknown test: " << test_name);
  }
}

static vistk::process_t create_process(vistk::process_registry::type_t const& type, vistk::process::name_t const& name, vistk::config_t config = vistk::config::empty_config());
static vistk::pipeline_t create_pipeline();

void
test_null_config()
{
  vistk::config_t const config;

  EXPECT_EXCEPTION(vistk::null_pipeline_config_exception,
                   vistk::pipeline_t(new vistk::pipeline(config)),
                   "passing a NULL config to the pipeline");
}
void
test_null_process()
{
  vistk::process_t const process;

  vistk::pipeline_t pipeline = create_pipeline();

  EXPECT_EXCEPTION(vistk::null_process_addition_exception,
                   pipeline->add_process(process),
                   "adding a NULL process to the pipeline");
}

void
test_add_process()
{
  vistk::process_registry::type_t const proc_type = vistk::process_registry::type_t("numbers");

  vistk::process_t const process = create_process(proc_type, vistk::process::name_t());

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_process(process);
}

void
test_add_group()
{
  vistk::config::value_t const proc_name = vistk::process::name_t("name");

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_group(proc_name);
}

void
test_duplicate_process_process()
{
  vistk::process_registry::type_t const proc_type = vistk::process_registry::type_t("numbers");

  vistk::process::name_t const proc_name = vistk::process::name_t("name");

  vistk::process_t const process = create_process(proc_type, proc_name);
  vistk::process_t const dup_process = create_process(proc_type, proc_name);

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_process(process);

  EXPECT_EXCEPTION(vistk::duplicate_process_name_exception,
                   pipeline->add_process(dup_process),
                   "adding a duplicate process to the pipeline");
}

void
test_duplicate_process_group()
{
  vistk::process_registry::type_t const proc_type = vistk::process_registry::type_t("numbers");

  vistk::process::name_t const proc_name = vistk::process::name_t("name");

  vistk::process_t const dup_process = create_process(proc_type, proc_name);

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_group(proc_name);

  EXPECT_EXCEPTION(vistk::duplicate_process_name_exception,
                   pipeline->add_process(dup_process),
                   "adding a duplicate process to the pipeline");
}

void
test_duplicate_group_process()
{
  vistk::process_registry::type_t const proc_type = vistk::process_registry::type_t("numbers");

  vistk::process::name_t const proc_name = vistk::process::name_t("name");

  vistk::process_t const process = create_process(proc_type, proc_name);

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_process(process);

  EXPECT_EXCEPTION(vistk::duplicate_process_name_exception,
                   pipeline->add_group(proc_name),
                   "adding a duplicate group to the pipeline");
}

void
test_duplicate_group_group()
{
  vistk::config::value_t const proc_name = vistk::process::name_t("name");

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_group(proc_name);

  EXPECT_EXCEPTION(vistk::duplicate_process_name_exception,
                   pipeline->add_group(proc_name),
                   "adding a duplicate group to the pipeline");
}

void
test_map_input_no_group()
{
  vistk::config::value_t const proc_name = vistk::process::name_t("name");

  vistk::pipeline_t pipeline = create_pipeline();

  EXPECT_EXCEPTION(vistk::no_such_group_exception,
                   pipeline->map_input_port(proc_name, vistk::process::port_t(),
                                            vistk::process::name_t(), vistk::process::port_t(),
                                            vistk::process::port_flags_t()),
                   "mapping an input on a non-existent group");
}

void
test_map_output_no_group()
{
  vistk::config::value_t const proc_name = vistk::process::name_t("name");

  vistk::pipeline_t pipeline = create_pipeline();

  EXPECT_EXCEPTION(vistk::no_such_group_exception,
                   pipeline->map_output_port(proc_name, vistk::process::port_t(),
                                             vistk::process::name_t(), vistk::process::port_t(),
                                             vistk::process::port_flags_t()),
                   "mapping an output to a non-existent group");
}

void
test_map_input_no_process()
{
  vistk::config::value_t const proc_name = vistk::process::name_t("name");

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_group(proc_name);

  EXPECT_EXCEPTION(vistk::no_such_process_exception,
                   pipeline->map_input_port(proc_name, vistk::process::port_t(),
                                            vistk::process::name_t(), vistk::process::port_t(),
                                            vistk::process::port_flags_t()),
                   "mapping an input on an non-existent group");
}

void
test_map_output_no_process()
{
  vistk::config::value_t const proc_name = vistk::process::name_t("name");

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_group(proc_name);

  EXPECT_EXCEPTION(vistk::no_such_process_exception,
                   pipeline->map_output_port(proc_name, vistk::process::port_t(),
                                             vistk::process::name_t(), vistk::process::port_t(),
                                             vistk::process::port_flags_t()),
                   "mapping an output on a non-existent group");
}

void
test_map_input()
{
  vistk::process_registry::type_t const proc_type = vistk::process_registry::type_t("numbers");

  vistk::process::name_t const group_name = vistk::process::name_t("group");
  vistk::process::name_t const proc_name = vistk::process::name_t("name");

  vistk::process_t const process = create_process(proc_type, proc_name);

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_group(group_name);
  pipeline->add_process(process);

  pipeline->map_input_port(group_name, vistk::process::port_t(),
                           proc_name, vistk::process::port_t(),
                           vistk::process::port_flags_t());
}

void
test_map_output()
{
  vistk::process_registry::type_t const proc_type = vistk::process_registry::type_t("numbers");

  vistk::process::name_t const group_name = vistk::process::name_t("group");<commit_msg>Update tests for mapping to non-existant processes<commit_after>/*ckwg +5
 * Copyright 2011 by Kitware, Inc. All Rights Reserved. Please refer to
 * KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
 * Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
 */

#include <test_common.h>

#include <vistk/pipeline/config.h>
#include <vistk/pipeline/modules.h>
#include <vistk/pipeline/pipeline.h>
#include <vistk/pipeline/pipeline_exception.h>
#include <vistk/pipeline/process.h>
#include <vistk/pipeline/process_exception.h>

#include <exception>
#include <iostream>
#include <string>

static void run_test(std::string const& test_name);

int
main(int argc, char* argv[])
{
  if (argc != 2)
  {
    TEST_ERROR("Expected one argument");

    return 1;
  }

  std::string const test_name = argv[1];

  try
  {
    run_test(test_name);
  }
  catch (std::exception& e)
  {
    TEST_ERROR("Unexpected exception: " << e.what());

    return 1;
  }

  return 0;
}

static void test_null_config();
static void test_null_process();
static void test_add_process();
static void test_add_group();
static void test_duplicate_process_process();
static void test_duplicate_process_group();
static void test_duplicate_group_process();
static void test_duplicate_group_group();
static void test_map_input_no_group();
static void test_map_output_no_group();
static void test_map_input_no_process();
static void test_map_output_no_process();
static void test_map_input();
static void test_map_output();
static void test_connect_no_upstream();
static void test_connect_no_downstream();
static void test_connect_type_mismatch();
static void test_connect_flag_mismatch();
static void test_connect();
static void test_connect_input_map();
static void test_connect_output_map();
static void test_setup_pipeline_no_processes();
static void test_setup_pipeline_orphaned_process();
static void test_setup_pipeline_missing_required_input_connection();
static void test_setup_pipeline_missing_required_output_connection();
static void test_setup_pipeline_missing_required_group_input_connection();
static void test_setup_pipeline_missing_required_group_output_connection();
static void test_setup_pipeline();

void
run_test(std::string const& test_name)
{
  if (test_name == "null_config")
  {
    test_null_config();
  }
  else if (test_name == "null_process")
  {
    test_null_process();
  }
  else if (test_name == "add_process")
  {
    test_add_process();
  }
  else if (test_name == "add_group")
  {
    test_add_group();
  }
  else if (test_name == "duplicate_process_process")
  {
    test_duplicate_process_process();
  }
  else if (test_name == "duplicate_process_group")
  {
    test_duplicate_process_group();
  }
  else if (test_name == "duplicate_group_process")
  {
    test_duplicate_group_process();
  }
  else if (test_name == "duplicate_group_group")
  {
    test_duplicate_group_group();
  }
  else if (test_name == "map_input_no_group")
  {
    test_map_input_no_group();
  }
  else if (test_name == "map_output_no_group")
  {
    test_map_output_no_group();
  }
  else if (test_name == "map_input_no_process")
  {
    test_map_input_no_process();
  }
  else if (test_name == "map_output_no_process")
  {
    test_map_output_no_process();
  }
  else if (test_name == "map_input")
  {
    test_map_input();
  }
  else if (test_name == "map_output")
  {
    test_map_output();
  }
  else if (test_name == "connect_no_upstream")
  {
    test_connect_no_upstream();
  }
  else if (test_name == "connect_no_downstream")
  {
    test_connect_no_downstream();
  }
  else if (test_name == "connect_type_mismatch")
  {
    test_connect_type_mismatch();
  }
  else if (test_name == "connect_flag_mismatch")
  {
    test_connect_flag_mismatch();
  }
  else if (test_name == "connect")
  {
    test_connect();
  }
  else if (test_name == "connect_input_map")
  {
    test_connect_input_map();
  }
  else if (test_name == "connect_output_map")
  {
    test_connect_output_map();
  }
  else if (test_name == "setup_pipeline_no_processes")
  {
    test_setup_pipeline_no_processes();
  }
  else if (test_name == "setup_pipeline_orphaned_process")
  {
    test_setup_pipeline_orphaned_process();
  }
  else if (test_name == "setup_pipeline_missing_required_input_connection")
  {
    test_setup_pipeline_missing_required_input_connection();
  }
  else if (test_name == "setup_pipeline_missing_required_output_connection")
  {
    test_setup_pipeline_missing_required_output_connection();
  }
  else if (test_name == "setup_pipeline_missing_required_group_input_connection")
  {
    test_setup_pipeline_missing_required_group_input_connection();
  }
  else if (test_name == "setup_pipeline_missing_required_group_output_connection")
  {
    test_setup_pipeline_missing_required_group_output_connection();
  }
  else if (test_name == "setup_pipeline")
  {
    test_setup_pipeline();
  }
  else
  {
    TEST_ERROR("Unknown test: " << test_name);
  }
}

static vistk::process_t create_process(vistk::process_registry::type_t const& type, vistk::process::name_t const& name, vistk::config_t config = vistk::config::empty_config());
static vistk::pipeline_t create_pipeline();

void
test_null_config()
{
  vistk::config_t const config;

  EXPECT_EXCEPTION(vistk::null_pipeline_config_exception,
                   vistk::pipeline_t(new vistk::pipeline(config)),
                   "passing a NULL config to the pipeline");
}
void
test_null_process()
{
  vistk::process_t const process;

  vistk::pipeline_t pipeline = create_pipeline();

  EXPECT_EXCEPTION(vistk::null_process_addition_exception,
                   pipeline->add_process(process),
                   "adding a NULL process to the pipeline");
}

void
test_add_process()
{
  vistk::process_registry::type_t const proc_type = vistk::process_registry::type_t("numbers");

  vistk::process_t const process = create_process(proc_type, vistk::process::name_t());

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_process(process);
}

void
test_add_group()
{
  vistk::config::value_t const proc_name = vistk::process::name_t("name");

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_group(proc_name);
}

void
test_duplicate_process_process()
{
  vistk::process_registry::type_t const proc_type = vistk::process_registry::type_t("numbers");

  vistk::process::name_t const proc_name = vistk::process::name_t("name");

  vistk::process_t const process = create_process(proc_type, proc_name);
  vistk::process_t const dup_process = create_process(proc_type, proc_name);

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_process(process);

  EXPECT_EXCEPTION(vistk::duplicate_process_name_exception,
                   pipeline->add_process(dup_process),
                   "adding a duplicate process to the pipeline");
}

void
test_duplicate_process_group()
{
  vistk::process_registry::type_t const proc_type = vistk::process_registry::type_t("numbers");

  vistk::process::name_t const proc_name = vistk::process::name_t("name");

  vistk::process_t const dup_process = create_process(proc_type, proc_name);

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_group(proc_name);

  EXPECT_EXCEPTION(vistk::duplicate_process_name_exception,
                   pipeline->add_process(dup_process),
                   "adding a duplicate process to the pipeline");
}

void
test_duplicate_group_process()
{
  vistk::process_registry::type_t const proc_type = vistk::process_registry::type_t("numbers");

  vistk::process::name_t const proc_name = vistk::process::name_t("name");

  vistk::process_t const process = create_process(proc_type, proc_name);

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_process(process);

  EXPECT_EXCEPTION(vistk::duplicate_process_name_exception,
                   pipeline->add_group(proc_name),
                   "adding a duplicate group to the pipeline");
}

void
test_duplicate_group_group()
{
  vistk::config::value_t const proc_name = vistk::process::name_t("name");

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_group(proc_name);

  EXPECT_EXCEPTION(vistk::duplicate_process_name_exception,
                   pipeline->add_group(proc_name),
                   "adding a duplicate group to the pipeline");
}

void
test_map_input_no_group()
{
  vistk::config::value_t const proc_name = vistk::process::name_t("name");

  vistk::pipeline_t pipeline = create_pipeline();

  EXPECT_EXCEPTION(vistk::no_such_group_exception,
                   pipeline->map_input_port(proc_name, vistk::process::port_t(),
                                            vistk::process::name_t(), vistk::process::port_t(),
                                            vistk::process::port_flags_t()),
                   "mapping an input on a non-existent group");
}

void
test_map_output_no_group()
{
  vistk::config::value_t const proc_name = vistk::process::name_t("name");

  vistk::pipeline_t pipeline = create_pipeline();

  EXPECT_EXCEPTION(vistk::no_such_group_exception,
                   pipeline->map_output_port(proc_name, vistk::process::port_t(),
                                             vistk::process::name_t(), vistk::process::port_t(),
                                             vistk::process::port_flags_t()),
                   "mapping an output to a non-existent group");
}

void
test_map_input_no_process()
{
  vistk::config::value_t const proc_name = vistk::process::name_t("name");

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_group(proc_name);

  pipeline->map_input_port(proc_name, vistk::process::port_t(),
                           vistk::process::name_t(), vistk::process::port_t(),
                           vistk::process::port_flags_t());
}

void
test_map_output_no_process()
{
  vistk::config::value_t const proc_name = vistk::process::name_t("name");

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_group(proc_name);

  pipeline->map_output_port(proc_name, vistk::process::port_t(),
                            vistk::process::name_t(), vistk::process::port_t(),
                            vistk::process::port_flags_t());
}

void
test_map_input()
{
  vistk::process_registry::type_t const proc_type = vistk::process_registry::type_t("numbers");

  vistk::process::name_t const group_name = vistk::process::name_t("group");
  vistk::process::name_t const proc_name = vistk::process::name_t("name");

  vistk::process_t const process = create_process(proc_type, proc_name);

  vistk::pipeline_t pipeline = create_pipeline();

  pipeline->add_group(group_name);
  pipeline->add_process(process);

  pipeline->map_input_port(group_name, vistk::process::port_t(),
                           proc_name, vistk::process::port_t(),
                           vistk::process::port_flags_t());
}

void
test_map_output()
{
  vistk::process_registry::type_t const proc_type = vistk::process_registry::type_t("numbers");

  vistk::process::name_t const group_name = vistk::process::name_t("group");
{'fraction_non_alphanumeric': 0.11783340025877839, 'fraction_numerical': 0.0015169767545620844, 'mean_word_length': 4.393166506256016, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1353010', 'n_tokens_mistral': 7458, 'n_tokens_neox': 7313, 'n_words': 1235}