aboutsummaryrefslogtreecommitdiff
path: root/tests/libfstree
diff options
context:
space:
mode:
Diffstat (limited to 'tests/libfstree')
-rw-r--r--tests/libfstree/Makemodule.am6
-rw-r--r--tests/libfstree/epoch.c48
2 files changed, 53 insertions, 1 deletions
diff --git a/tests/libfstree/Makemodule.am b/tests/libfstree/Makemodule.am
index 022b8e4..d589026 100644
--- a/tests/libfstree/Makemodule.am
+++ b/tests/libfstree/Makemodule.am
@@ -57,6 +57,10 @@ test_filename_sane_w32_SOURCES += lib/fstree/filename_sane.c
test_filename_sane_w32_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_WIN32=1
test_filename_sane_w32_LDADD = libcompat.a
+test_fstree_epoch_SOURCES = tests/libfstree/epoch.c
+test_fstree_epoch_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree
+test_fstree_epoch_SOURCES += lib/fstree/source_date_epoch.c
+
fstree_fuzz_SOURCES = tests/libfstree/fstree_fuzz.c
fstree_fuzz_LDADD = libfstree.a libfstream.a libcompat.a
@@ -65,7 +69,7 @@ FSTREE_TESTS = \
test_mknode_reg test_mknode_dir test_gen_inode_numbers \
test_add_by_path test_get_path test_fstree_sort test_fstree_from_file \
test_fstree_init test_filename_sane test_filename_sane_w32 \
- test_fstree_from_dir test_fstree_glob1
+ test_fstree_from_dir test_fstree_glob1 test_fstree_epoch
if BUILD_TOOLS
check_PROGRAMS += $(FSTREE_TESTS)
diff --git a/tests/libfstree/epoch.c b/tests/libfstree/epoch.c
new file mode 100644
index 0000000..e36cd5b
--- /dev/null
+++ b/tests/libfstree/epoch.c
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * epoch.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+#include "internal.h"
+#include "../test.h"
+
+int main(void)
+{
+ sqfs_u32 ts;
+
+ unsetenv("SOURCE_DATE_EPOCH");
+ ts = get_source_date_epoch();
+ TEST_EQUAL_UI(ts, 0);
+
+ setenv("SOURCE_DATE_EPOCH", "1337", 1);
+ ts = get_source_date_epoch();
+ TEST_EQUAL_UI(ts, 1337);
+
+ setenv("SOURCE_DATE_EPOCH", "0xCAFE", 1);
+ ts = get_source_date_epoch();
+ TEST_EQUAL_UI(ts, 0);
+
+ setenv("SOURCE_DATE_EPOCH", "foobar", 1);
+ ts = get_source_date_epoch();
+ TEST_EQUAL_UI(ts, 0);
+
+ setenv("SOURCE_DATE_EPOCH", "-12", 1);
+ ts = get_source_date_epoch();
+ TEST_EQUAL_UI(ts, 0);
+
+ setenv("SOURCE_DATE_EPOCH", "12", 1);
+ ts = get_source_date_epoch();
+ TEST_EQUAL_UI(ts, 12);
+
+ setenv("SOURCE_DATE_EPOCH", "4294967295", 1);
+ ts = get_source_date_epoch();
+ TEST_EQUAL_UI(ts, 0xFFFFFFFF);
+
+ setenv("SOURCE_DATE_EPOCH", "4294967296", 1);
+ ts = get_source_date_epoch();
+ TEST_EQUAL_UI(ts, 0);
+
+ return EXIT_SUCCESS;
+}