From: Klas Lindfors Date: Fri, 9 Nov 2012 14:47:46 +0000 (+0100) Subject: test yk_check_firmware2() with a couple of versions X-Git-Tag: v1.10.0~27 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b95c4d1a3efbd91a888b5fab0234dbe561e82d1;p=yubikey-personalization test yk_check_firmware2() with a couple of versions --- diff --git a/.gitignore b/.gitignore index 46b2343..a428b2e 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/tests/Makefile.am b/tests/Makefile.am index d2377c0..eff607d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 0000000..395716f --- /dev/null +++ b/tests/test_yk_utilities.c @@ -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 +#include +#include +#include + +#include +#include +#include + +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; +} +