test-parse-util.c revision b26fa1a2fbcfee7d03b0c8fd15ec3aa64ae70b9f
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
Copyright 2013 Thomas H.P. Andersen
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <locale.h>
#include <math.h>
#include "log.h"
#include "parse-util.h"
static void test_parse_boolean(void) {
}
static void test_parse_pid(void) {
int r;
assert_se(r == 0);
assert_se(r == 0);
}
static void test_parse_mode(void) {
mode_t m;
}
static void test_parse_size(void) {
}
static void test_parse_range(void) {
/* Successful cases */
/* Leading whitespace is acceptable */
/* Error cases, make sure they fail as expected */
/* Empty string */
/* 111--123 will pass -123 to safe_atou which returns -ERANGE for negative */
/* Error on trailing dash */
/* Whitespace is not a separator */
/* Trailing whitespace is invalid (from safe_atou) */
/* Out of the "unsigned" range, this is 1<<64 */
}
static void test_safe_atolli(void) {
int r;
long long l;
r = safe_atolli("12345", &l);
assert_se(r == 0);
assert_se(l == 12345);
r = safe_atolli(" 12345", &l);
assert_se(r == 0);
assert_se(l == 12345);
r = safe_atolli("-12345", &l);
assert_se(r == 0);
assert_se(l == -12345);
r = safe_atolli(" -12345", &l);
assert_se(r == 0);
assert_se(l == -12345);
r = safe_atolli("12345678901234567890", &l);
r = safe_atolli("-12345678901234567890", &l);
r = safe_atolli("junk", &l);
}
static void test_safe_atou16(void) {
int r;
uint16_t l;
r = safe_atou16("12345", &l);
assert_se(r == 0);
assert_se(l == 12345);
r = safe_atou16(" 12345", &l);
assert_se(r == 0);
assert_se(l == 12345);
r = safe_atou16("123456", &l);
r = safe_atou16("-1", &l);
r = safe_atou16(" -1", &l);
r = safe_atou16("junk", &l);
}
static void test_safe_atoi16(void) {
int r;
int16_t l;
r = safe_atoi16("-12345", &l);
assert_se(r == 0);
assert_se(l == -12345);
r = safe_atoi16(" -12345", &l);
assert_se(r == 0);
assert_se(l == -12345);
r = safe_atoi16("32767", &l);
assert_se(r == 0);
assert_se(l == 32767);
r = safe_atoi16(" 32767", &l);
assert_se(r == 0);
assert_se(l == 32767);
r = safe_atoi16("36536", &l);
r = safe_atoi16("-32769", &l);
r = safe_atoi16("junk", &l);
}
static void test_safe_atod(void) {
int r;
double d;
char *e;
r = safe_atod("junk", &d);
r = safe_atod("0.2244", &d);
assert_se(r == 0);
r = safe_atod("0,5", &d);
errno = 0;
strtod("0,5", &e);
assert_se(*e == ',');
/* Check if this really is locale independent */
r = safe_atod("0.2244", &d);
assert_se(r == 0);
r = safe_atod("0,5", &d);
errno = 0;
}
/* And check again, reset */
r = safe_atod("0.2244", &d);
assert_se(r == 0);
r = safe_atod("0,5", &d);
errno = 0;
strtod("0,5", &e);
assert_se(*e == ',');
}
log_open();
return 0;
}