#include <string>
using namespace std;

#include <message.h>

#include <messagetest.h>
#include <print.h>

string messagetest::doc[] = 
{
  "",
  "Write messages to log error file.",
  "Overloading << with return type message, write messages to log error file.",
  "Overloading << with return type message, write messages to log list of strings."
};


void messagetest::test01()
{
  cout << "Testing messagefile" << endl;

  stringc filename("error.txt");
  cout << "Appending to file " << filename << endl;
  cout << "On unix use $tail -f " << filename << " to follow changes" << endl;


  messagefile err(filename.c_str(),false);
  
  cout << "Enter text, " << endl;
  string quit("quit");
  cout << "To terminate enter " << quit << endl;
  char buff[256];
  for (;;)
  {
    cin.getline(buff,256);

    string in(buff);

    if (in==quit)
      return;

    err() << in << endl;
  }
}

//typedef endl<char, char_traits<char> > endl3;

void messagetest::test02()
{
  cout << "Testing messagefile with implicit calls." << endl;

  stringc filename("error.txt");
  messagefile err(filename);
  
  cout << "Enter text, " << endl;
  string quit("quit");
  cout << "To terminate enter " << quit << endl;
  char buff[256];
  for (;;)
  {
    cin.getline(buff,256);
    string in(buff);

    if (in==quit)
      return;

/*    (message&)err << in; // << endl; */
//    ((message&)err << in) << endl;
//    (message&)err << endl;
    // http://www.velocityreviews.com/forums/t279958-stdendl-type-unknown.html
    (message&)err << in << endl<char, char_traits<char> >;
  }
}

void messagetest::test03()
{
  messagelist err;  

  cout << "Adding some inapropriate message" << endl;
  (message&)err << "a" << "love" << "boat" << "at" << "work";

  cout << "Enter text, " << endl;
  string quit("quit");
  cout << "To terminate enter " << quit << endl;
  char buff[256];
  for (;;)
  {
    cin.getline(buff,256);
    string in(buff);

    if (in==quit)
      break;

    (message&)err << in; // << "a" << "cat" << "b"; //endl<char, char_traits<char> >;
  }

  cout << SHOW(err.vi.size()) << endl;
  for (uint i=0; i<err.vi.size(); ++i)
    cout << "*" << err.vi[i] << "*" << endl;

}







