//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / testing/mgmt
//
//File: commandtest.cpp
//
//Version: $Revision: 1.5 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/07/09 05:10:17 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author:
//      Timo Kokkonen
//
//Description:
//      Test file for mgmtCommand.
//
//Copyright:
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//
//Licence:
//
//
//History:
//
#include <typeinfo>
#include <iostream.h>
#include <string>

#include "mgmt/mgmtcommand.h"

#include "pf/debug.h"

void printUsage(string argv0_);
void printCommand(string &command_);
void printParameter(string &name_, string &value_, string &type_);

main(int argc, char* argv[])
{
    debugOutputCout();

    if (argc == 2)
    {
        if (argv[1][0] == 's')
        {
            debugUser("Start command test with one parameter");

            string command("testCommand");
            string name("name1");
            string value("value1");
            string type("type1");
            string commandOut("");
            string nameOut("");
            string valueOut("");
            string typeOut("");

            debugString("Creating command", command);
            mgmtCommand newCommand(command);
            newCommand.addParameter(name, value, type);

            debugUser("Printing created command ...");
            commandOut = newCommand.getCommandName();
            newCommand.getNextParameter(nameOut, valueOut, typeOut);
            printCommand(commandOut);
            printParameter(nameOut, valueOut, typeOut);
            debugUser("Done");
        }

        else if (argv[1][0] == 't')
        {
            debugUser("Start command test with tree parameter");

            string command("testCommand");
            string name("name1");
            string value("value1");
            string type("type1");
            string commandOut("");
            string nameOut("");
            string valueOut("");
            string typeOut("");
            pfUlong commandLength;

            debugString("Creating command", command);
            mgmtCommand newCommand(command);
            newCommand.addParameter(name, value, type);
            name = "name2";
            value = "value2";
            type = "type2";
            newCommand.addParameter(name, value, type);
            name = "name3";
            value = "value3";
            type = "type3";
            newCommand.addParameter(name, value);

            debugUser("Printing created command ...");
            commandOut = newCommand.getCommandName();
            printCommand(commandOut);
            commandLength = newCommand.getCommandLength();
            debugPfUlong("Parameters in command", commandLength);

            for (pfUlong i = 0; i < commandLength; ++i)
            {
                debugPfUlong("Parameter", i);
                newCommand.getNextParameter(nameOut, valueOut, typeOut);
                printParameter(nameOut, valueOut, typeOut);
            }
            debugUser("Done");

            debugUser("Copying commads parameter to other command...");

            mgmtCommand new2Command("Test");
            new2Command = newCommand;

            debugUser("Printing copy of list");
            debugString("Commands 2 name", new2Command.getCommandName());
            pfUlong length2 = new2Command.getCommandLength();
            debugPfUlong("Parameters in command 2", length2);

            for (pfUlong i = 0; i < length2; ++i)
            {
                debugPfUlong("Parameter", i);
                new2Command.getNextParameter(nameOut, valueOut, typeOut);
                printParameter(nameOut, valueOut, typeOut);
            }
            
        }
        else
        {
            printUsage(argv[0]);
        }
    }
    else
    {
        printUsage(argv[0]);
    }
}
    
void printUsage(string argv0_)
{
    string usage("Usage: " + argv0_ + "[test type]");
    debugUser(usage);
    debugUser("Test types");
    debugUser("s <-> create one parameter in command and print it");
    debugUser("t <-> create tree parameters in command and print it");
    debugUser("      also creates command2 and test operator=");
}

void printCommand(string &command_)
{
    debugString("Command", command_);
}

void printParameter(string &name_, string &value_, string &type_)
{
    debugString("Name", name_);
    debugString("Value", value_);
    debugString("Type", type_);
}
