void
Simple_Command_Parse_Test::test_parse_numeric_arg_1 ()
{
  Pipeline p;

  size_t errorc = 0;

  Simple_Command *c[] = { 0, 0 };

  std::vector<Argument *> *va[] = { 0, 0 };
  Argument *a[] = { 0, 0, 0 };

  const char *pipelinev[] = {
    "filter1 15 5 | filter2 0700",
    "filter1 15 5 2>&1 | filter2 0700 &> filter2.out"
   };

  const char *pipelinevp = 0;

  for (uint idx = 0; idx < 2; idx++)
    {
      try
        {
          pipelinevp = pipelinev[idx];

          p._charc = strlen (pipelinevp);
          p._startp = pipelinevp;
          p._endp = pipelinevp + p._charc;

          p.parse (pipelinevp);

          c[0] = static_cast<Simple_Command *> (p._cmdv.at (0));
          c[1] = static_cast<Simple_Command *> (p._cmdv.at (1));

          va[0] = c[0]->arguments ();
          va[1] = c[1]->arguments ();

          ASSERT_IDX (va[0]->size() == 2);
          ASSERT_IDX (va[1]->size() == 1);

          a[0] = va[0]->at (0);
          a[1] = va[0]->at (1);
          a[2] = va[1]->at (0);

          ASSERT_IDX (Util::strEqu ( a[0]->value(), "15"));
          ASSERT_IDX (Util::strEqu ( a[1]->value(), "5"));
          ASSERT_IDX (Util::strEqu ( a[2]->value(), "0700"));

          p.clear ();
        }
      CATCH_ERROR_PCHAR;
    }
  ASSERT_NO_ERROR;
}
void
Pipeline_Parse_Test::test_parse_exit_logical_not ()
{
  Pipeline p;

  uint errorc = 0;

  Simple_Command *f[] = { 0, 0, 0 };

  const char *pipelinev[] = {
     "!filter1 | filter2",
     "   !   filter1 | filter2"
   };

  const char *pipelinevp = 0;

  for (uint idx = 0; idx < 2; idx++)
    {
      try
        {
          // p._charc = strlen (pipelinev[idx]);
          // p.__parse (pipelinev[idx]);

          pipelinevp = pipelinev[idx];

          p._charc = strlen (pipelinevp);
          p._startp = pipelinevp;
          p._endp = pipelinevp + p._charc;

          p.parse (pipelinevp);

          // f[0] = p._filters.at (0);
          f[0] = static_cast<Simple_Command *> (p._cmdv.at (0));

          p._exit_status = EXIT_FAILURE;

          CPPUNIT_ASSERT (p._exit_not == true);
          CPPUNIT_ASSERT (p.exit_status () == EXIT_SUCCESS);

          p._exit_status = 2;

          CPPUNIT_ASSERT (p.exit_status () == EXIT_SUCCESS);
          CPPUNIT_ASSERT (Util::strEqu (f[0]->_file, "filter1"));

          p.clear ();
        }
      CATCH_ERROR_PCHAR;
    }

  CPPUNIT_ASSERT (errorc == 0);
}
void
Pipeline_Parse_Test::test_parse_async_pipeline_1 ()
{
  Pipeline p;

  uint errorc = 0;

  const char *pipelinev[] = {
    "filter1 | filter2 &",
    "filter1 | filter2&",
    "filter1 | filter2 &  ",
   };

  const char *pipelinevp = 0;

  for (uint idx = 0; idx < 3; idx++)
    {
      try
        {
          // p._charc = strlen (pipelinev[idx]);
          // p.__parse (pipelinev[idx]);

          pipelinevp = pipelinev[idx];

          p._charc = strlen (pipelinevp);
          p._startp = pipelinevp;
          p._endp = pipelinevp + p._charc;

          p.parse (pipelinevp);

          CPPUNIT_ASSERT (p._is_sequental == false);

          p.clear ();
        }
      CATCH_ERROR_PCHAR;
    }

  CPPUNIT_ASSERT (errorc == 0);
}
void
Pipeline_Parse_Test::test_parse_async_pipeline_FAILURE_1()
{
  Pipeline p;

  uint errorc = 0;

  const char *pipelinev[] = {
    "filter1 & | filter1",
    "filter2 | filter2 &&",
    "filter3 | filter3 & &",
    "filter4 | filter4 &&  "
   };

  const char *pipelinevp = 0;

  for (uint idx = 0; idx < 4; idx++)
    {
      try
        {
          pipelinevp = pipelinev[idx];

          p._charc = strlen (pipelinevp);
          p._startp = pipelinevp;
          p._endp = pipelinevp + p._charc;

          p.parse (pipelinevp);

          ASSERT_IDX (p._is_sequental == true);

          p.clear ();
        }
      CATCH_ERROR_PCHAR;
    }

  CPPUNIT_ASSERT (errorc == 4);
}
void
Pipeline_Parse_Test::test_parse_1 ()
{
  Pipeline p;

  const char *tokens = 0;
  const char *pipeline =  "";

  p._charc = strlen (pipeline);
  p._startp = pipeline;
  p._endp = pipeline + p._charc;

  tokens = p.parse (pipeline);

  // CPPUNIT_ASSERT (*tokens == 0); // *fail*
  CPPUNIT_ASSERT (p._cmdv.size () == 0);
  p.clear ();


  pipeline = " ";
  p._charc = strlen (pipeline);
  p._startp = pipeline;
  p._endp = pipeline + p._charc;

  tokens = p.parse (pipeline);

  // CPPUNIT_ASSERT (*tokens == 0);   // *fail*
  CPPUNIT_ASSERT (p._cmdv.size () == 0);
  p.clear ();


  pipeline = " | ";
  p._charc = strlen (pipeline);
  p._startp = pipeline;
  p._endp = pipeline + p._charc;

  tokens = p.parse (pipeline);

  // CPPUNIT_ASSERT (*tokens == 0);   // *fail*
  CPPUNIT_ASSERT (p._cmdv.size () == 0);
  p.clear ();


  pipeline = " || |";
  p._charc = strlen (pipeline);
  p._startp = pipeline;
  p._endp = pipeline + p._charc;

  tokens = p.parse (pipeline);

  // CPPUNIT_ASSERT (*tokens == 0);   // *fail*
  CPPUNIT_ASSERT (p._cmdv.size () == 0);
  p.clear ();


  pipeline = "ls";
  p._charc = strlen (pipeline);
  p._startp = pipeline;
  p._endp = pipeline + p._charc;

  tokens = p.parse (pipeline);

  // CPPUNIT_ASSERT (*tokens == 0);   // *fail*
  CPPUNIT_ASSERT (p._cmdv.size () == 1);


  Simple_Command *f[1] = {
    static_cast<Simple_Command *> (p._cmdv.at (0))
  };

  CPPUNIT_ASSERT (Util::strEqu (f[0]->path (), ""));
  CPPUNIT_ASSERT (strlen (f[0]->path ()) == 0);
  CPPUNIT_ASSERT (Util::strEqu (f[0]->file (), "ls"));
}