]> err.no Git - yubikey-personalization/commitdiff
let the firmware test do negative testing
authorKlas Lindfors <klas@yubico.com>
Thu, 2 Jan 2014 08:16:06 +0000 (09:16 +0100)
committerKlas Lindfors <klas@yubico.com>
Thu, 2 Jan 2014 08:16:06 +0000 (09:16 +0100)
tests/test_yk_utilities.c

index 40dad063444e06834f1c5990c6ba5e7ab74874c9..8e2bf2cdc24766800b0609519e01d9770e7713ff 100644 (file)
 #include <stdlib.h>
 #include <unistd.h>
 #include <assert.h>
+#include <stdbool.h>
 
 #include <ykstatus.h>
 #include <ykcore.h>
 #include <ykdef.h>
 
-struct {
+struct versions {
        int major;
        int minor;
        int build;
+       bool support;
 } supported[] = {
-       {0,9,9},
-       {1,2,9},
-       {1,3,1},
-       {2,0,2},
-       {2,1,1},
-       {2,2,3},
-       {2,3,0},
-       {2,4,5},
-       {3,0,1},
-       {3,2,8},
+       {0,8,0,false},
+       {0,9,9,true},
+       {1,2,9,true},
+       {1,3,1,true},
+       {2,0,2,true},
+       {2,1,1,true},
+       {2,2,3,true},
+       {2,3,0,true},
+       {2,4,5,true},
+       {2,5,2,false},
+       {3,0,1,true},
+       {3,2,8,true},
+       {3,3,0,false},
+       {4,0,0,false},
 };
 
 static YK_STATUS * _test_init_st(int major, int minor, int build)
@@ -72,12 +78,17 @@ static YK_STATUS * _test_init_st(int major, int minor, int build)
 static void _test_yk_firmware(void)
 {
        size_t i;
-       for(i = 0; i < sizeof(supported) / (sizeof(int) * 3); i++) {
+       for(i = 0; i < sizeof(supported) / sizeof(struct versions); 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);
+               if(supported[i].support == true) {
+                       assert(rc == 1);
+               } else {
+                       assert(yk_errno == YK_EFIRMWARE);
+                       assert(rc == 0);
+               }
                ykds_free(st);
        }
 }