Commit 2ad86bf8 authored by Marco Bartolini's avatar Marco Bartolini
Browse files

added tests for two parameters functions in SimpleParser

parent c214e55e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
#include "SP_types.h"
#include "SP_function1.h"
#include "SP_function2.h"
#include "SP_function0.h"
#include "SP_function3.h"
#include <ComponentErrors.h>
@@ -60,6 +61,9 @@ int changeDouble(double &d) {
	d/=2.0;
	return i;
}
void doubleTrouble(const double& first, const double& second) {
    return;
}
void test3Unary(const int& i,const int& j,const int& k) {
	int y=i+j+k;
	printf("'Test3Unary': %d\n",y);
@@ -108,6 +112,7 @@ int main(int argc, char *argv[]) {
	function1<CProva,non_constant,void_type,O<angle_type<deg> > > funG(&cl,&CProva::testDegAngle);
	function1<CProva,non_constant,void_type,O<declination_type<deg,true> > > funH(&cl,&CProva::testDegDeclination);
	function3<CProva,non_constant,void_type,I<int_type>,I<int_type>,I<int_type> > funI(&cl,&CProva::test3Unary);
	function2<CProva,non_constant,void_type,I<double_type>, I<double_type> >funJ(&cl,&CProva::doubleTrouble);
	
	/*base *p1,*p2;
	struct prova<int>data;
+56 −8
Original line number Diff line number Diff line
@@ -12,17 +12,26 @@ using namespace SimpleParser;
class TestObject
{
    public:
        TestObject() : test_value(0){};
        TestObject();
        void empty_command();
        void unary_command(const char* parameter);
        void two_params_command(const double& first, const double& second);
        IRA::CString result;
        int test_value;
        int test_int;
        double test_double[2];
};

TestObject::TestObject() :
    test_int(0)
{
    test_double[0] = 0;
    test_double[1] = 0;
}

void 
TestObject::empty_command()
{
    test_value++;
    test_int++;
    return;
}

@@ -33,6 +42,14 @@ TestObject::unary_command(const char* parameter)
    return;
}

void 
TestObject::two_params_command(const double& first, const double& second)
{
    test_double[0] = first;
    test_double[1] = second;
    return;
}

class TestProcedureParsing : public ::testing::Test
{
    public:
@@ -55,13 +72,22 @@ TestProcedureParsing::TestProcedureParsing()
                      &to,
                      &TestObject::unary_command), 
                  1);
    ACS::stringSeq noarg_procedure, arg_procedure;
    m_parser->add("two_params_command",
                  new function2<TestObject, non_constant, void_type, I<double_type>, I<double_type> >(
                      &to,
                      &TestObject::two_params_command), 
                  2);
    ACS::stringSeq noarg_procedure, arg_procedure, two_args_procedure;
    noarg_procedure.length(1);
    noarg_procedure[0] = "empty_command";
    m_parser->addExtraProcedure("empty_procedure", "testprocedure", noarg_procedure, 0);
    arg_procedure.length(1);
    arg_procedure[0] = "unary_command=$1";
    m_parser->addExtraProcedure("unary_procedure", "testprocedure", arg_procedure, 1);
    two_args_procedure.length(1);
    two_args_procedure[0] = "two_params_command=$1,$2";
    m_parser->addExtraProcedure("two_params_procedure", "testprocedure",
                                two_args_procedure, 2);
}

TestProcedureParsing::~TestProcedureParsing()
@@ -78,23 +104,23 @@ TEST_F(TestProcedureParsing, run_command_without_argument)
{
    IRA::CString procedure = "empty_command";
    IRA::CString output;
    int test_value = to.test_value;
    int test_int = to.test_int;
    m_parser->run(procedure, output);
    //This is a google test macro
    RecordProperty("run_output", (const char*) output);
    ASSERT_EQ(test_value + 1, to.test_value);
    ASSERT_EQ(test_int + 1, to.test_int);
}

TEST_F(TestProcedureParsing, run_procedure_without_argument)
{
    IRA::CString procedure = "empty_procedure";
    IRA::CString output;
    int test_value = to.test_value;
    int test_int = to.test_int;
    m_parser->run(procedure, output);
    //This is a google test macro
    RecordProperty("run_output", (const char*) output);
    sleep(2);
    ASSERT_EQ(test_value + 1, to.test_value);
    ASSERT_EQ(test_int + 1, to.test_int);
}

TEST_F(TestProcedureParsing, run_command_with_argument)
@@ -118,3 +144,25 @@ TEST_F(TestProcedureParsing, run_procedure_with_argument)
    ASSERT_EQ(IRA::CString("ciao"), to.result);
}

TEST_F(TestProcedureParsing, run_command_with_two_arguments)
{
    IRA::CString procedure = "two_params_command=10,20";
    IRA::CString output;
    m_parser->run(procedure, output);
    //This is a google test macro
    RecordProperty("run_output", (const char*) output);
    ASSERT_EQ((double)10, to.test_double[0]);
    ASSERT_EQ((double)20, to.test_double[1]);
}

TEST_F(TestProcedureParsing, run_procedure_with_two_arguments)
{
    IRA::CString procedure = "two_params_procedure=50,60.2345";
    IRA::CString output;
    m_parser->run(procedure, output);
    //This is a google test macro
    RecordProperty("run_output", (const char*) output);
    sleep(2);
    ASSERT_EQ((double)50, to.test_double[0]);
    ASSERT_EQ((double)60.2345, to.test_double[1]);
}
+7 −5
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="5" failures="0" disabled="0" errors="0" timestamp="2015-04-15T16:10:46" time="9.55" name="AllTests">
  <testsuite name="TestProcedureParsing" tests="5" failures="0" disabled="0" errors="0" time="9.548">
    <testcase name="test_setup" status="run" time="1.111" classname="TestProcedureParsing" />
    <testcase name="run_command_without_argument" status="run" time="1.108" classname="TestProcedureParsing" run_output="empty_command\" />
<testsuites tests="7" failures="0" disabled="0" errors="0" timestamp="2015-04-16T16:34:46" time="13.803" name="AllTests">
  <testsuite name="TestProcedureParsing" tests="7" failures="0" disabled="0" errors="0" time="13.786">
    <testcase name="test_setup" status="run" time="1.137" classname="TestProcedureParsing" />
    <testcase name="run_command_without_argument" status="run" time="1.11" classname="TestProcedureParsing" run_output="empty_command\" />
    <testcase name="run_procedure_without_argument" status="run" time="3.114" classname="TestProcedureParsing" run_output="empty_procedure\" />
    <testcase name="run_command_with_argument" status="run" time="1.105" classname="TestProcedureParsing" run_output="unary_command\" />
    <testcase name="run_command_with_argument" status="run" time="1.104" classname="TestProcedureParsing" run_output="unary_command\" />
    <testcase name="run_procedure_with_argument" status="run" time="3.105" classname="TestProcedureParsing" run_output="unary_procedure\" />
    <testcase name="run_command_with_two_arguments" status="run" time="1.103" classname="TestProcedureParsing" run_output="two_params_command\" />
    <testcase name="run_procedure_with_two_arguments" status="run" time="3.105" classname="TestProcedureParsing" run_output="two_params_procedure\" />
  </testsuite>
</testsuites>