-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
4 changed files
with
123 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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)) |