blob: a72ec30ffc5d2f6f46406404f9e8b87141c86b92 [file] [log] [blame]
Bryce Harrington82b9f2b2016-08-03 17:40:51 -07001/*
2 * Copyright © 2016 Samsung Electronics Co., Ltd
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26#include "config.h"
27
28#include <stdlib.h>
29#include <stdbool.h>
30#include <stdio.h>
31#include <assert.h>
32
33#include "shared/string-helpers.h"
34
35#include "weston-test-client-helper.h"
36
37TEST(strtol_conversions)
38{
39 bool ret;
40 int32_t val = -1;
41 char *str = NULL;
42
43 str = ""; val = -1;
44 ret = safe_strtoint(str, &val);
45 assert(ret == false);
46 assert(val == -1);
47
48 str = "."; val = -1;
49 ret = safe_strtoint(str, &val);
50 assert(ret == false);
51 assert(val == -1);
52
53 str = "42"; val = -1;
54 ret = safe_strtoint(str, &val);
55 assert(ret == true);
56 assert(val == 42);
57
58 str = "-42"; val = -1;
59 ret = safe_strtoint(str, &val);
60 assert(ret == true);
61 assert(val == -42);
62
63 str = "0042"; val = -1;
64 ret = safe_strtoint(str, &val);
65 assert(ret == true);
66 assert(val == 42);
67
68 str = "x42"; val = -1;
69 ret = safe_strtoint(str, &val);
70 assert(ret == false);
71 assert(val == -1);
72
73 str = "42x"; val = -1;
74 ret = safe_strtoint(str, &val);
75 assert(ret == false);
76 assert(val == -1);
77
78 str = "0x42424242"; val = -1;
79 ret = safe_strtoint(str, &val);
80 assert(ret == false);
81 assert(val == -1);
82
83 str = "424748364789L"; val = -1;
84 ret = safe_strtoint(str, &val);
85 assert(ret == false);
86 assert(val == -1);
87}