aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_next_algorithm.c
diff options
context:
space:
mode:
Diffstat (limited to 'librecrypt_next_algorithm.c')
-rw-r--r--librecrypt_next_algorithm.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/librecrypt_next_algorithm.c b/librecrypt_next_algorithm.c
new file mode 100644
index 0000000..b825582
--- /dev/null
+++ b/librecrypt_next_algorithm.c
@@ -0,0 +1,82 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifndef TEST
+
+
+extern inline char *librecrypt_next_algorithm(char **hash);
+
+
+#else
+
+
+static void
+testcase_1(void)
+{
+ char hash[] = ">a$b>c$d>e$f$";
+ char *s = hash, *a;
+
+ EXPECT((a = librecrypt_next_algorithm(&s)));
+ EXPECT(s != NULL);
+ EXPECT(!strcmp(a, ""));
+ EXPECT(!strcmp(s, "a$b>c$d>e$f$"));
+
+ EXPECT((a = librecrypt_next_algorithm(&s)));
+ EXPECT(s != NULL);
+ EXPECT(!strcmp(a, "a$b"));
+ EXPECT(!strcmp(s, "c$d>e$f$"));
+
+ EXPECT((a = librecrypt_next_algorithm(&s)));
+ EXPECT(s != NULL);
+ EXPECT(!strcmp(a, "c$d"));
+ EXPECT(!strcmp(s, "e$f$"));
+
+ EXPECT((a = librecrypt_next_algorithm(&s)));
+ EXPECT(s == NULL);
+ EXPECT(!strcmp(a, "e$f$"));
+
+ EXPECT(librecrypt_next_algorithm(&s) == NULL);
+ EXPECT(s == NULL);
+}
+
+
+static void
+testcase_2(void)
+{
+ char hash[] = "a$b>c$d>e$f$>";
+ char *s = hash, *a;
+
+ EXPECT((a = librecrypt_next_algorithm(&s)));
+ EXPECT(s != NULL);
+ EXPECT(!strcmp(a, "a$b"));
+ EXPECT(!strcmp(s, "c$d>e$f$>"));
+
+ EXPECT((a = librecrypt_next_algorithm(&s)));
+ EXPECT(s != NULL);
+ EXPECT(!strcmp(a, "c$d"));
+ EXPECT(!strcmp(s, "e$f$>"));
+
+ EXPECT((a = librecrypt_next_algorithm(&s)));
+ EXPECT(s != NULL);
+ EXPECT(!strcmp(a, "e$f$"));
+ EXPECT(!strcmp(s, ""));
+
+ EXPECT((a = librecrypt_next_algorithm(&s)));
+ EXPECT(s == NULL);
+ EXPECT(!strcmp(a, ""));
+
+ EXPECT(librecrypt_next_algorithm(&s) == NULL);
+ EXPECT(s == NULL);
+}
+
+
+int
+main(void)
+{
+ SET_UP_ALARM();
+ testcase_1();
+ testcase_2();
+ return 0;
+}
+
+
+#endif