Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator: Add missing std namespace to string arguments (#242) #276

Merged
merged 3 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/ignition/msgs/Generator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class Generator : public CodeGenerator
/// \param[in] _generatorContext Output directory.
/// \param[in] _error Unused string value
public: virtual bool Generate(const FileDescriptor *_file,
const string &_parameter,
const std::string &_parameter,
OutputDirectory *_generatorContext,
string *_error) const;
std::string *_error) const;

// private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Generator);
};
Expand Down
2 changes: 1 addition & 1 deletion src/Generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Generator::~Generator()

/////////////////////////////////////////////////
bool Generator::Generate(const FileDescriptor *_file,
const string &/*_parameter*/,
const std::string &/*_parameter*/,
OutputDirectory *_generatorContext,
std::string * /*_error*/) const
{
Expand Down
31 changes: 31 additions & 0 deletions test/test_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,35 @@
#define IGN_CONFIG_PATH "@CMAKE_BINARY_DIR@/test/conf"
#define IGN_TEST_LIBRARY_PATH "${PROJECT_BINARY_DIR}/src"

#if (_MSC_VER >= 1400) // Visual Studio 2005
#include <sstream>

/// \brief setenv/unstenv are not present in Windows. Define them to make
/// the code portable.
/// \param[in] _name Variable name.
/// \param[in] _value Value.
/// \param[in] _rewrite If 'name' does exist in the environment, then its
/// value is changed to 'value' if 'rewrite' is nonzero. If overwrite is
/// zero, then the value of 'name' is not changed.
/// /return 0 on success or -1 on error.
int setenv(const char *_name, const char *_value, int /*_rewrite*/)
{
std::stringstream sstr;
std::string name = _name;
std::string value = _value;
sstr << name << '=' << value;
return _putenv(sstr.str().c_str());
}

/// \brief Deletes an environment variable.
/// \param[in] _name Variable name.
void unsetenv(const char *_name)
{
std::stringstream sstr;
std::string name = _name;
sstr << name << '=';
_putenv(sstr.str().c_str());
}
#endif

#endif
7 changes: 6 additions & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ include_directories(
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/test
)

set (test_sources
ign_TEST.cc
)

# Skip command line tests for Windows, see
# https://bitbucket.org/ignitionrobotics/ign-msgs/issues/28
if (MSVC)
list(REMOVE_ITEM test_sources ign_TEST.cc)
endif()

if (IGNITION-TOOLS_BINARY_DIRS)
ign_build_tests(TYPE UNIT SOURCES ${test_sources})
endif ()
7 changes: 5 additions & 2 deletions tools/ign_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#include <ignition/msgs/config.hh>
#include "ignition/msgs/test_config.h"

#ifdef _MSC_VER
# define popen _popen
# define pclose _pclose
#endif

static const std::string g_version(std::string(IGNITION_MSGS_VERSION_FULL));

/////////////////////////////////////////////////
Expand Down Expand Up @@ -94,15 +99,13 @@ int main(int argc, char **argv)

// Make sure that we load the library recently built and not the one installed
// in your system.
#ifndef _WIN32
// Add the directory where ignition msgs has been built.
std::string value = std::string(IGN_TEST_LIBRARY_PATH);
// Save the current value of LD_LIBRARY_PATH.
auto cvalue = std::getenv("LD_LIBRARY_PATH");
if (cvalue)
value += ":" + std::string(cvalue);
setenv("LD_LIBRARY_PATH", value.c_str(), 1);
#endif

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down