Skip to content

Commit

Permalink
Add tests for short version option (-V).
Browse files Browse the repository at this point in the history
Signed-off-by: David Antliff <[email protected]>
  • Loading branch information
David Antliff committed Apr 1, 2016
1 parent 0248a9e commit 8f25e64
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
14 changes: 6 additions & 8 deletions api/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set (test_api_runner_SOURCES
support/support.cc
support/process.cc
support/daemon.cc

test_log.cc
test_error.cc
test_lwm2m_error.cc
Expand Down Expand Up @@ -34,17 +34,17 @@ set (test_api_runner_SOURCES
test_session_common.cc
test_define_operation.cc
test_value.cc

test_client_session.cc
test_client_define_operation.cc
test_client_define_defaults.cc
test_set_operation.cc
test_get_operation.cc
test_client_delete_operation.cc
test_server_delete_operation.cc
test_subscribe_operation.cc
test_observe_operation.cc
test_subscribe_operation.cc
test_observe_operation.cc

test_server_session.cc
test_server_define_operation.cc
test_server_define_defaults.cc
Expand All @@ -56,7 +56,7 @@ set (test_api_runner_SOURCES
test_changeset.cc
test_subscribe_observe_common.cc
test_execute_operation.cc

test_bootstrap.cc
test_daemon.cc
)
Expand Down Expand Up @@ -115,5 +115,3 @@ if (RUN_TESTS)
DEPENDS test_api_runner_out.xml
)
endif ()


2 changes: 1 addition & 1 deletion api/tests/support/process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

namespace Awa {

pid_t SpawnProcess(std::vector<const char *> &commandVector, bool wait_, bool silent)
pid_t SpawnProcess(const std::vector<const char *> &commandVector, bool wait_, bool silent)
{
pid_t c_pid, pid;

Expand Down
2 changes: 1 addition & 1 deletion api/tests/support/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Awa {
// Note that the type of the vector must be char *, not const char *.
// If true, wait specifies that the parent should wait for the child to terminate.
// If true, silent specifies that the child's stdout will be redirected to /dev/null.
pid_t SpawnProcess(std::vector<const char *> &commandVector, bool wait, bool silent);
pid_t SpawnProcess(const std::vector<const char *> &commandVector, bool wait, bool silent);

// Kill an existing process, with SIGKILL.
void KillProcess(pid_t pid);
Expand Down
49 changes: 39 additions & 10 deletions api/tests/test_daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TestDaemonVersion : public TestDaemon, public CaptureStdout
{
protected:
static void SetUpTestCase() {
expectedOutput = VERSION + std::string("\n");
expectedVersion = VERSION + std::string("\n");
}

virtual void SetUp() {
Expand All @@ -50,13 +50,7 @@ class TestDaemonVersion : public TestDaemon, public CaptureStdout
CaptureStdout::TearDown();
}

void CheckVersionOption(const char * daemonPath)
{
// suppress "deprecated conversion from string constant" warning
#pragma GCC diagnostic ignored "-Wwrite-strings"
std::vector<const char *> commandVector { daemonPath, "--version" };
#pragma GCC diagnostic pop

void CheckOutput(const std::vector<const char *> & commandVector, const std::string expectedOutput) {
pid_t pid = SpawnProcess(commandVector, false, false);
ASSERT_GT(pid, 0);

Expand All @@ -70,10 +64,30 @@ class TestDaemonVersion : public TestDaemon, public CaptureStdout
EXPECT_STREQ(expectedOutput.c_str(), output);
}

static std::string expectedOutput;
void CheckVersionOption(const char * daemonPath)
{
// suppress "deprecated conversion from string constant" warning
#pragma GCC diagnostic ignored "-Wwrite-strings"
std::vector<const char *> commandVector { daemonPath, "--version" };
#pragma GCC diagnostic pop

CheckOutput(commandVector, expectedVersion);
}

void CheckShortVersionOption(const char * daemonPath)
{
// suppress "deprecated conversion from string constant" warning
#pragma GCC diagnostic ignored "-Wwrite-strings"
std::vector<const char *> commandVector { daemonPath, "-V" };
#pragma GCC diagnostic pop

CheckOutput(commandVector, expectedVersion);
}

static std::string expectedVersion;
};

std::string TestDaemonVersion::expectedOutput = std::string();
std::string TestDaemonVersion::expectedVersion = std::string();

TEST_F(TestDaemonVersion, bootstrap_prints_version)
{
Expand All @@ -90,6 +104,21 @@ TEST_F(TestDaemonVersion, server_prints_version)
CheckVersionOption(global::serverDaemonPath);
}

TEST_F(TestDaemonVersion, bootstrap_prints_version_short)
{
CheckShortVersionOption(global::bootstrapServerDaemonPath);
}

TEST_F(TestDaemonVersion, client_prints_version_short)
{
CheckShortVersionOption(global::clientDaemonPath);
}

TEST_F(TestDaemonVersion, server_prints_version_short)
{
CheckShortVersionOption(global::serverDaemonPath);
}

// TODO: test that --logFile/-l option with --version/-V writes to log, not stdout.

} // namespace Awa
Expand Down

0 comments on commit 8f25e64

Please sign in to comment.