29 using namespace basis;
39 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
48 virtual int execute();
58 const char *last_period = 0;
59 bool got_digit =
false;
60 for (
const char *address = input.
s(); *address; address++) {
61 if ( (*address <=
'9') && (*address >=
'0') ) {
63 current_byte += *address -
'0';
65 }
else if (*address ==
'.') {
67 if (last_period + 1 == address) {
68 LOG(
"The IP address entry has an empty digit. Exiting.");
71 last_period = address;
72 if (current_byte > 255) {
73 LOG(
"The IP address entry has an illegal abyte. Exiting.");
76 ip_address[index] =
abyte(current_byte);
82 LOG(
"The IP address entry has illegal characters. Exiting.");
87 if ( (index == 3) && got_digit) {
88 if (current_byte > 255) {
89 LOG(
"The IP address entry has an illegal abyte. Exiting.");
92 ip_address[index] = current_byte;
93 }
else if (index < 4) {
94 LOG(
"The IP address entry is too short. Exiting.");
100 int test_spocket::execute()
105 bool is_client =
false;
109 const char *DEFAULT_HOST =
"127.0.0.1";
110 const int DEFAULT_PORT = 12348;
111 const int DEFAULT_SEND_SIZE = 1008;
112 const int DEFAULT_SEND_COUNT = 10;
117 This program takes five command line arguments to begin operation.\n\
118 These arguments (in order) are:\n\
119 \tIP address\t\tIn the form w.x.y.z\n\
120 \tPort number\t\tAs a short integer\n\
121 \tTester role\t\tEither \"client\" or \"server\"\n\
122 \tSend size\t\tThe size of the data to exchange.\n\
123 \tSend count\t\tThe number of \"packets\" to exchange.\n\
124 Note: it is expected that the client and server have equal send sizes;\n\
125 this allows the receiver to know when it's gotten all the data that's\n\
126 expected during a cycle.");
129 parse_address(DEFAULT_HOST, ip_address);
130 rcv_port = DEFAULT_PORT;
132 send_size = DEFAULT_SEND_SIZE;
133 send_count = DEFAULT_SEND_COUNT;
142 LOG(
"failed to parse source address.");
147 (
int)ip_address[0], (
int)ip_address[1], (
int)ip_address[2],
148 (
int)ip_address[3]));
152 LOG(
"The port entry is malformed. Exiting.");
160 if (arg3 ==
astring(
"client")) is_client =
true;
161 else if (arg3 ==
astring(
"server")) is_client =
false;
163 LOG(
"The tester role (client/server) is malformed. Exiting.");
166 if (is_client)
LOG(
"\tTester role is \"client\".")
167 else
LOG("\tTester role is \"server\".");
171 LOG(
"The send size entry is malformed. Exiting.");
178 LOG(
"The send count entry is malformed. Exiting.");
181 LOG(
a_sprintf(
"\tGot a send count of %d.", send_count));
198 const char *action = is_client?
"connect" :
"accept";
199 LOG(
astring(
"Failed to ") + action +
" on the tester.");
210 launch_process::RETURN_IMMEDIATELY, kidnum);
211 ASSERT_EQUAL(result, 0,
"launching paired process should start successfully");
217 const char *action = is_client?
"connect" :
"accept";
218 LOG(
astring(
"Failed to ") + action +
" on the tester.");
228 LOG(
"Failed out of send_data; maybe other side terminated.");
239 LOG(
"\t\tsend stats\t\treceive stats");
240 LOG(
"\t\t----------\t\t-------------");
The application_shell is a base object for console programs.
a_sprintf is a specialization of astring that provides printf style support.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
void to_lower()
to_lower modifies "this" by replacing capitals with lower-case.
A very common template for a dynamic array of bytes.
Outcomes describe the state of completion for an operation.
Provides the capability to start processes in a variety of ways to run other applications.
static basis::un_int run(const basis::astring &app_name, const basis::astring &command_line, int flag, basis::un_int &child_id)
starts an application using the "app_name" as the executable to run.
this type of address describes a destination out on the internet.
bool perform_test(int size, int count, testing_statistics &stats_to_fill)
bool accept(bool wait=true)
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Provides macros that implement the 'main' program of an application.
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
unsigned char abyte
A fairly important unit which is seldom defined...
unsigned int un_int
Abbreviated name for unsigned integers.
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
Provides access to the operating system's socket methods.
A dynamic container class that holds any kind of object via pointers.
Useful support functions for unit testing, especially within hoople.
abyte ip_address_holder[4]
HOOPLE_MAIN(test_spocket,)
#define ASSERT_EQUAL(a, b, test_name)