Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_util.c
Go to the documentation of this file.
1/*
2 * Copyright 2015-2018 Yubico AB
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifdef NDEBUG
18#undef NDEBUG
19#endif
20
21#include <assert.h>
22#include <stdint.h>
23#include <stdio.h>
24#include <string.h>
25
26#include "yubihsm.h"
27#include "internal.h"
28
31
32static void test_status(void) {
33 struct {
34 const char *data;
36 } tests[] = {
37 {"status=OK\nversion=1.2.3\n",
38 {NULL, NULL, NULL, NULL, NULL, true, 1, 2, 3, "", 0, 0}},
39 {"", {NULL, NULL, NULL, NULL, NULL, false, 0, 0, 0, "", 0, 0}},
40 {"foobar", {NULL, NULL, NULL, NULL, NULL, false, 0, 0, 0, "", 0, 0}},
41 {"\n\n\n\n\n\n", {NULL, NULL, NULL, NULL, NULL, false, 0, 0, 0, "", 0, 0}},
42 {"status=NO_DEVICE\nserial=*\nversion=1.0.2\npid=412\naddress=\nport=12345",
43 {NULL, NULL, NULL, NULL, NULL, false, 1, 0, 2, "", 12345, 412}},
44 {"version=1.2", {NULL, NULL, NULL, NULL, NULL, false, 1, 2, 0, "", 0, 0}},
45 {"version=foobar",
46 {NULL, NULL, NULL, NULL, NULL, false, 0, 0, 0, "", 0, 0}},
47 {"version=2..\nstatus=OK",
48 {NULL, NULL, NULL, NULL, NULL, true, 2, 0, 0, "", 0, 0}},
49 };
50
51 for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
52 yh_connector c = {NULL, NULL, NULL, NULL, NULL, false, 0, 0, 0, "", 0, 0};
53 char *data = strdup(tests[i].data);
54
55 parse_status_data(data, &c);
56 free(data);
57 assert(memcmp(&c, &tests[i].c, sizeof(c)) == 0);
58 }
59}
60
61int main(void) {
62 _yh_output = stderr;
63 _yh_verbosity = 0;
64
65 test_status();
66}
void YH_INTERNAL parse_status_data(char *data, yh_connector *connector)
Definition lib_util.c:65
unsigned char uint8_t
Definition stdint.h:124
uint8_t _yh_verbosity
Definition test_util.c:29
FILE * _yh_output
Definition test_util.c:30
int main(void)
Definition test_util.c:61