[Rprotobuf-commits] r606 - in pkg: . inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Dec 27 09:52:32 CET 2013


Author: murray
Date: 2013-12-27 09:52:31 +0100 (Fri, 27 Dec 2013)
New Revision: 606

Added:
   pkg/inst/unitTests/runit.messages.R
Modified:
   pkg/ChangeLog
Log:
Add unit tests for our handling of setting repeated message fields.



Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2013-12-27 08:36:02 UTC (rev 605)
+++ pkg/ChangeLog	2013-12-27 08:52:31 UTC (rev 606)
@@ -5,6 +5,8 @@
 	  try/catch block so we catch any exceptions generated by Rcpp::as
 	  or other functions and forward it along to an R-language stop()
 	  error instead of terminating our R instance.
+	* inst/unitTests/runit.messages.R (test.message): Add unit tests
+	  for our handling of setting repeated message fields.
 
 2013-12-26  Murray Stokely  <mstokely at google.com>
 

Added: pkg/inst/unitTests/runit.messages.R
===================================================================
--- pkg/inst/unitTests/runit.messages.R	                        (rev 0)
+++ pkg/inst/unitTests/runit.messages.R	2013-12-27 08:52:31 UTC (rev 606)
@@ -0,0 +1,47 @@
+# Copyright 2013 Google Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+test.message <- function() {
+  if (!exists("protobuf_unittest.TestAllTypes",
+              "RProtoBuf:DescriptorPool")) {
+    unittest.proto.file <- system.file("unitTests", "data",
+                                       "unittest.proto",
+                                       package="RProtoBuf")
+    readProtoFiles(file=unittest.proto.file)
+  }
+  a <- new(protobuf_unittest.TestAllTypes)
+  a$repeated_nested_message <- list(
+      new(protobuf_unittest.TestAllTypes.NestedMessage, bb=3),
+      new(protobuf_unittest.TestAllTypes.NestedMessage, bb=4))
+  checkEquals(a$repeated_nested_message[[1]]$bb, 3)
+  checkEquals(a$repeated_nested_message[[2]]$bb, 4)
+
+  checkException(a$repeated_nested_message <- list(
+      new(protobuf_unittest.ForeignMessage, c=1),
+      new(protobuf_unittest.TestAllTypes.NestedMessage, bb=4)))
+
+  checkException(a$repeated_nested_message <- list(
+      new(protobuf_unittest.TestAllTypes.NestedMessage, bb=4),
+      new(protobuf_unittest.ForeignMessage, c=1)))
+
+  checkException(a$repeated_nested_message <- list(
+      new(protobuf_unittest.TestAllTypes.NestedMessage, bb=4),
+      3))                                   
+
+  checkException(a$repeated_nested_message <- list(
+      new(protobuf_unittest.TestAllTypes.NestedMessage, bb=4),
+      "foo"))
+}



More information about the Rprotobuf-commits mailing list