Commit 3efb66c8 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Commandline patch

parent 5bbeef85
...@@ -31,7 +31,7 @@ TRIBITS_ADD_LIBRARY(radixcore ...@@ -31,7 +31,7 @@ TRIBITS_ADD_LIBRARY(radixcore
IF(MINGW) IF(MINGW)
FIND_LIBRARY(PSAPI psapi) FIND_LIBRARY(PSAPI psapi)
MESSAGE(STATUS "Checking required PSAPI library") MESSAGE(STATUS "Checking required PSAPI library")
TARGET_LINK_LIBRARIES(radixcore "${PSAPI}") TARGET_LINK_LIBRARIES(radixcore "-lpsapi")
ENDIF() ENDIF()
# #
# Add testing directory # Add testing directory
......
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#include <typeinfo> #include <typeinfo>
#include "radixcore/bug.hh"
#include "radixcore/commandline.hh" #include "radixbug/bug.hh"
#include "radixcommand/commandline.hh"
#include "radixcore/stringfunctions.hh"
namespace radix namespace radix
{ {
template <typename return_type> template <typename return_type>
...@@ -31,7 +34,16 @@ return_type CommandLine::get(const std::string &name) const ...@@ -31,7 +34,16 @@ return_type CommandLine::get(const std::string &name) const
// ss >> result; // ss >> result;
// Fortify does not like >> operator (string termination) // Fortify does not like >> operator (string termination)
if (typeid(int) == typeid(return_type)) if (typeid(bool) == typeid(return_type))
{
if (value[0] == '1') return true;
if (value[0] == '0') return false;
std::string lower = radix::string_tolower(value);
if (lower.compare("true") == 0) return true;
return false;
}
else if (typeid(int) == typeid(return_type))
result = stoi(value); result = stoi(value);
else if (typeid(long) == typeid(return_type)) else if (typeid(long) == typeid(return_type))
result = stol(value); result = stol(value);
......
...@@ -94,3 +94,26 @@ TEST(radixcommand, args) ...@@ -94,3 +94,26 @@ TEST(radixcommand, args)
std::string a5 = line.arg<std::string>(5); std::string a5 = line.arg<std::string>(5);
EXPECT_EQ("input 6", a5); EXPECT_EQ("input 6", a5);
} }
TEST(radixcommand, GetBool)
{
int fake_argc = 6;
char *fake_argv[] = {(char *)("/Users/jap/build/release/dummy"),
(char *)"-a=1",
(char *)"-b=0",
(char *)"-c=true",
(char *)"-d=false",
(char *)"-r=random"};
CommandLine line(fake_argc, fake_argv);
line.addOption("a", "Numeric true bool.", true);
line.addOption("b", "Numeric false bool.", true);
line.addOption("c", "Alpha true bool.", true);
line.addOption("d", "Alpha false bool.", true);
line.addOption("r", "Default Alpha false bool.", true);
EXPECT_TRUE(line.get<bool>("a"));
EXPECT_FALSE(line.get<bool>("b"));
EXPECT_TRUE(line.get<bool>("c"));
EXPECT_FALSE(line.get<bool>("d"));
EXPECT_FALSE(line.get<bool>("r"));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment