Skip to content

Commit

Permalink
add test code for multibyte string (ros#985)
Browse files Browse the repository at this point in the history
* add test code for multibyte string

* merge Python 2 and 3 code paths
  • Loading branch information
dirk-thomas authored Feb 14, 2017
1 parent c9ce9b4 commit 468ed43
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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
17 changes: 16 additions & 1 deletion 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,7 +214,21 @@ 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
Cls = StringString
Req = StringStringRequest

for name in [STRING_CAT_SERVICE_NAKED, STRING_CAT_SERVICE_WRAPPED]:
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

def test_constants(self):
Cls = ConstantsMultiplex
Req = ConstantsMultiplexRequest
Expand Down

0 comments on commit 468ed43

Please sign in to comment.