Commit 0d872f83 authored by Kenton Varda's avatar Kenton Varda

Add test of capnp encode/decode/eval.

parent d5965282
......@@ -300,4 +300,4 @@ nodist_capnp_test_SOURCES = $(test_capnpc_outputs)
capnp_evolution_test_LDADD = libcapnpc.la libcapnp.la libkj.la
capnp_evolution_test_SOURCES = src/capnp/compiler/evolution-test.c++
TESTS = capnp-test capnp-evolution-test
TESTS = capnp-test capnp-evolution-test src/capnp/compiler/capnp-test.sh
#! /bin/sh
# Copyright (c) 2013, Kenton Varda <temporal@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. 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.
#
# 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.
# This is a one-off test rule.
set -eu
echo findProvider file:capnp
read CAPNP
export CAPNP
echo findProvider file:capnp/compiler/capnp-test.sh
read CAPNP_TEST
# Register our interest in the testdata files.
echo findProvider file:capnp/testdata/binary; read JUNK
echo findProvider file:capnp/testdata/flat; read JUNK
echo findProvider file:capnp/testdata/packed; read JUNK
echo findProvider file:capnp/testdata/pretty.txt; read JUNK
echo findProvider file:capnp/testdata/short.txt; read JUNK
# Register our interest in the schema files.
echo findProvider file:capnp/c++.capnp
echo findProvider file:capnp/test.capnp
$CAPNP_TEST >&2
echo passed
#! /bin/sh
# Copyright (c) 2013, Kenton Varda <temporal@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. 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.
#
# 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.
# Tests the `capnp` tool's various commands, other than `compile`.
set -eu
fail() {
echo "FAILED: $@" >&2
exit 1
}
if test -e ./capnp; then
CAPNP=${CAPNP:-./capnp}
else
CAPNP=${CAPNP:-capnp}
fi
SCHEMA=$(dirname "$0")/../test.capnp
TESTDATA=$(dirname "$0")/../testdata
$CAPNP encode $SCHEMA TestAllTypes < $TESTDATA/short.txt | cmp $TESTDATA/binary || fail encode
$CAPNP encode --flat $SCHEMA TestAllTypes < $TESTDATA/short.txt | cmp $TESTDATA/flat || fail encode flat
$CAPNP encode --packed $SCHEMA TestAllTypes < $TESTDATA/short.txt | cmp $TESTDATA/packed || fail encode packed
$CAPNP encode $SCHEMA TestAllTypes < $TESTDATA/pretty.txt | cmp $TESTDATA/binary || fail parse pretty
$CAPNP decode $SCHEMA TestAllTypes < $TESTDATA/binary | cmp $TESTDATA/pretty.txt || fail decode
$CAPNP decode --flat $SCHEMA TestAllTypes < $TESTDATA/flat | cmp $TESTDATA/pretty.txt || fail decode flat
$CAPNP decode --packed $SCHEMA TestAllTypes < $TESTDATA/packed | cmp $TESTDATA/pretty.txt || fail decode packed
$CAPNP decode --short $SCHEMA TestAllTypes < $TESTDATA/binary | cmp $TESTDATA/short.txt || fail decode short
test_eval() {
test "x$($CAPNP eval $SCHEMA $1)" = "x$2" || fail eval "$1 == $2"
}
test_eval TestDefaults.uInt32Field 3456789012
test_eval TestDefaults.structField.textField '"baz"'
test_eval TestDefaults.int8List "[111, -111]"
test_eval 'TestDefaults.structList[1]' '( textField = "structlist 2" )'
test_eval globalStruct '(int32Field = 54321)'
test_eval TestConstants.enumConst corge
test_eval 'TestListDefaults.lists.int32ListList[2][0]' 12341234
......@@ -265,7 +265,7 @@ static ChangeInfo structGroupifyFields(
groupNested.adoptWithCaveats(i, kj::mv(groupified[i]));
}
newGroup.initName().setValue(kj::str("g", groupNested[0].getName().getValue()));
newGroup.initName().setValue(kj::str("g", nextOrdinal, "x", groupNested[0].getName().getValue()));
newGroup.getId().setUnspecified();
newGroup.setGroup();
......@@ -861,8 +861,7 @@ public:
{
kj::String text = kj::str(
"Randomly testing backwards-compatibility scenarios...\n"
"seed = ", seed, " <- PLEASE RECORD THIS NUMBER IF THE TEST FAILS\n");
"Randomly testing backwards-compatibility scenarios with seed: ", seed, "\n");
kj::FdOutputStream(STDOUT_FILENO).write(text.begin(), text.size());
}
......
( boolField = true,
int8Field = -123,
int16Field = -12345,
int32Field = -12345678,
int64Field = -123456789012345,
uInt8Field = 234,
uInt16Field = 45678,
uInt32Field = 3456789012,
uInt64Field = 12345678901234567890,
float32Field = 1234.5,
float64Field = -1.23e47,
textField = "foo",
dataField = "bar",
structField = (
boolField = true,
int8Field = -12,
int16Field = 3456,
int32Field = -78901234,
int64Field = 56789012345678,
uInt8Field = 90,
uInt16Field = 1234,
uInt32Field = 56789012,
uInt64Field = 345678901234567890,
float32Field = -1.25e-10,
float64Field = 345,
textField = "baz",
dataField = "qux",
structField = (
textField = "nested",
structField = (
textField = "really nested" ) ),
enumField = baz,
voidList = [void, void, void],
boolList = [false, true, false, true, true],
int8List = [12, -34, -128, 127],
int16List = [1234, -5678, -32768, 32767],
int32List = [12345678, -90123456, -2147483648, 2147483647],
int64List = [123456789012345, -678901234567890, -9223372036854775808, 9223372036854775807],
uInt8List = [12, 34, 0, 255],
uInt16List = [1234, 5678, 0, 65535],
uInt32List = [12345678, 90123456, 0, 4294967295],
uInt64List = [123456789012345, 678901234567890, 0, 18446744073709551615],
float32List = [0, 1234567, 1e37, -1e37, 1e-37, -1e-37],
float64List = [0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306],
textList = ["quux", "corge", "grault"],
dataList = ["garply", "waldo", "fred"],
structList = [
( textField = "x structlist 1" ),
( textField = "x structlist 2" ),
( textField = "x structlist 3" ) ],
enumList = [qux, bar, grault] ),
enumField = corge,
voidList = [void, void, void, void, void, void],
boolList = [true, false, false, true],
int8List = [111, -111],
int16List = [11111, -11111],
int32List = [111111111, -111111111],
int64List = [1111111111111111111, -1111111111111111111],
uInt8List = [111, 222],
uInt16List = [33333, 44444],
uInt32List = [3333333333],
uInt64List = [11111111111111111111],
float32List = [5555.5, inf, -inf, nan],
float64List = [7777.75, inf, -inf, nan],
textList = ["plugh", "xyzzy", "thud"],
dataList = ["oops", "exhausted", "rfc3092"],
structList = [
( textField = "structlist 1" ),
( textField = "structlist 2" ),
( textField = "structlist 3" ) ],
enumList = [foo, garply] )
(boolField = true, int8Field = -123, int16Field = -12345, int32Field = -12345678, int64Field = -123456789012345, uInt8Field = 234, uInt16Field = 45678, uInt32Field = 3456789012, uInt64Field = 12345678901234567890, float32Field = 1234.5, float64Field = -1.23e47, textField = "foo", dataField = "bar", structField = (boolField = true, int8Field = -12, int16Field = 3456, int32Field = -78901234, int64Field = 56789012345678, uInt8Field = 90, uInt16Field = 1234, uInt32Field = 56789012, uInt64Field = 345678901234567890, float32Field = -1.25e-10, float64Field = 345, textField = "baz", dataField = "qux", structField = (textField = "nested", structField = (textField = "really nested")), enumField = baz, voidList = [void, void, void], boolList = [false, true, false, true, true], int8List = [12, -34, -128, 127], int16List = [1234, -5678, -32768, 32767], int32List = [12345678, -90123456, -2147483648, 2147483647], int64List = [123456789012345, -678901234567890, -9223372036854775808, 9223372036854775807], uInt8List = [12, 34, 0, 255], uInt16List = [1234, 5678, 0, 65535], uInt32List = [12345678, 90123456, 0, 4294967295], uInt64List = [123456789012345, 678901234567890, 0, 18446744073709551615], float32List = [0, 1234567, 1e37, -1e37, 1e-37, -1e-37], float64List = [0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306], textList = ["quux", "corge", "grault"], dataList = ["garply", "waldo", "fred"], structList = [(textField = "x structlist 1"), (textField = "x structlist 2"), (textField = "x structlist 3")], enumList = [qux, bar, grault]), enumField = corge, voidList = [void, void, void, void, void, void], boolList = [true, false, false, true], int8List = [111, -111], int16List = [11111, -11111], int32List = [111111111, -111111111], int64List = [1111111111111111111, -1111111111111111111], uInt8List = [111, 222], uInt16List = [33333, 44444], uInt32List = [3333333333], uInt64List = [11111111111111111111], float32List = [5555.5, inf, -inf, nan], float64List = [7777.75, inf, -inf, nan], textList = ["plugh", "xyzzy", "thud"], dataList = ["oops", "exhausted", "rfc3092"], structList = [(textField = "structlist 1"), (textField = "structlist 2"), (textField = "structlist 3")], enumList = [foo, garply])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment