From fcfc99f766f278564c062922a2857c21ac9af041 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Tue, 13 Sep 2011 16:14:08 +0000 Subject: Fixed a bunch of bugs related to callback fields. Most importantly, callback fields in submessages were being overwritten with garbage, causing segfaults. Additionally, converted PB_LTYPE_FIXED to PB_LTYPE_FIXED32 and PB_LTYPE_FIXED64. This makes the interface a bit easier to use, and in addition runs faster. git-svn-id: https://svn.kapsi.fi/jpa/nanopb@975 e3a754e5-d11d-0410-8d38-ebb782a927b9 --- tests/encode_unittests.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'tests/encode_unittests.c') diff --git a/tests/encode_unittests.c b/tests/encode_unittests.c index 926a254..166e6e8 100644 --- a/tests/encode_unittests.c +++ b/tests/encode_unittests.c @@ -99,15 +99,13 @@ int main() COMMENT("Test pb_encode_tag_for_field") TEST(WRITES(pb_encode_tag_for_field(&s, &field), "\x50")); - field.type = PB_LTYPE_FIXED; - field.data_size = 8; + field.type = PB_LTYPE_FIXED64; TEST(WRITES(pb_encode_tag_for_field(&s, &field), "\x51")); field.type = PB_LTYPE_STRING; TEST(WRITES(pb_encode_tag_for_field(&s, &field), "\x52")); - field.type = PB_LTYPE_FIXED; - field.data_size = 4; + field.type = PB_LTYPE_FIXED32; TEST(WRITES(pb_encode_tag_for_field(&s, &field), "\x55")); } @@ -149,26 +147,24 @@ int main() { uint8_t buffer[30]; pb_ostream_t s; - pb_field_t field = {1, PB_LTYPE_FIXED, 0, 0, sizeof(float)}; float fvalue; double dvalue; - COMMENT("Test pb_enc_fixed using float") + COMMENT("Test pb_enc_fixed32 using float") fvalue = 0.0f; - TEST(WRITES(pb_enc_fixed(&s, &field, &fvalue), "\x00\x00\x00\x00")) + TEST(WRITES(pb_enc_fixed32(&s, NULL, &fvalue), "\x00\x00\x00\x00")) fvalue = 99.0f; - TEST(WRITES(pb_enc_fixed(&s, &field, &fvalue), "\x00\x00\xc6\x42")) + TEST(WRITES(pb_enc_fixed32(&s, NULL, &fvalue), "\x00\x00\xc6\x42")) fvalue = -12345678.0f; - TEST(WRITES(pb_enc_fixed(&s, &field, &fvalue), "\x4e\x61\x3c\xcb")) + TEST(WRITES(pb_enc_fixed32(&s, NULL, &fvalue), "\x4e\x61\x3c\xcb")) - COMMENT("Test pb_enc_fixed using double") - field.data_size = sizeof(double); + COMMENT("Test pb_enc_fixed64 using double") dvalue = 0.0; - TEST(WRITES(pb_enc_fixed(&s, &field, &dvalue), "\x00\x00\x00\x00\x00\x00\x00\x00")) + TEST(WRITES(pb_enc_fixed64(&s, NULL, &dvalue), "\x00\x00\x00\x00\x00\x00\x00\x00")) dvalue = 99.0; - TEST(WRITES(pb_enc_fixed(&s, &field, &dvalue), "\x00\x00\x00\x00\x00\xc0\x58\x40")) + TEST(WRITES(pb_enc_fixed64(&s, NULL, &dvalue), "\x00\x00\x00\x00\x00\xc0\x58\x40")) dvalue = -12345678.0; - TEST(WRITES(pb_enc_fixed(&s, &field, &dvalue), "\x00\x00\x00\xc0\x29\x8c\x67\xc1")) + TEST(WRITES(pb_enc_fixed64(&s, NULL, &dvalue), "\x00\x00\x00\xc0\x29\x8c\x67\xc1")) } { -- cgit 1.2.3-korg