Added missing source file

This commit is contained in:
Brian Gerkey 2009-10-27 20:30:54 +00:00
parent e96f899a5c
commit a84890bec6
1 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,102 @@
/*
* Copyright (c) 2008, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Author: Brian Gerkey */
#include <string>
#include <vector>
#include <stdlib.h>
#include <unistd.h>
#include <gtest/gtest.h>
#include "ros/package.h"
void string_split(const std::string &s, std::vector<std::string> &t, const std::string &d)
{ t.clear();
size_t start = 0, end;
while ((end = s.find_first_of(d, start)) != std::string::npos)
{
if((end-start) > 0)
t.push_back(s.substr(start, end-start));
start = end + 1;
}
if(start < s.size())
t.push_back(s.substr(start));
}
TEST(roslib, commandListNames)
{
char buf[1024];
std::string rr = std::string(getcwd(buf, sizeof(buf)));
setenv("ROS_ROOT", rr.c_str(), 1);
setenv("ROS_PACKAGE_PATH", rr.c_str(), 1);
std::string output = ros::package::command("list-names");
std::vector<std::string> output_list;
string_split(output, output_list, "\n");
ASSERT_EQ((int)output_list.size(), 1);
ASSERT_STREQ(output_list[0].c_str(), "test_roslib");
}
TEST(roslib, commandList)
{
char buf[1024];
std::string rr = std::string(getcwd(buf, sizeof(buf)));
setenv("ROS_ROOT", rr.c_str(), 1);
setenv("ROS_PACKAGE_PATH", rr.c_str(), 1);
std::string output = ros::package::command("list");
std::vector<std::string> output_list;
std::vector<std::string> name_path;
string_split(output, output_list, "\n");
ASSERT_EQ((int)output_list.size(), 1);
string_split(output_list[0], name_path, " ");
ASSERT_EQ((int)name_path.size(), 2);
ASSERT_STREQ(name_path[0].c_str(), "test_roslib");
}
TEST(roslib, getAll)
{
char buf[1024];
std::string rr = std::string(getcwd(buf, sizeof(buf)));
setenv("ROS_ROOT", rr.c_str(), 1);
setenv("ROS_PACKAGE_PATH", rr.c_str(), 1);
std::vector<std::string> output_list;
ASSERT_TRUE(ros::package::getAll(output_list));
ASSERT_EQ((int)output_list.size(), 1);
ASSERT_STREQ(output_list[0].c_str(), "test_roslib");
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}