diff options
author | Joshua Haberman <joshua@reverberate.org> | 2010-07-17 13:49:50 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2010-07-17 13:49:50 -0700 |
commit | 79de3ca9e48877dfc506c9a486e1e5599c2312f9 (patch) | |
tree | 775dd49dbbc6b48ebe2f3974991ab45f68910222 | |
parent | 60ae9be4380937c3cd39fb72df04fd1723e741e6 (diff) |
Add forgotten test_decoder.c.
-rw-r--r-- | tests/test_decoder.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test_decoder.c b/tests/test_decoder.c new file mode 100644 index 0000000..0e6f19c --- /dev/null +++ b/tests/test_decoder.c @@ -0,0 +1,32 @@ + +#include "upb_decoder.h" +#include "upb_textprinter.h" +#include "upb_stdio.h" + +int main() { + upb_symtab *symtab = upb_symtab_new(); + upb_symtab_add_descriptorproto(symtab); + upb_def *fds = upb_symtab_lookup( + symtab, UPB_STRLIT("google.protobuf.FileDescriptorSet")); + + upb_stdio *in = upb_stdio_new(); + upb_stdio_reset(in, stdin); + upb_stdio *out = upb_stdio_new(); + upb_stdio_reset(out, stdout); + upb_decoder *d = upb_decoder_new(upb_downcast_msgdef(fds)); + upb_decoder_reset(d, upb_stdio_bytesrc(in)); + upb_textprinter *p = upb_textprinter_new(); + upb_textprinter_reset(p, upb_stdio_bytesink(out), false); + + upb_status status = UPB_STATUS_INIT; + upb_streamdata(upb_decoder_src(d), upb_textprinter_sink(p), &status); + + assert(upb_ok(&status)); + + upb_stdio_free(in); + upb_stdio_free(out); + upb_decoder_free(d); + upb_textprinter_free(p); + upb_def_unref(fds); + upb_symtab_unref(symtab); +} |