aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/msgpack.rb
diff options
context:
space:
mode:
authorJack Nagel2012-04-11 00:26:32 -0500
committerJack Nagel2012-04-11 00:27:47 -0500
commit4ad165ce78ccab22d4424d844010c1b204e48090 (patch)
treed16986c6a410a11ff25f12339f3b3cb88e3383f4 /Library/Formula/msgpack.rb
parent19273231125d2e50d4fbe9f67d92f493ae461643 (diff)
downloadhomebrew-4ad165ce78ccab22d4424d844010c1b204e48090.tar.bz2
msgpack: add test
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library/Formula/msgpack.rb')
-rw-r--r--Library/Formula/msgpack.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/Library/Formula/msgpack.rb b/Library/Formula/msgpack.rb
index 6715aa773..681fb22ec 100644
--- a/Library/Formula/msgpack.rb
+++ b/Library/Formula/msgpack.rb
@@ -13,4 +13,44 @@ class Msgpack < Formula
system "./configure", "--disable-dependency-tracking", "--prefix=#{prefix}"
system "make install"
end
+
+ def test
+ # Reference: http://wiki.msgpack.org/display/MSGPACK/QuickStart+for+C+Language
+ mktemp do
+ (Pathname.pwd/'test.c').write <<-EOS.undent
+ #include <msgpack.h>
+ #include <stdio.h>
+
+ int main(void)
+ {
+ msgpack_sbuffer* buffer = msgpack_sbuffer_new();
+ msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write);
+ msgpack_pack_int(pk, 1);
+ msgpack_pack_int(pk, 2);
+ msgpack_pack_int(pk, 3);
+
+ /* deserializes these objects using msgpack_unpacker. */
+ msgpack_unpacker pac;
+ msgpack_unpacker_init(&pac, MSGPACK_UNPACKER_INIT_BUFFER_SIZE);
+
+ /* feeds the buffer. */
+ msgpack_unpacker_reserve_buffer(&pac, buffer->size);
+ memcpy(msgpack_unpacker_buffer(&pac), buffer->data, buffer->size);
+ msgpack_unpacker_buffer_consumed(&pac, buffer->size);
+
+ /* now starts streaming deserialization. */
+ msgpack_unpacked result;
+ msgpack_unpacked_init(&result);
+
+ while(msgpack_unpacker_next(&pac, &result)) {
+ msgpack_object_print(stdout, result.data);
+ puts("");
+ }
+ }
+ EOS
+
+ system ENV.cc, "-o", "test", "test.c", "-lmsgpack"
+ `./test` == "1\n2\n3\n"
+ end
+ end
end