Permalink
Browse files

unittest.proto: Add cpp_trigraph field from Google protobuf 2.4.1.

wire-format-test.lisp: Rename to wire-format_test.lisp.
protobuf.asd: Reflow comments.
  • Loading branch information...
1 parent d6d4c9a commit 5b324887233bc785a94feb16ac1aadaf74343a1e @brown committed Jan 27, 2012
Showing with 123 additions and 23 deletions.
  1. +7 −0 google/protobuf/unittest.proto
  2. +1 −1 protobuf-test.asd
  3. +21 −22 protobuf.asd
  4. +94 −0 wire-format_test.lisp
@@ -495,6 +495,13 @@ message TestExtremeDefaultValues {
// optional float inf_float = 17 [default = inf];
// optional float neg_inf_float = 18 [default = -inf];
// optional float nan_float = 19 [default = nan];
+
+ // Tests for C++ trigraphs.
+ // Trigraphs should be escaped in C++ generated files, but they should not be
+ // escaped for other languages.
+ // Note that in .proto file, "\?" is a valid way to escape ? in string
+ // literals.
+ optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"];
}
message SparseEnumMessage {
View
@@ -48,7 +48,7 @@
:components
((:static-file "golden")
(:file "message-test" :depends-on ("unittest"))
- (:file "wire-format-test")
+ (:file "wire-format_test")
;; Old protocol buffer tests.
;; TODO(brown): Delete when the new proto2 tests cover all the functionality.
(:file "proto-lisp-test" :depends-on ("testproto1" "testproto2"))
View
@@ -70,9 +70,10 @@
:initform ()
:initarg :proto-search-path
:reader search-path
- :documentation "List containing directories where the protocol buffer compiler should search
-for imported protobuf files. Non-absolute pathnames are treated as relative to the directory
-containing the DEFSYSTEM form in which they appear."))
+ :documentation
+"List containing directories where the protocol buffer compiler should search
+for imported protobuf files. Non-absolute pathnames are treated as relative to
+the directory containing the DEFSYSTEM form in which they appear."))
(:documentation "A protocol buffer definition file."))
(export '(protobuf-source-file proto-pathname search-path))
@@ -91,25 +92,26 @@ containing the DEFSYSTEM form in which they appear."))
(defclass proto-to-lisp (operation)
()
- (:documentation "An ASDF operation that compiles a .proto file containing protocol buffer
+ (:documentation
+"An ASDF operation that compiles a .proto file containing protocol buffer
definitions into a Lisp source file."))
(defmethod component-depends-on ((operation compile-op) (component protobuf-source-file))
- "Compiling a protocol buffer file depends on generating Lisp source code for the protobuf, but
-also on loading package definitions and in-line function definitions that the machine-generated
-protobuf Lisp code uses."
+ "Compiling a protocol buffer file depends on generating Lisp source code for
+the protobuf, but also on loading package definitions and in-line function
+definitions that the machine-generated protobuf Lisp code uses."
`((proto-to-lisp ,(component-name component))
,@(call-next-method)))
(defmethod component-depends-on ((operation load-op) (component protobuf-source-file))
- "Loading a protocol buffer file depends on generating Lisp source code for the protobuf, but also
-on loading package definitions and in-line function definitions that the machine-generated protobuf
-Lisp code uses."
+ "Loading a protocol buffer file depends on generating Lisp source code for the
+protobuf, but also on loading package definitions and in-line function
+definitions that the machine-generated protobuf Lisp code uses."
`((proto-to-lisp ,(component-name component))
,@(call-next-method)))
(defun proto-input (protobuf-source-file)
- "Return the pathname of the protocol buffer definition file that must be
+ "Returns the pathname of the protocol buffer definition file that must be
translated into Lisp source code for this PROTO-FILE component."
(if (proto-pathname protobuf-source-file)
;; Path of the protobuf file was specified with :PROTO-PATHNAME.
@@ -126,13 +128,14 @@ translated into Lisp source code for this PROTO-FILE component."
(list *protoc* *protoc-gen-lisp* (proto-input component)))
(defmethod output-files ((operation proto-to-lisp) (component protobuf-source-file))
- "Arrange for the Lisp output file of PROTO-TO-LISP operations to be stored where fasl files are
-located."
+ "Arranges for the Lisp output file of PROTO-TO-LISP operations to be stored
+where fasl files are located."
(values (list (component-pathname component))
nil)) ; allow around methods to translate
(defun resolve-relative-pathname (path parent-path)
- "When PATH doesn't have an absolute directory component, treat it as relative to PARENT-PATH."
+ "When PATH doesn't have an absolute directory component, treat it as relative
+to PARENT-PATH."
(let* ((pathname (pathname path))
(directory (pathname-directory pathname)))
(if (and (list directory) (eq (car directory) :absolute))
@@ -175,9 +178,9 @@ located."
(error 'compile-failed :component component :operation operation))))
(defmethod asdf::component-self-dependencies :around ((op load-op) (c protobuf-source-file))
- "Remove PROTO-TO-LISP operations from self dependencies. Otherwise, the Lisp output files of
-PROTO-TO-LISP are considered to be input files for LOAD-OP, which means ASDF loads both the .lisp
-file and the .fasl file."
+ "Removes PROTO-TO-LISP operations from self dependencies. Otherwise, the Lisp
+output files of PROTO-TO-LISP are considered to be input files for LOAD-OP,
+which means ASDF loads both the .lisp file and the .fasl file."
(remove-if (lambda (x)
(eq (car x) 'proto-to-lisp))
(call-next-method)))
@@ -214,13 +217,9 @@ file and the .fasl file."
:name "Protocol Buffer"
:description "Protocol buffer code"
:long-description "A Common Lisp implementation of Google's protocol buffer support libraries."
- :version "0.7.3"
+ :version "0.7.4"
:author "Robert Brown"
:license "See file COPYING and the copyright messages in individual files."
- ;; After loading the system, announce its availability.
- :perform (load-op :after (operation component)
- (pushnew :protobuf cl:*features*)
- (provide 'protobuf))
:depends-on (com.google.base
varint
#-(or allegro clisp sbcl) trivial-utf-8)
View
@@ -0,0 +1,94 @@
+;;;; Copyright 2010 Google Inc. All Rights Reserved
+
+;;;; Redistribution and use in source and binary forms, with or without
+;;;; modification, are permitted provided that the following conditions are
+;;;; met:
+
+;;;; * Redistributions of source code must retain the above copyright
+;;;; notice, this list of conditions and the following disclaimer.
+;;;; * Redistributions in binary form must reproduce the above
+;;;; copyright notice, this list of conditions and the following disclaimer
+;;;; in the documentation and/or other materials provided with the
+;;;; distribution.
+;;;; * Neither the name of Google Inc. nor the names of its
+;;;; contributors may be used to endorse or promote products derived from
+;;;; this software without specific prior written permission.
+
+;;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+;;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+;;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+;;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+;;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+;;;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+;;;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+;;;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+;;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+;;;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+;;;; Author: brown@google.com (Robert Brown)
+
+;;;; Test the protocol buffer wire format.
+
+(in-package #:common-lisp-user)
+
+(defpackage #:wire-format-test
+ (:documentation "Tests for protocol buffer wire format functions.")
+ (:use #:common-lisp
+ #:com.google.base
+ #:hu.dwim.stefil
+ #:wire-format)
+ (:export #:test-wire-format))
+
+(in-package #:wire-format-test)
+(declaim #.*optimize-default*)
+
+(defsuite (test-wire-format :in root-suite) ()
+ (run-child-tests))
+
+(in-suite test-wire-format)
+
+(deftest zig-zag-encode-decode ()
+ (flet ((verify (fun arg-results)
+ (loop for (arg result) in arg-results do
+ (is (= (funcall fun arg) result)))))
+ (verify #'zig-zag-encode32
+ `((0 0) (-1 1) (1 2) (-2 3)
+ (#x3fffffff #x7ffffffe)
+ (,(- #xc0000000 (ash 1 32)) #x7fffffff)
+ (#x7fffffff #xfffffffe)
+ (,(- #x80000000 (ash 1 32)) #xffffffff)))
+ (verify #'zig-zag-decode32
+ `((0 0) (1 -1) (2 1) (3 -2)
+ (#x7ffffffe #x3fffffff)
+ (#x7fffffff ,(- #xc0000000 (ash 1 32)))
+ (#xfffffffe #x7fffffff)
+ (#xffffffff ,(- #x80000000 (ash 1 32)))))
+ (verify #'zig-zag-encode64
+ `((0 0) (-1 1) (1 2) (-2 3)
+ (#x000000003fffffff #x000000007ffffffe)
+ (,(- #xffffffffc0000000 (ash 1 64)) #x000000007fffffff)
+ (#x000000007fffffff #x00000000fffffffe)
+ (,(- #xffffffff80000000 (ash 1 64)) #x00000000ffffffff)
+ (#x7fffffffffffffff #xfffffffffffffffe)
+ (,(- #x8000000000000000 (ash 1 64)) #xffffffffffffffff)))
+ (verify #'zig-zag-decode64
+ `((0 0) (1 -1) (2 1) (3 -2)
+ (#x000000007ffffffe #x000000003fffffff)
+ (#x000000007fffffff ,(- #xffffffffc0000000 (ash 1 64)))
+ (#x00000000fffffffe #x000000007fffffff)
+ (#x00000000ffffffff ,(- #xffffffff80000000 (ash 1 64)))
+ (#xfffffffffffffffe #x7fffffffffffffff)
+ (#xffffffffffffffff ,(- #x8000000000000000 (ash 1 64))))))
+
+ ;; Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1) were chosen
+ ;; semi-randomly via keyboard bashing.
+ (flet ((round-trip32 (n)
+ (is (= n (zig-zag-decode32 (zig-zag-encode32 n)))))
+ (round-trip64 (n)
+ (is (= n (zig-zag-decode64 (zig-zag-encode64 n))))))
+ (dolist (n '(0 1 -1 14927 -3612))
+ (round-trip32 n))
+ (dolist (n '(0 1 -1 14927 -3612 856912304801416 -75123905439571256))
+ (round-trip64 n)))
+ (values))

0 comments on commit 5b32488

Please sign in to comment.