1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/*
Adept MobileRobots Robotics Interface for Applications (ARIA)
Copyright (C) 2004, 2005 ActivMedia Robotics LLC
Copyright (C) 2006, 2007, 2008, 2009, 2010 MobileRobots Inc.
Copyright (C) 2011, 2012, 2013 Adept Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
If you wish to redistribute ARIA under different terms, contact
Adept MobileRobots for information about a commercial version of ARIA at
robots@mobilerobots.com or
Adept MobileRobots, 10 Columbia Drive, Amherst, NH 03031; +1-603-881-7960
*/
#include "Aria.h"
class TestAction0 : public ArAction
{
public:
TestAction0(const char *name) : ArAction(name)
{};
virtual ~TestAction0(void) {}
ArActionDesired *fire(ArActionDesired currentDesired) { return NULL; }
};
class TestAction1 : public ArAction
{
public:
TestAction1(const char *name, const char *description = "") :
ArAction(name, description)
{
setNextArgument(ArArg("first", &myDouble));
myDouble = 1;
};
virtual ~TestAction1(void) {}
ArActionDesired *fire(ArActionDesired currentDesired) { return NULL; }
double myDouble;
};
class TestAction3 : public ArAction
{
public:
TestAction3(const char *name, const char *description = "") :
ArAction(name, description)
{
setNextArgument(ArArg("first", &myDouble, "That infamous double"));
setNextArgument(ArArg("second", &myInt));
setNextArgument(ArArg("third", myString, "An infamous string", sizeof(myString)));
myDouble = 3;
myInt = 3;
strcpy(myString, "3");
};
virtual ~TestAction3(void) {}
ArActionDesired *fire(ArActionDesired currentDesired) { return NULL; }
double myDouble;
int myInt;
char myString[512];
};
int main(void)
{
ArArg *arg;
printf("Test0 should have no arguments\nIt should have no description.\n----------------------------------\n");
TestAction0 ta0("Test0");
ta0.log();
printf("Test1 should have one argument.\nA double equal to 1.\nIt should have no description.\n----------------------------------\n");
TestAction1 ta1("Test1");
ta1.log();
printf("Test3 should have 3 arguments.\nA double, an int, and a string equal to 3.\nIt should also have a description.\n----------------------------------\n");
TestAction3 ta3("Test3", "The real test class");
ta3.log();
printf("Okay, now the automated test bit:\n");
arg = ta3.getArg(0);
if (arg->getType() == ArArg::DOUBLE && arg->getDouble() == 3 &&
ta3.myDouble == 3)
printf("Double argument type and equality: passed.\n");
else
{
printf("Double argument type and equality: FAILED.\n");
exit(1);
}
arg->setDouble(6);
printf("Double argument setting: %f %f:", arg->getDouble(), ta3.myDouble);
if (arg->getDouble() == 6 && ta3.myDouble == 6)
printf(" passed\n");
else
{
printf(" FAILED\n");
exit(1);
}
arg = ta3.getArg(1);
if (arg->getType() == ArArg::INT && arg->getInt() == 3 &&
ta3.myInt == 3)
printf("Int argument type and equality: passed.\n");
else
{
printf("Int argument type and equality: FAILED.\n");
exit(1);
}
arg->setInt(6);
printf("Int argument setting: %d %d:", arg->getInt(), ta3.myInt);
if (arg->getInt() == 6 && ta3.myInt == 6)
printf(" passed\n");
else
{
printf(" FAILED\n");
exit(1);
}
arg = ta3.getArg(2);
if (arg->getType() == ArArg::STRING && strcmp(arg->getString(), "3") == 0 &&
strcmp(ta3.myString, "3") == 0)
printf("String argument type and equality: passed.\n");
else
{
printf("String argument type and equality: FAILED.\n");
exit(1);
}
arg->setString("6");
printf("String argument setting: %s %s:", arg->getString(),
ta3.myString);
if (strcmp(arg->getString(), "6") == 0 && strcmp(ta3.myString, "6") == 0)
printf(" passed\n");
else
{
printf(" FAILED\n");
exit(1);
}
printf("\nAll tests PASSED\n");
}
|