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

add test code for multibyte string #530

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 13 additions & 0 deletions test/test_roscpp/test/src/service_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ TEST(SrvCall, callSrv)
ASSERT_STREQ(res.str.c_str(), "CASE_flip");
}

TEST(SrvCall, callSrvUnicode)
{
test_roscpp::TestStringString::Request req;
test_roscpp::TestStringString::Response res;

req.str = std::string("ロボット");

ASSERT_TRUE(ros::service::waitForService("service_adv"));
ASSERT_TRUE(ros::service::call("service_adv", req, res));

ASSERT_STREQ(res.str.c_str(), "ロボット");
}

TEST(SrvCall, callSrvMultipleTimes)
{
test_roscpp::TestStringString::Request req;
Expand Down
23 changes: 23 additions & 0 deletions test/test_rospy/test/rostest/test_basic_services.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Software License Agreement (BSD License)
#
# Copyright (c) 2008, Willow Garage, Inc.
Expand Down Expand Up @@ -213,6 +214,28 @@ def test_String_String(self):
resp_req_kwds = self._test_req_kwds(name, Cls, {'str': String('FOO'), 'str2': Val('bar')})
for resp in [resp_req, resp_req_naked, resp_req_kwds]:
self.assertEquals('FOObar', resp.str.data)

def test_String_String_unicode(self):
from std_msgs.msg import String
from test_rospy.srv import StringString, StringStringRequest
from test_rospy.msg import Val
import sys
Cls = StringString
Req = StringStringRequest

for name in [STRING_CAT_SERVICE_NAKED, STRING_CAT_SERVICE_WRAPPED]:
if sys.version_info.major < '3':
resp_req = self._test(name, Cls, Req(String(u'ロボット'), Val(u'机器人')))
resp_req_naked = self._test_req_naked(name, Cls, (String(u'ロボット'), Val(u'机器人'),))
resp_req_kwds = self._test_req_kwds(name, Cls, {'str': String(u'ロボット'), 'str2': Val(u'机器人')})
for resp in [resp_req, resp_req_naked, resp_req_kwds]:
self.assertEquals('ロボット机器人', resp.str.data) # if you send in unicode, you'll receive in str
else:
resp_req = self._test(name, Cls, Req(String('ロボット'), Val('机器人')))
resp_req_naked = self._test_req_naked(name, Cls, (String('ロボット'), Val('机器人'),))
resp_req_kwds = self._test_req_kwds(name, Cls, {'str': String('ロボット'), 'str2': Val('机器人')})
for resp in [resp_req, resp_req_naked, resp_req_kwds]:
self.assertEquals('ロボット机器人', resp.str.data)

def test_constants(self):
Cls = ConstantsMultiplex
Expand Down