test: Allow command line override of mock server port

pull/34/head
David Drysdale 10 years ago
parent 2aa07c7d02
commit 3907b6dc68
  1. 9
      test/ares-test-main.cc
  2. 3
      test/ares-test.cc
  3. 1
      test/ares-test.h

@ -1,8 +1,4 @@
#include <sys/types.h> #include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <pwd.h>
#include <iostream>
#include "ares-test.h" #include "ares-test.h"
@ -11,6 +7,9 @@ int main(int argc, char* argv[]) {
for (int ii = 1; ii < argc; ii++) { for (int ii = 1; ii < argc; ii++) {
if (strcmp(argv[ii], "-v") == 0) { if (strcmp(argv[ii], "-v") == 0) {
ares::test::verbose = true; ares::test::verbose = true;
} else if ((strcmp(argv[ii], "-p") == 0) && (ii + 1 < argc)) {
ii++;
ares::test::mock_port = atoi(argv[ii]);
} }
} }

@ -56,6 +56,7 @@ void ProcessWork(ares_channel channel,
} // namespace } // namespace
bool verbose = false; bool verbose = false;
int mock_port = 5300;
unsigned long LibraryTest::fails_ = 0; unsigned long LibraryTest::fails_ = 0;
std::map<size_t, int> LibraryTest::size_fails_; std::map<size_t, int> LibraryTest::size_fails_;
@ -218,7 +219,7 @@ void MockServer::ProcessRequest(struct sockaddr_storage* addr, int addrlen,
MockChannelOptsTest::MockChannelOptsTest(struct ares_options* givenopts, MockChannelOptsTest::MockChannelOptsTest(struct ares_options* givenopts,
int optmask) int optmask)
: server_(5300), channel_(nullptr) { : server_(mock_port), channel_(nullptr) {
// Set up channel options. // Set up channel options.
struct ares_options opts; struct ares_options opts;
if (givenopts) { if (givenopts) {

@ -21,6 +21,7 @@ typedef unsigned char byte;
namespace test { namespace test {
extern bool verbose; extern bool verbose;
extern int mock_port;
// Test fixture that ensures library initialization, and allows // Test fixture that ensures library initialization, and allows
// memory allocations to be failed. // memory allocations to be failed.

Loading…
Cancel
Save