check_model.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 /* Author: John Hsu */
00036 
00037 #include <string>
00038 #include <gtest/gtest.h>
00039 #include "gazebo/GetWorldProperties.h"
00040 #include "geometry_msgs/Pose.h"
00041 #include "std_srvs/Empty.h"
00042 
00043 #include <sstream>
00044 #include <tinyxml.h>
00045 #include <boost/lexical_cast.hpp>
00046 
00047 // Including ros, just to be able to call ros::init(), to remove unwanted
00048 // args from command-line.
00049 #include <ros/ros.h>
00050 
00051 int g_argc;
00052 char** g_argv;
00053 
00054 TEST(SpawnTest, spawnSingleBox)
00055 {
00056   ros::NodeHandle nh("");
00057   // make the service call to spawn model
00058   ros::service::waitForService("gazebo/get_world_properties");
00059   ros::ServiceClient check_model_client = nh.serviceClient<gazebo::GetWorldProperties>("gazebo/get_world_properties");
00060   gazebo::GetWorldProperties world_properties;
00061 
00062 
00063   bool found = false;
00064 
00065   // test duration
00066   double test_duration = 10.0; // default to 10 seconds sim time
00067   try
00068   {
00069     test_duration = boost::lexical_cast<double>(g_argv[1]);
00070   }
00071   catch (boost::bad_lexical_cast &e)
00072   {
00073     ROS_ERROR("first argument of check_model should be timeout");
00074     return;
00075   }
00076   ros::Time timeout = ros::Time::now() + ros::Duration(test_duration);
00077 
00078   // model name to look for
00079   std::string model_name = std::string(g_argv[2]);
00080   ROS_INFO("looking for model: %s",model_name.c_str());
00081 
00082   while (!found && ros::Time::now() < timeout)
00083   {
00084     check_model_client.call(world_properties);
00085     for (std::vector<std::string>::iterator mit = world_properties.response.model_names.begin();
00086                                             mit != world_properties.response.model_names.end();
00087                                             mit++)
00088     {
00089       if (*mit == model_name)
00090       {
00091         found = true;
00092         break;
00093       }
00094     }
00095   }
00096 
00097   ASSERT_TRUE(found);
00098 
00099   SUCCEED();
00100 }
00101 
00102 
00103 
00104 
00105 int main(int argc, char** argv)
00106 {
00107   ros::init(argc, argv, "test", ros::init_options::AnonymousName);
00108   testing::InitGoogleTest(&argc, argv);
00109   g_argc = argc;
00110   g_argv = argv;
00111   return RUN_ALL_TESTS();
00112 }


gazebo_tests
Author(s): John Hsu
autogenerated on Sun Jan 5 2014 11:35:20