1 /*
2  * Copyright (c) 2020 Nitrokey UG
3  *
4  * This file is part of libnitrokey.
5  *
6  * libnitrokey is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * any later version.
10  *
11  * libnitrokey is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with libnitrokey. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * SPDX-License-Identifier: LGPL-3.0
20  */
21 
22 #include <stdlib.h>
23 #include "../NK_C_API.h"
24 
25 // This test should be run with valgrind to make sure that there are no
26 // memory leaks in the tested functions:
27 //     valgrind ./test_memory
test_too_long_strings(C)28 int main() {
29 	int result = NK_login_auto();
30 	if (result != 1)
31 		return 1;
32 
33 	int retry_count = NK_get_admin_retry_count();
34 	if (retry_count != 3)
35 		return 1;
36 	retry_count = NK_get_user_retry_count();
37 	if (retry_count != 3)
38 		return 1;
39 
40 	enum NK_device_model model = NK_get_device_model();
41 	if (model != NK_PRO && model != NK_STORAGE)
42 		return 1;
43 
44 	uint8_t *config = NK_read_config();
45 	if (config == NULL)
46 		return 1;
47 	NK_free_config(config);
48 
49 	result = NK_enable_password_safe("123456");
50 	if (result != 0)
51 		return 1;
52 
53 	uint8_t *slot_status = NK_get_password_safe_slot_status();
54 	if (slot_status == NULL) {
55 		return 1;
56 	}
57 	NK_free_password_safe_slot_status(slot_status);
58 
59 	NK_logout();
60 
61 	return 0;
62 }
63 
64