[Rprotobuf-commits] r719 - in pkg: . inst/unitTests inst/unitTests/data
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jan 5 03:02:16 CET 2014
Author: murray
Date: 2014-01-05 03:02:15 +0100 (Sun, 05 Jan 2014)
New Revision: 719
Added:
pkg/inst/unitTests/data/encoding.proto
Modified:
pkg/ChangeLog
pkg/inst/unitTests/runit.serialize.R
Log:
Add example message types used in the encoding documentation and new
unit test verifying the byte-by-byte encoding used for some examples.
Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog 2014-01-05 00:06:16 UTC (rev 718)
+++ pkg/ChangeLog 2014-01-05 02:02:15 UTC (rev 719)
@@ -1,5 +1,10 @@
2014-01-04 Murray Stokely <mstokely at google.com>
+ * inst/unitTests/data/encoding.proto: Add example messages used in
+ the encoding documentation.
+ * inst/unitTests/runit.serialize.R (test.encoding): Add tests
+ verifying the exact byte serialization as described in the
+ encoding documentation.
* src/wrapper_ZeroCopyInputStream.cpp (rprotobuf): Add
BEGIN/END_RCPP macros to gracefully catch exceptions and return
them as R language errors.
Added: pkg/inst/unitTests/data/encoding.proto
===================================================================
--- pkg/inst/unitTests/data/encoding.proto (rev 0)
+++ pkg/inst/unitTests/data/encoding.proto 2014-01-05 02:02:15 UTC (rev 719)
@@ -0,0 +1,16 @@
+// Examples from:
+// https://developers.google.com/protocol-buffers/docs/encoding
+package protobuf_encoding_test;
+
+message Test1 {
+ required int32 a = 1;
+}
+message Test2 {
+ required string b = 2;
+}
+message Test3 {
+ required Test1 c = 3;
+}
+message Test4 {
+ repeated int32 d = 4 [packed=true];
+}
Modified: pkg/inst/unitTests/runit.serialize.R
===================================================================
--- pkg/inst/unitTests/runit.serialize.R 2014-01-05 00:06:16 UTC (rev 718)
+++ pkg/inst/unitTests/runit.serialize.R 2014-01-05 02:02:15 UTC (rev 719)
@@ -1,3 +1,4 @@
+# -*- indent-tabs-mode: nil; tab-width: 4; show-trailing-whitespace: t; c-indent-level: 4; c-basic-offset: 4; -*-
# Copyright 2012 Google Inc. All Rights Reserved.
# Author: Murray Stokely
#
@@ -15,7 +16,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
# this is executed before each test function
.setUp <- function(){
if( !exists("tutorial.Person", "RProtoBuf:DescriptorPool") ) {
@@ -25,6 +25,37 @@
}
}
+test.encoding <- function() {
+ if (!exists("protobuf_encoding_test.Test1",
+ "RProtoBuf:DescriptorPool")) {
+ unittest.proto.file <- system.file("unitTests", "data",
+ "encoding.proto",
+ package="RProtoBuf")
+ readProtoFiles(file=unittest.proto.file)
+ }
+
+ # Encoding examples from:
+ # https://developers.google.com/protocol-buffers/docs/encoding
+ test1 <- new(protobuf_encoding_test.Test1)
+ test1$a <- 150
+ checkIdentical(test1$serialize(NULL), as.raw(c(0x08,0x96,0x01)))
+
+ test2 <- new(protobuf_encoding_test.Test2)
+ test2$b <- "testing"
+ checkIdentical(test2$serialize(NULL),
+ as.raw(c(0x12, 0x07, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67)))
+
+ test3 <- new(protobuf_encoding_test.Test3)
+ test3$c$a <- 150
+ checkIdentical(test3$serialize(NULL),
+ as.raw(c(0x1a, 0x03, 0x08, 0x96, 0x01)))
+
+ test4 <- new(protobuf_encoding_test.Test4)
+ test4$d <- c(3, 270, 86942)
+ checkIdentical(test4$serialize(NULL),
+ as.raw(c(0x22, 0x06, 0x03, 0x8e, 0x02, 0x9e, 0xa7, 0x05)))
+}
+
test.serialize <- function() {
person <- new(tutorial.Person)
More information about the Rprotobuf-commits
mailing list