diff options
author | Andrew Bartlett <abartlet@samba.org> | 2011-06-24 16:26:23 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2011-06-24 16:26:23 +1000 |
commit | 6da26870e0ae5acd6ff49a30ec2f6886b44d095e (patch) | |
tree | 850c71039563c16a5d563c47e7ba2ab645baf198 /lib/util/tests/asn1_tests.c | |
parent | 6925a799d04c6fa59dd2ddef1f5510f9bb7d17d1 (diff) | |
parent | 2610c05b5b95cc7036b3d6dfb894c6cfbdb68483 (diff) | |
download | samba-6da26870e0ae5acd6ff49a30ec2f6886b44d095e.tar.gz samba-6da26870e0ae5acd6ff49a30ec2f6886b44d095e.tar.bz2 samba-6da26870e0ae5acd6ff49a30ec2f6886b44d095e.zip |
Merge 2610c05b5b95cc7036b3d6dfb894c6cfbdb68483 as Samba-4.0alpha16
Diffstat (limited to 'lib/util/tests/asn1_tests.c')
-rw-r--r-- | lib/util/tests/asn1_tests.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/lib/util/tests/asn1_tests.c b/lib/util/tests/asn1_tests.c index ac8ca538f8..3ee64c3f7a 100644 --- a/lib/util/tests/asn1_tests.c +++ b/lib/util/tests/asn1_tests.c @@ -4,6 +4,8 @@ util_asn1 testing Copyright (C) Kamen Mazdrashki <kamen.mazdrashki@postpath.com> 2009 + Copyright (C) Volker Lendecke 2004 + Copyright (C) Andrew Bartlett 2011 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -103,6 +105,55 @@ static const struct oid_data partial_oid_data_ok[] = { }, }; +static const struct { + DATA_BLOB blob; + int value; +} integer_tests[] = { + { + .blob = {"\x02\x01\x00", 3}, + .value = 0 + }, + { + .blob = {"\x02\x01\x7f", 3}, + .value = 127 + }, + { + .blob = {"\x02\x02\x00\x80", 4}, + .value = 128 + }, + { + .blob = {"\x02\x02\x01\x00", 4}, + .value = 256 + }, + { + .blob = {"\x02\x01\x80", 3}, + .value = -128 + }, + { + .blob = {"\x02\x02\xff\x7f", 4}, + .value = -129 + }, + { + .blob = {"\x02\x01\xff", 3}, + .value = -1 + }, + { + .blob = {"\x02\x02\xff\x01", 4}, + .value = -255 + }, + { + .blob = {"\x02\x02\x00\xff", 4}, + .value = 255 + }, + { + .blob = {"\x02\x04\x80\x00\x00\x00", 6}, + .value = 0x80000000 + }, + { + .blob = {"\x02\x04\x7f\xff\xff\xff", 6}, + .value = 0x7fffffff + } +}; /* Testing ber_write_OID_String() function */ static bool test_ber_write_OID_String(struct torture_context *tctx) @@ -260,6 +311,46 @@ static bool test_ber_read_partial_OID_String(struct torture_context *tctx) return true; } +/* + * Testing asn1_read_Integer and asn1_write_Integer functions, + * inspired by Love Hornquist Astrand + */ + +static bool test_asn1_Integer(struct torture_context *tctx) +{ + int i; + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_new(tctx); + + for (i = 0; i < ARRAY_SIZE(integer_tests); i++) { + ASN1_DATA *data; + DATA_BLOB blob; + int val; + + data = asn1_init(mem_ctx); + if (!data) { + return -1; + } + + asn1_write_Integer(data, integer_tests[i].value); + + blob.data = data->data; + blob.length = data->length; + torture_assert_data_blob_equal(tctx, blob, integer_tests[i].blob, "asn1_write_Integer gave incorrect result"); + + asn1_load(data, blob); + torture_assert(tctx, asn1_read_Integer(data, &val), "asn1_write_Integer output could not be read by asn1_read_Integer()"); + + torture_assert_int_equal(tctx, val, integer_tests[i].value, + "readback of asn1_write_Integer output by asn1_read_Integer() failed"); + } + + talloc_free(mem_ctx); + + return true; +} + /* LOCAL-ASN1 test suite creation */ struct torture_suite *torture_local_util_asn1(TALLOC_CTX *mem_ctx) @@ -278,5 +369,8 @@ struct torture_suite *torture_local_util_asn1(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "ber_read_partial_OID_String", test_ber_read_partial_OID_String); + torture_suite_add_simple_test(suite, "asn1_Integer", + test_asn1_Integer); + return suite; } |