Commit 8b936efe authored by Kenton Varda's avatar Kenton Varda

Fix bug where only the first import made it into the import table. Can't…

Fix bug where only the first import made it into the import table.  Can't believe this wasn't tested.  Sigh.
parent 57e36257
...@@ -247,13 +247,16 @@ uninstall-hook: ...@@ -247,13 +247,16 @@ uninstall-hook:
test_capnpc_inputs = \ test_capnpc_inputs = \
src/capnp/test.capnp \ src/capnp/test.capnp \
src/capnp/test-import.capnp src/capnp/test-import.capnp \
src/capnp/test-import2.capnp
test_capnpc_outputs = \ test_capnpc_outputs = \
src/capnp/test.capnp.c++ \ src/capnp/test.capnp.c++ \
src/capnp/test.capnp.h \ src/capnp/test.capnp.h \
src/capnp/test-import.capnp.c++ \ src/capnp/test-import.capnp.c++ \
src/capnp/test-import.capnp.h src/capnp/test-import.capnp.h \
src/capnp/test-import2.capnp.c++ \
src/capnp/test-import2.capnp.h
if USE_EXTERNAL_CAPNP if USE_EXTERNAL_CAPNP
......
...@@ -889,7 +889,7 @@ Orphan<List<schema::CodeGeneratorRequest::RequestedFile::Import>> ...@@ -889,7 +889,7 @@ Orphan<List<schema::CodeGeneratorRequest::RequestedFile::Import>>
uint i = 0; uint i = 0;
for (auto name: importNames) { for (auto name: importNames) {
// We presumably ran this import before, so it shouldn't throw now. // We presumably ran this import before, so it shouldn't throw now.
auto entry = builder[i]; auto entry = builder[i++];
entry.setId(KJ_ASSERT_NONNULL(importRelative(name)).rootNode.getId()); entry.setId(KJ_ASSERT_NONNULL(importRelative(name)).rootNode.getId());
entry.setName(name); entry.setName(name);
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <capnp/test-import.capnp.h> #include <capnp/test-import.capnp.h>
#include <capnp/test-import2.capnp.h>
#include "message.h" #include "message.h"
#include <kj/thread.h> #include <kj/thread.h>
#include <kj/debug.h> #include <kj/debug.h>
...@@ -1450,10 +1451,22 @@ TEST(Encoding, NestedTypes) { ...@@ -1450,10 +1451,22 @@ TEST(Encoding, NestedTypes) {
TEST(Encoding, Imports) { TEST(Encoding, Imports) {
// Also just testing the generated code. // Also just testing the generated code.
{
MallocMessageBuilder builder; MallocMessageBuilder builder;
TestImport::Builder root = builder.getRoot<TestImport>(); TestImport::Builder root = builder.getRoot<TestImport>();
initTestMessage(root.initField()); initTestMessage(root.initField());
checkTestMessage(root.asReader().getField()); checkTestMessage(root.asReader().getField());
}
{
MallocMessageBuilder builder;
TestImport2::Builder root = builder.getRoot<TestImport2>();
initTestMessage(root.initFoo());
checkTestMessage(root.asReader().getFoo());
root.setBar(Schema::from<TestAllTypes>().getProto());
initTestMessage(root.initBaz().initField());
checkTestMessage(root.asReader().getBaz().getField());
}
} }
TEST(Encoding, Using) { TEST(Encoding, Using) {
......
# 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.
@0xc64a3bf0338a124a;
using Import1 = import "schema.capnp";
using Import2 = import "test-import.capnp";
using Import3 = import "test.capnp";
struct TestImport2 {
foo @0 :Import3.TestAllTypes;
bar @1 :Import1.Node;
baz @2 :Import2.TestImport;
}
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