-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for the pcp::get_pcp_runtime_version overloads.
- Loading branch information
Showing
6 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright Paul Colby 2014. | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE.md or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include <map> | ||
#include <string> | ||
|
||
/// @brief Test values to be returned by our mock pmGetConfig implementation. | ||
extern std::map<std::string, char *> fake_pm_config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright Paul Colby 2014. | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE.md or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include "fake_libpcp.h" | ||
|
||
#include "pcp-cpp/config.hpp" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
TEST(get_pcp_runtime_version, numeric) { | ||
fake_pm_config.clear(); | ||
|
||
// Typical PCP version strings. | ||
fake_pm_config["PCP_VERSION"] = const_cast<char *>("1.2.3"); | ||
EXPECT_EQ(0x10203, pcp::get_pcp_runtime_version<int32_t>()); | ||
fake_pm_config["PCP_VERSION"] = const_cast<char *>("4.67.78"); | ||
EXPECT_EQ(0x4434E, pcp::get_pcp_runtime_version<int32_t>()); | ||
|
||
// Edge cases. | ||
fake_pm_config["PCP_VERSION"] = const_cast<char *>("0.0.0"); | ||
EXPECT_EQ(0, pcp::get_pcp_runtime_version<int32_t>()); | ||
fake_pm_config["PCP_VERSION"] = const_cast<char *>("255.255.255"); | ||
EXPECT_EQ(0xFFFFFF, pcp::get_pcp_runtime_version<int32_t>()); | ||
|
||
// Funky / bad / invalid versions. | ||
fake_pm_config["PCP_VERSION"] = const_cast<char *>("not a version string"); | ||
EXPECT_EQ(0, pcp::get_pcp_runtime_version<int32_t>()); | ||
fake_pm_config["PCP_VERSION"] = const_cast<char *>("1"); | ||
EXPECT_EQ(0, pcp::get_pcp_runtime_version<int32_t>()); | ||
fake_pm_config["PCP_VERSION"] = const_cast<char *>("1.2"); | ||
EXPECT_EQ(0, pcp::get_pcp_runtime_version<int32_t>()); | ||
fake_pm_config["PCP_VERSION"] = const_cast<char *>("1.2.4.5.6.7.8.9"); | ||
EXPECT_EQ(0x10209, pcp::get_pcp_runtime_version<int32_t>()); | ||
|
||
fake_pm_config.clear(); | ||
} | ||
|
||
TEST(get_pcp_runtime_version, string) { | ||
fake_pm_config.clear(); | ||
|
||
// The get_pcp_runtime_version<char *> specialisation simply returns the | ||
// pmGetValue value verbatim. | ||
fake_pm_config["PCP_VERSION"] = const_cast<char *>(""); | ||
EXPECT_STREQ("", pcp::get_pcp_runtime_version<char *>()); | ||
fake_pm_config["PCP_VERSION"] = const_cast<char *>("1.2.3"); | ||
EXPECT_STREQ("1.2.3", pcp::get_pcp_runtime_version<char *>()); | ||
fake_pm_config["PCP_VERSION"] = const_cast<char *>("4.5.6"); | ||
EXPECT_STREQ("4.5.6", pcp::get_pcp_runtime_version<char *>()); | ||
|
||
fake_pm_config.clear(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters