From 9ed94f80d5a448e1eb00284d0893ad8ab86ef38b Mon Sep 17 00:00:00 2001 From: Daniel Salzman <daniel.salzman@nic.cz> Date: Mon, 20 Aug 2012 14:18:05 +0200 Subject: [PATCH] Added test for date_to_timestamp --- src/Makefile.am | 6 +- .../test/{test_functions.c => processing.c} | 0 .../test/{test_functions.h => processing.h} | 2 + src/zscanner/test/tests.c | 62 +++++++++++++++++++ src/zscanner/test/tests.h | 36 +++++++++++ 5 files changed, 104 insertions(+), 2 deletions(-) rename src/zscanner/test/{test_functions.c => processing.c} (100%) rename src/zscanner/test/{test_functions.h => processing.h} (99%) create mode 100644 src/zscanner/test/tests.c create mode 100644 src/zscanner/test/tests.h diff --git a/src/Makefile.am b/src/Makefile.am index 49bf349896..2ba64a5b36 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -67,8 +67,10 @@ unittests_zscanner_SOURCES = \ zscanner/scanner.c \ zscanner/scanner_functions.h \ zscanner/scanner_functions.c \ - zscanner/test/test_functions.h \ - zscanner/test/test_functions.c + zscanner/test/tests.h \ + zscanner/test/tests.c \ + zscanner/test/processing.h \ + zscanner/test/processing.c unittests_SOURCES = \ tests/common/acl_tests.c \ diff --git a/src/zscanner/test/test_functions.c b/src/zscanner/test/processing.c similarity index 100% rename from src/zscanner/test/test_functions.c rename to src/zscanner/test/processing.c diff --git a/src/zscanner/test/test_functions.h b/src/zscanner/test/processing.h similarity index 99% rename from src/zscanner/test/test_functions.h rename to src/zscanner/test/processing.h index 26090aa3e7..f3dcfbd026 100644 --- a/src/zscanner/test/test_functions.h +++ b/src/zscanner/test/processing.h @@ -29,10 +29,12 @@ #include "zscanner/scanner.h" + void process_error(const scanner_t *scanner); void process_record(const scanner_t *scanner); + #endif // _ZSCANNER__TEST_FUNCTIONS_H_ /*! @} */ diff --git a/src/zscanner/test/tests.c b/src/zscanner/test/tests.c new file mode 100644 index 0000000000..3f6edb2875 --- /dev/null +++ b/src/zscanner/test/tests.c @@ -0,0 +1,62 @@ +/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> + + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "zscanner/test/tests.h" + +#include <inttypes.h> // PRIu64 +#include <stdio.h> // printf +#include <time.h> +#include <stdlib.h> +#include "../scanner_functions.h" + +int test__date_to_timestamp() +{ + time_t timestamp_in = 0, timestamp_out = 0, max_timestamp = 0; + char buffer[16]; + struct tm tm; + + putenv("TZ=UTC"); + tzset(); + + strptime("21051231235959", "%Y%m%d%H%M%S", &tm); + max_timestamp = mktime(&tm); + + for (timestamp_in = 0; timestamp_in < max_timestamp; timestamp_in += 30) { + strftime(buffer, sizeof(buffer), "%Y%m%d%H%M%S", gmtime(×tamp_in)); + + date_to_timestamp((uint8_t *)buffer, (uint32_t *)(×tamp_out)); + + if (timestamp_in % 10000000 == 0) { + printf("%s = %"PRIu64"\n", buffer, timestamp_in); + } + + if (timestamp_in != timestamp_out) { + if (timestamp_in > timestamp_out) { + printf("%s = %"PRIu64", in - out = %"PRIu64"\n", + buffer, timestamp_in, timestamp_in - timestamp_out); + } + else { + printf("%s = %"PRIu64", out - in = %"PRIu64"\n", + buffer, timestamp_in, timestamp_out - timestamp_in); + } + + return -1; + } + } + + return 0; +} + diff --git a/src/zscanner/test/tests.h b/src/zscanner/test/tests.h new file mode 100644 index 0000000000..5f53803f3d --- /dev/null +++ b/src/zscanner/test/tests.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> + + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +/*! + * \file tests.h + * + * \author Daniel Salzman <daniel.salzman@nic.cz> + * + * \brief Zone scanner test functions. + * + * \addtogroup zone_scanner_test + * @{ + */ + +#ifndef _ZSCANNER__TESTS_H_ +#define _ZSCANNER__TESTS_H_ + + +int test__date_to_timestamp(); + + +#endif // _ZSCANNER__TESTS_H_ + +/*! @} */ -- GitLab