]> err.no Git - yubikey-personalization/commitdiff
test yk_check_firmware2() with a couple of versions
authorKlas Lindfors <klas@yubico.com>
Fri, 9 Nov 2012 14:47:46 +0000 (15:47 +0100)
committerKlas Lindfors <klas@yubico.com>
Fri, 9 Nov 2012 14:51:56 +0000 (15:51 +0100)
.gitignore
tests/Makefile.am
tests/test_yk_utilities.c [new file with mode: 0644]

index 46b2343e67d773457bd39e72823c85ad66a52720..a428b2eeb44f6140a195e0dfc8840f2739e2aa8e 100644 (file)
@@ -46,6 +46,8 @@ tests/test_threaded_calls
 tests/test_threaded_calls.o
 tests/test_ykpbkdf2
 tests/test_ykpbkdf2.o
+tests/test_yk_utilities
+tests/test_yk_utilities.o
 tmp/
 usha.lo
 usha.o
index d2377c08bf97e04baa9f14b657f6886e0e6d077d..eff607d123d89adf699fc9e1be1726e2b5822a62 100644 (file)
@@ -32,7 +32,8 @@ AM_CFLAGS=-I$(srcdir)/.. -I$(srcdir)/../ykcore $(WARN_CFLAGS)
 LDADD = ../libykpers-1.la $(LTLIBYUBIKEY)
 
 ctests = selftest test_args_to_config test_key_generation \
-       test_ndef_construction test_threaded_calls test_ykpbkdf2
+       test_ndef_construction test_threaded_calls test_ykpbkdf2 \
+       test_yk_utilities
 check_PROGRAMS = $(ctests)
 TESTS = $(ctests)
 
diff --git a/tests/test_yk_utilities.c b/tests/test_yk_utilities.c
new file mode 100644 (file)
index 0000000..395716f
--- /dev/null
@@ -0,0 +1,89 @@
+/* -*- mode:C; c-file-style: "bsd" -*- */
+/*
+ * Copyright (c) 2012 Yubico AB
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <assert.h>
+
+#include <ykstatus.h>
+#include <ykcore.h>
+#include <ykdef.h>
+
+struct {
+       int major;
+       int minor;
+       int build;
+} supported[] = {
+       {0,9,9},
+       {1,2,9},
+       {1,3,1},
+       {2,0,2},
+       {2,1,1},
+       {2,2,3},
+       {2,3,0},
+       {3,0,1},
+};
+
+static YK_STATUS * _test_init_st(int major, int minor, int build)
+{
+       YK_STATUS *st = ykds_alloc();
+       struct status_st *t;
+
+       t = (struct status_st *) st;
+
+       /* connected key details */
+       t->versionMajor = major;
+       t->versionMinor = minor;
+       t->versionBuild = build;
+
+       return st;
+}
+
+static void _test_yk_firmware(void)
+{
+       size_t i;
+       for(i = 0; i < sizeof(supported) / (sizeof(int) * 3); i++) {
+               int rc;
+               YK_STATUS *st = _test_init_st(supported[i].major, supported[i].minor, supported[i].build);
+               printf("testing: %d.%d.%d\n", supported[i].major, supported[i].minor, supported[i].build);
+               rc = yk_check_firmware_version2(st);
+               assert(rc == 1);
+               ykds_free(st);
+       }
+}
+
+int main(void)
+{
+       _test_yk_firmware();
+
+       return 0;
+}
+