Goby v2
test.cpp
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 //
5 //
6 // This file is part of the Goby Underwater Autonomy Project Binaries
7 // ("The Goby Binaries").
8 //
9 // The Goby Binaries are free software: you can redistribute them and/or modify
10 // them under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // The Goby Binaries are distributed in the hope that they will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
21 
22 #include <iostream>
23 
24 #include "basic_node_report.pb.h"
25 #include "goby/common/logger.h"
26 #include "goby/moos/moos_translator.h"
27 #include "goby/util/binary.h"
28 #include "goby/util/sci.h"
29 #include "test.pb.h"
30 
31 using namespace goby::moos;
32 
33 void populate_test_msg(TestMsg* msg_in);
34 void run_one_in_one_out_test(MOOSTranslator& translator, int i, bool hex_encode);
35 
36 int main(int argc, char* argv[])
37 {
38  goby::glog.add_stream(goby::common::logger::DEBUG3, &std::cout);
39  goby::glog.set_name(argv[0]);
40 
42  entry.set_protobuf_name("TestMsg");
43 
44  protobuf::TranslatorEntry::CreateParser* parser = entry.add_create();
45  parser->set_technique(protobuf::TranslatorEntry::TECHNIQUE_PROTOBUF_TEXT_FORMAT);
46  parser->set_moos_var("TEST_MSG_1");
47 
48  protobuf::TranslatorEntry::PublishSerializer* serializer = entry.add_publish();
49  serializer->set_technique(protobuf::TranslatorEntry::TECHNIQUE_PROTOBUF_TEXT_FORMAT);
50  serializer->set_moos_var("TEST_MSG_1");
51 
52  const double LAT_ORIGIN = 42.5;
53  const double LON_ORIGIN = 10.8;
54 
55  MOOSTranslator translator(entry, LAT_ORIGIN, LON_ORIGIN,
56  TRANSLATOR_TEST_DIR "/modemidlookup.txt");
57 
58  CMOOSGeodesy geodesy;
59  geodesy.Initialise(LAT_ORIGIN, LON_ORIGIN);
60 
61  goby::glog << translator << std::endl;
62  run_one_in_one_out_test(translator, 0, false);
63 
64  std::set<protobuf::TranslatorEntry> entries;
65  {
67  entry.set_protobuf_name("TestMsg");
68 
69  protobuf::TranslatorEntry::CreateParser* parser = entry.add_create();
70  parser->set_technique(protobuf::TranslatorEntry::TECHNIQUE_PROTOBUF_NATIVE_ENCODED);
71  parser->set_moos_var("TEST_MSG_1");
72 
73  protobuf::TranslatorEntry::PublishSerializer* serializer = entry.add_publish();
74  serializer->set_technique(protobuf::TranslatorEntry::TECHNIQUE_PROTOBUF_NATIVE_ENCODED);
75  serializer->set_moos_var("TEST_MSG_1");
76 
77  entries.insert(entry);
78  }
79 
80  translator.clear_entry("TestMsg");
81  translator.add_entry(entries);
82 
83  goby::glog << translator << std::endl;
84  run_one_in_one_out_test(translator, 1, true);
85 
86  {
88  entry.set_protobuf_name("TestMsg");
89 
90  protobuf::TranslatorEntry::CreateParser* parser = entry.add_create();
91  parser->set_technique(
92  protobuf::TranslatorEntry::TECHNIQUE_COMMA_SEPARATED_KEY_EQUALS_VALUE_PAIRS);
93  parser->set_moos_var("TEST_MSG_1");
94 
95  protobuf::TranslatorEntry::PublishSerializer* serializer = entry.add_publish();
96  serializer->set_technique(
97  protobuf::TranslatorEntry::TECHNIQUE_COMMA_SEPARATED_KEY_EQUALS_VALUE_PAIRS);
98  serializer->set_moos_var("TEST_MSG_1");
99 
100  translator.clear_entry(entry.protobuf_name());
101  translator.add_entry(entry);
102  }
103 
104  goby::glog << translator << std::endl;
105  run_one_in_one_out_test(translator, 2, false);
106 
107  {
109  entry.set_protobuf_name("TestMsg");
110 
111  protobuf::TranslatorEntry::CreateParser* parser = entry.add_create();
112  parser->set_technique(protobuf::TranslatorEntry::TECHNIQUE_PREFIXED_PROTOBUF_NATIVE_HEX);
113  parser->set_moos_var("TEST_MSG_1");
114 
115  protobuf::TranslatorEntry::PublishSerializer* serializer = entry.add_publish();
116  serializer->set_technique(
117  protobuf::TranslatorEntry::TECHNIQUE_PREFIXED_PROTOBUF_NATIVE_HEX);
118  serializer->set_moos_var("TEST_MSG_1");
119 
120  translator.clear_entry(entry.protobuf_name());
121  translator.add_entry(entry);
122  }
123 
124  goby::glog << translator << std::endl;
125  run_one_in_one_out_test(translator, 3, false);
126 
127  std::string format_str = "NAME=%1%,X=%202%,Y=%3%,HEADING=%201%,REPEAT={%10%}";
128  {
129  std::string repeat_format_str =
130  format_str + ",REPEAT={%10.0%,%10.1%,%10.2%,%10.3%,%10.4%,%10.5%,%10.6%,%10.7%,%10.8%,%"
131  "10.9%,%10.10%,%10.11%}";
133  entry.set_protobuf_name("BasicNodeReport");
134 
135  protobuf::TranslatorEntry::CreateParser* parser = entry.add_create();
136  parser->set_technique(protobuf::TranslatorEntry::TECHNIQUE_FORMAT);
137  parser->set_moos_var("NODE_REPORT");
138  parser->set_format(repeat_format_str);
139 
140  protobuf::TranslatorEntry::PublishSerializer* serializer = entry.add_publish();
141  serializer->set_technique(protobuf::TranslatorEntry::TECHNIQUE_FORMAT);
142  serializer->set_moos_var("NODE_REPORT");
143  serializer->set_format(repeat_format_str);
144 
145  translator.clear_entry(entry.protobuf_name());
146  translator.add_entry(entry);
147  }
148 
149  goby::glog << translator << std::endl;
150 
151  BasicNodeReport report;
152  report.set_name("unicorn");
153  report.set_x(550);
154  report.set_y(1023.5);
155  report.set_heading(240);
156  report.add_repeat(1);
157  report.add_repeat(-1);
158  report.add_repeat(2);
159  report.add_repeat(-2);
160  report.add_repeat(3);
161  report.add_repeat(-3);
162  report.add_repeat(4);
163  report.add_repeat(-4);
164  report.add_repeat(5);
165  report.add_repeat(-5);
166  report.add_repeat(6);
167  report.add_repeat(-6);
168 
169  std::multimap<std::string, CMOOSMsg> moos_msgs = translator.protobuf_to_moos(report);
170 
171  for (std::multimap<std::string, CMOOSMsg>::const_iterator it = moos_msgs.begin(),
172  n = moos_msgs.end();
173  it != n; ++it)
174  {
175  goby::glog << "Variable: " << it->first << "\n"
176  << "Value: " << it->second.GetString() << std::endl;
177  assert(it->second.GetString() ==
178  "NAME=unicorn,X=550,Y=1023.5,HEADING=240,REPEAT={1,-1,2,-2,3,-3,4,-4,5,-5,6,-6},"
179  "REPEAT={1,-1,2,-2,3,-3,4,-4,5,-5,6,-6}");
180  }
181 
182  typedef std::auto_ptr<google::protobuf::Message> GoogleProtobufMessagePointer;
183  GoogleProtobufMessagePointer report_out =
184  translator.moos_to_protobuf<GoogleProtobufMessagePointer>(moos_msgs, "BasicNodeReport");
185 
186  goby::glog << "Message out: " << std::endl;
187  goby::glog << report_out->DebugString() << std::endl;
188  assert(report_out->SerializeAsString() == report.SerializeAsString());
189 
190  {
192  entry.set_protobuf_name("BasicNodeReport");
193 
194  protobuf::TranslatorEntry::CreateParser* parser = entry.add_create();
195  parser->set_technique(protobuf::TranslatorEntry::TECHNIQUE_FORMAT);
196  parser->set_moos_var("NAV_X");
197  parser->set_format("%202%");
198 
199  parser = entry.add_create();
200  parser->set_technique(protobuf::TranslatorEntry::TECHNIQUE_FORMAT);
201  parser->set_moos_var("VEHICLE_NAME");
202  protobuf::TranslatorEntry::CreateParser::Algorithm* algo_in = parser->add_algorithm();
203  algo_in->set_name("to_lower");
204  algo_in->set_primary_field(1);
205  parser->set_format("%1%");
206 
207  parser = entry.add_create();
208  parser->set_technique(
209  protobuf::TranslatorEntry::TECHNIQUE_COMMA_SEPARATED_KEY_EQUALS_VALUE_PAIRS);
210  parser->set_moos_var("NAV_HEADING");
211  algo_in = parser->add_algorithm();
212  algo_in->set_name("angle_0_360");
213  algo_in->set_primary_field(201);
214 
215  parser = entry.add_create();
216  parser->set_technique(protobuf::TranslatorEntry::TECHNIQUE_FORMAT);
217  parser->set_moos_var("NAV_Y");
218  parser->set_format("%3%");
219 
220  protobuf::TranslatorEntry::PublishSerializer* serializer = entry.add_publish();
221  serializer->set_technique(protobuf::TranslatorEntry::TECHNIQUE_FORMAT);
222  serializer->set_moos_var("NODE_REPORT_FORMAT");
223  serializer->set_format(format_str + ";LAT=%100%;LON=%101%;X+Y=%104%,X-Y=%105%");
224 
226  serializer->add_algorithm();
227  algo_out->set_name("utm_x2lon");
228  algo_out->set_output_virtual_field(101);
229  algo_out->set_primary_field(202);
230  algo_out->add_reference_field(3);
231 
232  algo_out = serializer->add_algorithm();
233  algo_out->set_name("utm_y2lat");
234  algo_out->set_output_virtual_field(100);
235  algo_out->set_primary_field(3);
236  algo_out->add_reference_field(202);
237 
238  algo_out = serializer->add_algorithm();
239  algo_out->set_name("name2modem_id");
240  algo_out->set_output_virtual_field(102);
241  algo_out->set_primary_field(1);
242 
243  algo_out = serializer->add_algorithm();
244  algo_out->set_name("name2modem_id");
245  algo_out->set_output_virtual_field(103);
246  algo_out->set_primary_field(1);
247 
248  algo_out = serializer->add_algorithm();
249  algo_out->set_name("modem_id2type");
250  algo_out->set_output_virtual_field(103);
251  algo_out->set_primary_field(1);
252 
253  algo_out = serializer->add_algorithm();
254  algo_out->set_name("to_upper");
255  algo_out->set_output_virtual_field(103);
256  algo_out->set_primary_field(1);
257 
258  algo_out = serializer->add_algorithm();
259  algo_out->set_name("add");
260  algo_out->set_output_virtual_field(104);
261  algo_out->set_primary_field(202);
262  algo_out->add_reference_field(3);
263 
264  algo_out = serializer->add_algorithm();
265  algo_out->set_name("subtract");
266  algo_out->set_output_virtual_field(105);
267  algo_out->set_primary_field(202);
268  algo_out->add_reference_field(3);
269 
270  protobuf::TranslatorEntry::PublishSerializer* serializer2 = entry.add_publish();
271  serializer2->CopyFrom(*serializer);
272  serializer2->clear_format();
273  serializer2->set_technique(
274  protobuf::TranslatorEntry::TECHNIQUE_COMMA_SEPARATED_KEY_EQUALS_VALUE_PAIRS);
275  serializer2->set_moos_var("NODE_REPORT_KEY_VALUE");
276 
277  translator.clear_entry(entry.protobuf_name());
278  translator.add_entry(entry);
279  }
280 
281  goby::glog << translator << std::endl;
282 
283  moos_msgs.clear();
284  moos_msgs.insert(std::make_pair("NAV_X", CMOOSMsg(MOOS_NOTIFY, "NAV_X", report.x())));
285  moos_msgs.insert(std::make_pair("NAV_Y", CMOOSMsg(MOOS_NOTIFY, "NAV_Y", report.y())));
286  moos_msgs.insert(
287  std::make_pair("NAV_HEADING", CMOOSMsg(MOOS_NOTIFY, "NAV_HEADING", "heading=-120")));
288  moos_msgs.insert(
289  std::make_pair("VEHICLE_NAME", CMOOSMsg(MOOS_NOTIFY, "VEHICLE_NAME", "UNICORN")));
290 
291  report_out =
292  translator.moos_to_protobuf<GoogleProtobufMessagePointer>(moos_msgs, "BasicNodeReport");
293 
294  report.clear_repeat();
295 
296  goby::glog << "Message in: " << std::endl;
297  goby::glog << report.DebugString() << std::endl;
298  goby::glog << "Message out: " << std::endl;
299  goby::glog << report_out->DebugString() << std::endl;
300 
301  assert(report_out->SerializeAsString() == report.SerializeAsString());
302 
303  moos_msgs = translator.protobuf_to_moos(*report_out);
304 
305  double expected_lat = 0, expected_lon = 0;
306  geodesy.UTM2LatLong(report.x(), report.y(), expected_lat, expected_lon);
307  const int LAT_INT_DIGITS = 2;
308  const int LON_INT_DIGITS = 3;
309  expected_lat = goby::util::unbiased_round(expected_lat, std::numeric_limits<double>::digits10 -
310  LAT_INT_DIGITS - 1);
311  expected_lon = goby::util::unbiased_round(expected_lon, std::numeric_limits<double>::digits10 -
312  LON_INT_DIGITS - 1);
313 
314  std::stringstream expected_lat_ss, expected_lon_ss;
315  expected_lat_ss << std::setprecision(std::numeric_limits<double>::digits10) << expected_lat;
316  expected_lon_ss << std::setprecision(std::numeric_limits<double>::digits10) << expected_lon;
317  boost::format expected_lat_fmt("%1%");
318  boost::format expected_lon_fmt("%1%");
319  std::string expected_lat_fmt_str =
320  (expected_lat_fmt %
321  boost::io::group(std::setprecision(std::numeric_limits<double>::digits10), expected_lat))
322  .str();
323  std::string expected_lon_fmt_str =
324  (expected_lon_fmt %
325  boost::io::group(std::setprecision(std::numeric_limits<double>::digits10), expected_lon))
326  .str();
327  std::string expected_lat_key_values_str = expected_lat_ss.str();
328  std::string expected_lon_key_values_str = expected_lon_ss.str();
329 
330  for (std::multimap<std::string, CMOOSMsg>::const_iterator it = moos_msgs.begin(),
331  n = moos_msgs.end();
332  it != n; ++it)
333  {
334  goby::glog << "Variable: " << it->first << "\n"
335  << "Value: " << it->second.GetString() << std::endl;
336 
337  goby::glog << "Expected lat (FORMAT): " << expected_lat_fmt_str << std::endl;
338  goby::glog << "Expected lon (FORMAT): " << expected_lon_fmt_str << std::endl;
339  goby::glog << "Expected lat (KEY_VALUES): " << expected_lat_key_values_str << std::endl;
340  goby::glog << "Expected lon (KEY_VALUES): " << expected_lon_key_values_str << std::endl;
341 
342  if (it->first == "NODE_REPORT_FORMAT")
343  assert(it->second.GetString() ==
344  std::string("NAME=unicorn,X=550,Y=1023.5,HEADING=240,REPEAT={};LAT=") +
345  expected_lat_fmt_str + ";LON=" + expected_lon_fmt_str +
346  ";X+Y=1573.5,X-Y=-473.5");
347  else if (it->first == "NODE_REPORT_KEY_VALUE")
348  assert(it->second.GetString() ==
349  std::string("Name=unicorn,x=550,y=1023.5,heading=240,utm_y2lat(y)=") +
350  expected_lat_key_values_str +
351  ",utm_x2lon("
352  "x)=" +
353  expected_lon_key_values_str +
354  ",name2modem_id(Name)=3,name2modem_id+modem_id2type+to_upper("
355  "Name)=AUV,add(x)=1573.5,subtract(x)=-473.5");
356  }
357 
358  std::string sub_message_format_str = "em.val=%17:1%";
359  {
361  entry.set_protobuf_name("TestMsg");
362 
363  protobuf::TranslatorEntry::CreateParser* parser = entry.add_create();
364  parser->set_technique(protobuf::TranslatorEntry::TECHNIQUE_FORMAT);
365  parser->set_moos_var("TEST_MSG_1");
366  parser->set_format(sub_message_format_str);
367 
368  protobuf::TranslatorEntry::PublishSerializer* serializer = entry.add_publish();
369  serializer->set_technique(protobuf::TranslatorEntry::TECHNIQUE_FORMAT);
370  serializer->set_moos_var("TEST_MSG_1");
371  serializer->set_format(sub_message_format_str);
372 
373  translator.clear_entry(entry.protobuf_name());
374  translator.add_entry(entry);
375  }
376 
377  goby::glog << translator << std::endl;
378 
379  TestMsg embedded_test;
380  embedded_test.mutable_msg_default_optional()->set_val(19.998);
381  moos_msgs = translator.protobuf_to_moos(embedded_test);
382 
383  for (std::multimap<std::string, CMOOSMsg>::const_iterator it = moos_msgs.begin(),
384  n = moos_msgs.end();
385  it != n; ++it)
386  {
387  goby::glog << "Variable: " << it->first << "\n"
388  << "Value: " << it->second.GetString() << std::endl;
389  assert(it->second.GetString() == "em.val=19.998");
390  }
391 
392  typedef std::auto_ptr<google::protobuf::Message> GoogleProtobufMessagePointer;
393  GoogleProtobufMessagePointer embedded_test_out =
394  translator.moos_to_protobuf<GoogleProtobufMessagePointer>(moos_msgs, "TestMsg");
395 
396  goby::glog << "Message out: " << std::endl;
397  goby::glog << embedded_test_out->DebugString() << std::endl;
398  assert(embedded_test_out->SerializePartialAsString() ==
399  embedded_test.SerializePartialAsString());
400 
401  sub_message_format_str =
402  "em0.val=%117.0:1%,1uint64=%106.1%,0uint64=%106.0%.2uint64=%106.2%:em1.val=%117.1:1%,dbl0=%"
403  "101.0%,dbl1=%101.1%,dbl2=%101.2%,dbl3=%101.3%,em0.em1.val=%37:2:1%";
404  {
406  entry.set_protobuf_name("TestMsg");
407 
408  protobuf::TranslatorEntry::CreateParser* parser = entry.add_create();
409  parser->set_technique(protobuf::TranslatorEntry::TECHNIQUE_FORMAT);
410  parser->set_moos_var("TEST_MSG_1");
411  parser->set_format(sub_message_format_str);
412 
413  protobuf::TranslatorEntry::PublishSerializer* serializer = entry.add_publish();
414  serializer->set_technique(protobuf::TranslatorEntry::TECHNIQUE_FORMAT);
415  serializer->set_moos_var("TEST_MSG_1");
416  serializer->set_format(sub_message_format_str);
417 
418  translator.clear_entry(entry.protobuf_name());
419  translator.add_entry(entry);
420  }
421 
422  goby::glog << translator << std::endl;
423 
424  embedded_test.Clear();
425  embedded_test.add_msg_default_repeat()->set_val(21.123);
426  embedded_test.add_msg_default_repeat()->set_val(100.5);
427  embedded_test.mutable_msg_default_required()->mutable_msg()->set_val(45);
428  embedded_test.add_uint64_default_repeat(0);
429  embedded_test.add_uint64_default_repeat(100);
430  embedded_test.add_uint64_default_repeat(200);
431  moos_msgs = translator.protobuf_to_moos(embedded_test);
432 
433  for (std::multimap<std::string, CMOOSMsg>::const_iterator it = moos_msgs.begin(),
434  n = moos_msgs.end();
435  it != n; ++it)
436  {
437  goby::glog << "Variable: " << it->first << "\n"
438  << "Value: " << it->second.GetString() << std::endl;
439  assert(it->second.GetString() ==
440  "em0.val=21.123,1uint64=100,0uint64=0.2uint64=200:em1.val=100.5,dbl0=nan,dbl1=nan,"
441  "dbl2=nan,dbl3=nan,em0.em1.val=45");
442  }
443 
444  typedef std::auto_ptr<google::protobuf::Message> GoogleProtobufMessagePointer;
445  embedded_test_out =
446  translator.moos_to_protobuf<GoogleProtobufMessagePointer>(moos_msgs, "TestMsg");
447 
448  goby::glog << "Message out: " << std::endl;
449  goby::glog << embedded_test_out->DebugString() << std::endl;
450 
451  embedded_test.add_double_default_repeat(std::numeric_limits<double>::quiet_NaN());
452  embedded_test.add_double_default_repeat(std::numeric_limits<double>::quiet_NaN());
453  embedded_test.add_double_default_repeat(std::numeric_limits<double>::quiet_NaN());
454  embedded_test.add_double_default_repeat(std::numeric_limits<double>::quiet_NaN());
455  assert(embedded_test_out->SerializePartialAsString() ==
456  embedded_test.SerializePartialAsString());
457 
458  std::cout << "all tests passed" << std::endl;
459 }
460 
461 void run_one_in_one_out_test(MOOSTranslator& translator, int i, bool hex_encode)
462 {
463  TestMsg msg;
464  populate_test_msg(&msg);
465 
466  std::multimap<std::string, CMOOSMsg> moos_msgs = translator.protobuf_to_moos(msg);
467 
468  for (std::multimap<std::string, CMOOSMsg>::const_iterator it = moos_msgs.begin(),
469  n = moos_msgs.end();
470  it != n; ++it)
471  {
472  goby::glog << "Variable: " << it->first << "\n"
473  << "Value: "
474  << (hex_encode ? goby::util::hex_encode(it->second.GetString())
475  : it->second.GetString())
476  << std::endl;
477 
478  switch (i)
479  {
480  case 0:
481  {
482  std::string test;
484  protobuf::TranslatorEntry::TECHNIQUE_PROTOBUF_TEXT_FORMAT>::serialize(&test,
485  msg);
486  ;
487 
488  assert(it->second.GetString() == test);
489  assert(it->first == "TEST_MSG_1");
490  break;
491  }
492 
493  case 1:
494  {
495  assert(it->second.GetString() == msg.SerializeAsString());
496  assert(it->first == "TEST_MSG_1");
497  break;
498  }
499 
500  case 2:
501  {
502  std::string test;
504  protobuf::TranslatorEntry::TECHNIQUE_COMMA_SEPARATED_KEY_EQUALS_VALUE_PAIRS>::
505  serialize(&test, msg,
506  google::protobuf::RepeatedPtrField<
508  assert(it->second.GetString() == test);
509  assert(it->first == "TEST_MSG_1");
510  break;
511  }
512 
513  case 3:
514  {
515  TestMsg msg_out;
517  protobuf::TranslatorEntry::TECHNIQUE_PREFIXED_PROTOBUF_NATIVE_HEX>::
518  parse(it->second.GetString(), &msg_out);
519 
520  assert(msg.SerializeAsString() == msg_out.SerializeAsString());
521  assert(it->first == "TEST_MSG_1");
522  break;
523  }
524 
525  default: assert(false);
526  };
527 
528  ++i;
529  }
530 
531  typedef std::auto_ptr<google::protobuf::Message> GoogleProtobufMessagePointer;
532  GoogleProtobufMessagePointer msg_out =
533  translator.moos_to_protobuf<GoogleProtobufMessagePointer>(moos_msgs, "TestMsg");
534 
535  goby::glog << "Message out: " << std::endl;
536  goby::glog << msg_out->DebugString() << std::endl;
537  assert(msg_out->SerializeAsString() == msg.SerializeAsString());
538 }
539 
540 void populate_test_msg(TestMsg* msg_in)
541 {
542  int i = 0;
543  msg_in->set_double_default_optional(++i + 0.1);
544  msg_in->set_float_default_optional(++i + 0.2);
545 
546  msg_in->set_int32_default_optional(++i);
547  msg_in->set_int64_default_optional(-++i);
548  msg_in->set_uint32_default_optional(++i);
549  msg_in->set_uint64_default_optional(++i);
550  msg_in->set_sint32_default_optional(-++i);
551  msg_in->set_sint64_default_optional(++i);
552  msg_in->set_fixed32_default_optional(++i);
553  msg_in->set_fixed64_default_optional(++i);
554  msg_in->set_sfixed32_default_optional(++i);
555  msg_in->set_sfixed64_default_optional(-++i);
556 
557  msg_in->set_bool_default_optional(true);
558 
559  msg_in->set_string_default_optional("abc123");
560  msg_in->set_bytes_default_optional(goby::util::hex_decode("00112233aabbcc1234"));
561 
562  msg_in->set_enum_default_optional(ENUM_C);
563  msg_in->mutable_msg_default_optional()->set_val(++i + 0.3);
564  msg_in->mutable_msg_default_optional()->mutable_msg()->set_val(++i);
565 
566  msg_in->set_double_default_required(++i + 0.1);
567  msg_in->set_float_default_required(++i + 0.2);
568 
569  msg_in->set_int32_default_required(++i);
570  msg_in->set_int64_default_required(-++i);
571  msg_in->set_uint32_default_required(++i);
572  msg_in->set_uint64_default_required(++i);
573  msg_in->set_sint32_default_required(-++i);
574  msg_in->set_sint64_default_required(++i);
575  msg_in->set_fixed32_default_required(++i);
576  msg_in->set_fixed64_default_required(++i);
577  msg_in->set_sfixed32_default_required(++i);
578  msg_in->set_sfixed64_default_required(-++i);
579 
580  msg_in->set_bool_default_required(true);
581 
582  msg_in->set_string_default_required("abc123");
583  msg_in->set_bytes_default_required(goby::util::hex_decode("00112233aabbcc1234"));
584 
585  msg_in->set_enum_default_required(ENUM_C);
586  msg_in->mutable_msg_default_required()->set_val(++i + 0.3);
587  msg_in->mutable_msg_default_required()->mutable_msg()->set_val(++i);
588 
589  for (int j = 0; j < 2; ++j)
590  {
591  msg_in->add_double_default_repeat(++i + 0.1);
592  msg_in->add_float_default_repeat(++i + 0.2);
593 
594  msg_in->add_int32_default_repeat(++i);
595  msg_in->add_int64_default_repeat(-++i);
596  msg_in->add_uint32_default_repeat(++i);
597  msg_in->add_uint64_default_repeat(++i);
598  msg_in->add_sint32_default_repeat(-++i);
599  msg_in->add_sint64_default_repeat(++i);
600  msg_in->add_fixed32_default_repeat(++i);
601  msg_in->add_fixed64_default_repeat(++i);
602  msg_in->add_sfixed32_default_repeat(++i);
603  msg_in->add_sfixed64_default_repeat(-++i);
604 
605  msg_in->add_bool_default_repeat(true);
606 
607  msg_in->add_string_default_repeat("abc123");
608 
609  if (j)
610  msg_in->add_bytes_default_repeat(goby::util::hex_decode("00aabbcc"));
611  else
612  msg_in->add_bytes_default_repeat(goby::util::hex_decode("ffeedd12"));
613 
614  msg_in->add_enum_default_repeat(static_cast<Enum1>((++i % 3) + 1));
615  EmbeddedMsg1* em_msg = msg_in->add_msg_default_repeat();
616  em_msg->set_val(++i + 0.3);
617  em_msg->mutable_msg()->set_val(++i);
618  }
619 }
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
Definition: flex_ostream.h:67
Definition: as.cpp:24
common::FlexOstream glog
Access the Goby logger through this object.
void add_stream(logger::Verbosity verbosity=logger::VERBOSE, std::ostream *os=0)
Attach a stream object (e.g. std::cout, std::ofstream, ...) to the logger with desired verbosity...
Definition: flex_ostream.h:96