]> granicus.if.org Git - libevent/commitdiff
More documentation and unit tests for event_tagging.
authorNick Mathewson <nickm@torproject.org>
Thu, 29 Oct 2009 16:35:20 +0000 (16:35 +0000)
committerNick Mathewson <nickm@torproject.org>
Thu, 29 Oct 2009 16:35:20 +0000 (16:35 +0000)
svn:r1476

event_tagging.c
test/regress.c

index c5654d30c8024f9351f6c104ba4896cb0821f7bb..f1d7a992770e3610c0e848b3aac60ebb4e547bda 100644 (file)
 #include "mm-internal.h"
 #include "util-internal.h"
 
+/*
+  Here's our wire format:
+
+  Stream = TaggedData*
+
+  TaggedData = Tag Length Data
+       where the integer value of 'Length' is the length of 'data'.
+
+  Tag = HByte* LByte
+       where HByte is a byte with the high bit set, and LByte is a byte
+       with the high bit clear. The integer value of the tag is taken
+       by concatenating the lower 7 bits from all the tags.  So for example,
+       the tag 0x66 is encoded as [66], whereas the tag 0x166 is encoded as
+       [82 66]
+
+  Length = Integer
+
+  Integer = NNibbles Nibble* Padding?
+       where NNibbles is a 4-bit value encoding the number of nibbles-1,
+       and each Nibble is 4 bits worth of encoded integer, in big-endian
+       order.  If the total encoded integer size is an odd number of nibbles,
+       a final padding nibble with value 0 is appended.
+*/
+
 int evtag_decode_int(ev_uint32_t *pnumber, struct evbuffer *evbuf);
 int evtag_decode_int64(ev_uint64_t *pnumber, struct evbuffer *evbuf);
 int evtag_encode_tag(struct evbuffer *evbuf, ev_uint32_t tag);
index e19295808b2db19b7da7c4ed04883517be8fadd7..b34bb7444b1d7572f35e8374652d026b23844352 100644 (file)
@@ -1464,6 +1464,33 @@ end:
        evbuffer_free(tmp);
 }
 
+static void
+evtag_test_peek(void *ptr)
+{
+       struct evbuffer *tmp = evbuffer_new();
+       ev_uint32_t u32;
+
+       evtag_marshal_int(tmp, 30, 0);
+       evtag_marshal_string(tmp, 40, "Hello world");
+
+       tt_int_op(evtag_peek(tmp, &u32), ==, 1);
+       tt_int_op(u32, ==, 30);
+       tt_int_op(evtag_peek_length(tmp, &u32), ==, 0);
+       tt_int_op(u32, ==, 1+1+1);
+       tt_int_op(evtag_consume(tmp), ==, 0);
+
+       tt_int_op(evtag_peek(tmp, &u32), ==, 1);
+       tt_int_op(u32, ==, 40);
+       tt_int_op(evtag_peek_length(tmp, &u32), ==, 0);
+       tt_int_op(u32, ==, 1+1+11);
+       tt_int_op(evtag_payload_length(tmp, &u32), ==, 0);
+       tt_int_op(u32, ==, 11);
+
+end:
+       evbuffer_free(tmp);
+}
+
+
 
 static void
 test_methods(void *ptr)
@@ -1832,6 +1859,7 @@ struct testcase_t evtag_testcases[] = {
        { "int", evtag_int_test, TT_FORK, NULL, NULL },
        { "fuzz", evtag_fuzz, TT_FORK, NULL, NULL },
        { "encoding", evtag_tag_encoding, TT_FORK, NULL, NULL },
+       { "peek", evtag_test_peek, 0, NULL, NULL },
 
        END_OF_TESTCASES
 };