-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug in
create
where command line arguments were truncated (#472)
Signed-off-by: Addisu Z. Taddese <[email protected]>
- Loading branch information
Showing
5 changed files
with
118 additions
and
2 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
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,56 @@ | ||
// Copyright 2023 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
#include <gz/msgs/boolean.pb.h> | ||
#include <gz/msgs/entity_factory.pb.h> | ||
#include <csignal> | ||
#include <chrono> | ||
#include <condition_variable> | ||
#include <functional> | ||
#include <mutex> | ||
#include <gz/transport/Node.hh> | ||
|
||
// Simple application that provides a `/create` service and prints out the | ||
// sdf_filename of the request. This works in conjection with | ||
// test_create_node.launch.py | ||
int main() | ||
{ | ||
std::mutex m; | ||
std::condition_variable cv; | ||
bool test_complete = false; | ||
|
||
gz::transport::Node node; | ||
auto cb = std::function( | ||
[&]( | ||
const gz::msgs::EntityFactory & _req, | ||
gz::msgs::Boolean & _res) -> bool { | ||
std::cout << _req.sdf_filename() << std::endl; | ||
_res.set_data(true); | ||
|
||
{ | ||
std::lock_guard<std::mutex> lk(m); | ||
test_complete = true; | ||
} | ||
cv.notify_one(); | ||
return true; | ||
}); | ||
|
||
node.Advertise("/world/default/create", cb); | ||
// wait until we receive a message. | ||
std::unique_lock<std::mutex> lk(m); | ||
cv.wait(lk, [&] {return test_complete;}); | ||
// Sleep so that the service response can be sent before exiting. | ||
std::this_thread::sleep_for(std::chrono::seconds(1)); | ||
} |
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,47 @@ | ||
# Copyright 2023 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
from launch import LaunchDescription | ||
|
||
from launch_ros.actions import Node | ||
|
||
import launch_testing | ||
|
||
|
||
def generate_test_description(): | ||
expected_file_name = 'nonexistent/long/file_name' | ||
create = Node(package='ros_gz_sim', executable='create', | ||
arguments=['-world', 'default', '-file', expected_file_name], output='screen') | ||
test_create = Node(package='ros_gz_sim', executable='test_create', output='screen') | ||
return LaunchDescription([ | ||
create, | ||
test_create, | ||
launch_testing.util.KeepAliveProc(), | ||
launch_testing.actions.ReadyToTest(), | ||
]), locals() | ||
|
||
|
||
class WaitForTests(unittest.TestCase): | ||
|
||
def test_termination(self, test_create, proc_info): | ||
proc_info.assertWaitForShutdown(process=test_create, timeout=200) | ||
|
||
|
||
@launch_testing.post_shutdown_test() | ||
class CreateTest(unittest.TestCase): | ||
|
||
def test_output(self, expected_file_name, test_create, proc_output): | ||
launch_testing.asserts.assertInStdout(proc_output, expected_file_name, test_create) |