summaryrefslogtreecommitdiff
path: root/lib/util/tests
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util/tests')
-rw-r--r--lib/util/tests/asn1_tests.c94
-rw-r--r--lib/util/tests/str.c10
-rw-r--r--lib/util/tests/time.c18
3 files changed, 99 insertions, 23 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;
}
diff --git a/lib/util/tests/str.c b/lib/util/tests/str.c
index 6b38feaf43..f9f3abf731 100644
--- a/lib/util/tests/str.c
+++ b/lib/util/tests/str.c
@@ -25,7 +25,7 @@
static bool test_string_sub_simple(struct torture_context *tctx)
{
char tmp[100];
- safe_strcpy(tmp, "foobar", sizeof(tmp));
+ strlcpy(tmp, "foobar", sizeof(tmp));
string_sub(tmp, "foo", "bar", sizeof(tmp));
torture_assert_str_equal(tctx, tmp, "barbar", "invalid sub");
return true;
@@ -34,7 +34,7 @@ static bool test_string_sub_simple(struct torture_context *tctx)
static bool test_string_sub_multiple(struct torture_context *tctx)
{
char tmp[100];
- safe_strcpy(tmp, "fooblafoo", sizeof(tmp));
+ strlcpy(tmp, "fooblafoo", sizeof(tmp));
string_sub(tmp, "foo", "bar", sizeof(tmp));
torture_assert_str_equal(tctx, tmp, "barblabar", "invalid sub");
return true;
@@ -43,7 +43,7 @@ static bool test_string_sub_multiple(struct torture_context *tctx)
static bool test_string_sub_longer(struct torture_context *tctx)
{
char tmp[100];
- safe_strcpy(tmp, "foobla", sizeof(tmp));
+ strlcpy(tmp, "foobla", sizeof(tmp));
string_sub(tmp, "foo", "blie", sizeof(tmp));
torture_assert_str_equal(tctx, tmp, "bliebla", "invalid sub");
return true;
@@ -52,7 +52,7 @@ static bool test_string_sub_longer(struct torture_context *tctx)
static bool test_string_sub_shorter(struct torture_context *tctx)
{
char tmp[100];
- safe_strcpy(tmp, "foobla", sizeof(tmp));
+ strlcpy(tmp, "foobla", sizeof(tmp));
string_sub(tmp, "foo", "bl", sizeof(tmp));
torture_assert_str_equal(tctx, tmp, "blbla", "invalid sub");
return true;
@@ -61,7 +61,7 @@ static bool test_string_sub_shorter(struct torture_context *tctx)
static bool test_string_sub_special_char(struct torture_context *tctx)
{
char tmp[100];
- safe_strcpy(tmp, "foobla", sizeof(tmp));
+ strlcpy(tmp, "foobla", sizeof(tmp));
string_sub(tmp, "foo", "%b;l", sizeof(tmp));
torture_assert_str_equal(tctx, tmp, "_b_lbla", "invalid sub");
return true;
diff --git a/lib/util/tests/time.c b/lib/util/tests/time.c
index 592f88f88b..a8b26762e3 100644
--- a/lib/util/tests/time.c
+++ b/lib/util/tests/time.c
@@ -81,29 +81,11 @@ static bool test_timestring(struct torture_context *tctx)
return true;
}
-static bool test_get_time_zone(struct torture_context *tctx)
-{
- time_t t = time(NULL);
- int old_extra_time_offset = extra_time_offset;
- int old_offset, new_offset;
- /* test that extra_time_offset works */
-
- old_offset = get_time_zone(t);
- extra_time_offset = 42;
- new_offset = get_time_zone(t);
- extra_time_offset = old_extra_time_offset;
- torture_assert_int_equal(tctx, old_offset+60*42, new_offset,
- "time offset not used");
- return true;
-}
-
-
struct torture_suite *torture_local_util_time(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "time");
torture_suite_add_simple_test(suite, "null_time", test_null_time);
- torture_suite_add_simple_test(suite, "get_time_zone", test_get_time_zone);
torture_suite_add_simple_test(suite, "null_nttime", test_null_nttime);
torture_suite_add_simple_test(suite, "http_timestring",
test_http_timestring);