File: param_string.c

package info (click to toggle)
bctoolbox 5.3.105-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,380 kB
  • sloc: ansic: 9,623; cpp: 5,550; sh: 26; makefile: 12
file content (59 lines) | stat: -rw-r--r-- 2,390 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright (c) 2016-2020 Belledonne Communications SARL.
 *
 * This file is part of bctoolbox.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "bctoolbox/param_string.h"
#include "bctoolbox_tester.h"

static void get_value_test(void) {
	size_t result_len = 10;
	char *result = bctbx_malloc(result_len);

	char *paramString = "";
	BC_ASSERT_FALSE(bctbx_param_string_get_value(paramString, "param", result, result_len));

	paramString = "param=true";
	BC_ASSERT_TRUE(bctbx_param_string_get_value(paramString, "param", result, result_len));
	BC_ASSERT_TRUE(strcmp(result, "true") == 0);
	BC_ASSERT_FALSE(bctbx_param_string_get_value(paramString, "notparam", result, result_len));

	paramString = "test;param=true;test";
	BC_ASSERT_TRUE(bctbx_param_string_get_value(paramString, "param", result, result_len));
	BC_ASSERT_TRUE(strcmp(result, "true") == 0);
	BC_ASSERT_FALSE(bctbx_param_string_get_value(paramString, "notparam", result, result_len));

	bctbx_free(result);
}

static void get_bool_value_test(void) {
	char *paramString = "";
	BC_ASSERT_FALSE(bctbx_param_string_get_bool_value(paramString, "param"));
	paramString = "param=false";
	BC_ASSERT_FALSE(bctbx_param_string_get_bool_value(paramString, "param"));
	paramString = "param=42";
	BC_ASSERT_FALSE(bctbx_param_string_get_bool_value(paramString, "param"));
	paramString = "param=true";
	BC_ASSERT_TRUE(bctbx_param_string_get_bool_value(paramString, "param"));
}

static test_t param_string_tests[] = {TEST_NO_TAG("Get value", get_value_test),
                                      TEST_NO_TAG("Get bool value", get_bool_value_test)};

test_suite_t param_string_test_suite = {
    "Param string",     NULL, NULL, NULL, NULL, sizeof(param_string_tests) / sizeof(param_string_tests[0]),
    param_string_tests, 0};