summaryrefslogtreecommitdiff
path: root/tests/libgit2/date
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-11-16 23:29:22 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2022-02-22 22:07:45 -0500
commit3344fddc97bbdea9c1b6ebb6f7fb6dbd70b41dfb (patch)
treefd6368a72944571c51627b40c592e7d58e0036e1 /tests/libgit2/date
parent91ba089663f5efc3bd4ba14a5099372cf5ce57a6 (diff)
downloadlibgit2-3344fddc97bbdea9c1b6ebb6f7fb6dbd70b41dfb.tar.gz
refactor: `tests` is now `tests/libgit2`
Like we want to separate libgit2 and utility source code, we want to separate libgit2 and utility tests. Start by moving all the tests into libgit2.
Diffstat (limited to 'tests/libgit2/date')
-rw-r--r--tests/libgit2/date/date.c22
-rw-r--r--tests/libgit2/date/rfc2822.c37
2 files changed, 59 insertions, 0 deletions
diff --git a/tests/libgit2/date/date.c b/tests/libgit2/date/date.c
new file mode 100644
index 000000000..82b5c6728
--- /dev/null
+++ b/tests/libgit2/date/date.c
@@ -0,0 +1,22 @@
+#include "clar_libgit2.h"
+
+#include "date.h"
+
+void test_date_date__overflow(void)
+{
+#ifdef __LP64__
+ git_time_t d2038, d2039;
+
+ /* This is expected to fail on a 32-bit machine. */
+ cl_git_pass(git_date_parse(&d2038, "2038-1-1"));
+ cl_git_pass(git_date_parse(&d2039, "2039-1-1"));
+ cl_assert(d2038 < d2039);
+#endif
+}
+
+void test_date_date__invalid_date(void)
+{
+ git_time_t d;
+ cl_git_fail(git_date_parse(&d, ""));
+ cl_git_fail(git_date_parse(&d, "NEITHER_INTEGER_NOR_DATETIME"));
+}
diff --git a/tests/libgit2/date/rfc2822.c b/tests/libgit2/date/rfc2822.c
new file mode 100644
index 000000000..b0bbcfce5
--- /dev/null
+++ b/tests/libgit2/date/rfc2822.c
@@ -0,0 +1,37 @@
+#include "clar_libgit2.h"
+
+#include "date.h"
+
+void test_date_rfc2822__format_rfc2822_no_offset(void)
+{
+ git_time t = {1397031663, 0};
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_date_rfc2822_fmt(&buf, t.time, t.offset));
+ cl_assert_equal_s("Wed, 9 Apr 2014 08:21:03 +0000", buf.ptr);
+
+ git_str_dispose(&buf);
+}
+
+void test_date_rfc2822__format_rfc2822_positive_offset(void)
+{
+ git_time t = {1397031663, 120};
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_date_rfc2822_fmt(&buf, t.time, t.offset));
+ cl_assert_equal_s("Wed, 9 Apr 2014 10:21:03 +0200", buf.ptr);
+
+ git_str_dispose(&buf);
+}
+
+void test_date_rfc2822__format_rfc2822_negative_offset(void)
+{
+ git_time t = {1397031663, -120};
+ git_str buf = GIT_STR_INIT;
+
+ cl_git_pass(git_date_rfc2822_fmt(&buf, t.time, t.offset));
+ cl_assert_equal_s("Wed, 9 Apr 2014 06:21:03 -0200", buf.ptr);
+
+ git_str_dispose(&buf);
+}
+