Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_usb_url.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#include <assert.h>
21#include <stdio.h>
22#include <string.h>
23
24#include "yubihsm.h"
25#include "internal.h"
26
29
30static void test_urls(void) {
31 struct {
32 const char *string;
33 unsigned long serial;
34 bool ret;
35 } tests[] = {
36 {"yhusb://serial=12345", 12345, true},
37 {"", 0, false},
38 {"yhusb://", 0, true},
39 {"yhusb://foo=bar&serial=1000000", 1000000, true},
40 };
41
42 for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
43 unsigned long serial = 0;
44 assert(parse_usb_url(tests[i].string, &serial) == tests[i].ret);
45 if (tests[i].ret) {
46 assert(serial == tests[i].serial);
47 }
48 }
49}
50
51int main(void) {
52 _yh_output = stderr;
53 test_urls();
54}
bool YH_INTERNAL parse_usb_url(const char *url, unsigned long *serial)
Definition lib_util.c:140
unsigned char uint8_t
Definition stdint.h:124
uint8_t _yh_verbosity
FILE * _yh_output
int main(void)
#define YH_VERB_ALL
Debug level all. All previous options enabled.
Definition yubihsm.h:145
uint32_t serial
CK_RV ret