diff options
author | Aaron Ball <nullspoon@oper.io> | 2020-05-12 08:35:44 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2020-05-12 09:03:49 -0600 |
commit | 3350ce6f2546c5d8891074e21b0d4971c6ffca8c (patch) | |
tree | aba195ab474f90cfb0b5e48b88cb32c2c2eac2db /tests | |
download | i3cstat-3350ce6f2546c5d8891074e21b0d4971c6ffca8c.tar.gz i3cstat-3350ce6f2546c5d8891074e21b0d4971c6ffca8c.tar.xz |
Initial commit
This includes support for printing battery, cpu, filesystem, memory,
time, and date sections. Sections with percentage values also support
the `display = bar` configuration to make them display a bar rather than
the actual percent. Finally, for relevant data types, colors change from
green to red as percentage approaches appropriate levels (eg: when
memory is high, color is red; when battery is low, color is red,
otherwise green).
Diffstat (limited to 'tests')
-rw-r--r-- | tests/assert.c | 52 | ||||
-rw-r--r-- | tests/assert.h | 34 | ||||
-rw-r--r-- | tests/main.c | 26 | ||||
-rw-r--r-- | tests/test_common.c | 75 | ||||
-rw-r--r-- | tests/test_common.h | 28 | ||||
-rw-r--r-- | tests/test_config.c | 27 | ||||
-rw-r--r-- | tests/test_config.h | 27 |
7 files changed, 269 insertions, 0 deletions
diff --git a/tests/assert.c b/tests/assert.c new file mode 100644 index 0000000..01a7e3b --- /dev/null +++ b/tests/assert.c @@ -0,0 +1,52 @@ +/** + * I3cstatus prints a configurable status bar for the i3 window manager + * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io> + * + * 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 "assert.h" + +int assert_strncmp(char* s1, char* s2, size_t n) { + if(strncmp(s1, s2, n) == 0) { + printf("[%sPASS%s] First %d chars of '%s' are '%s'\n", + CGREEN, CRESET, (int)n, s1, s2); + return 1; + } + + printf("[%sFAIL%s] First %d chars of '%s' are NOT '%s'\n", + CRED, CRESET, (int)n, s1, s2); + return -1; +} + +int assert_strcmp(char* s1, char* s2) { + if(strcmp(s1, s2) == 0) { + printf("[%sPASS%s] '%s' == '%s'\n", + CGREEN, CRESET, s1, s2); + return 1; + } + + printf("[%sFAIL%s] '%s' != '%s'\n", + CRED, CRESET, s1, s2); + return -1; +} + +int assert_int(char* name, int ret, int expected) { + if(ret == expected) { + printf("[%sPASS%s]", CGREEN, CRESET); + } else { + printf("[%sFAIL%s]", CRED, CRESET); + } + printf(" %s returned %d (expected %d)\n", name, ret, expected); + return -1; +} diff --git a/tests/assert.h b/tests/assert.h new file mode 100644 index 0000000..e8322e5 --- /dev/null +++ b/tests/assert.h @@ -0,0 +1,34 @@ +/** + * I3cstatus prints a configurable status bar for the i3 window manager + * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io> + * + * 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/>. + */ +#ifndef _LIB_ASSERT +#define _LIB_ASSERT +#include <stdio.h> +#include <string.h> + +#define CYELLOW "\e[32m" +#define CGREEN "\e[32m" +#define CRED "\e[31m" +#define CRESET "\e[0m" + +int assert_strncmp(char*, char*, size_t); + +int assert_strcmp(char*, char*); + +int assert_int(char*, int, int); + +#endif diff --git a/tests/main.c b/tests/main.c new file mode 100644 index 0000000..45a4fb3 --- /dev/null +++ b/tests/main.c @@ -0,0 +1,26 @@ +/** + * I3cstatus prints a configurable status bar for the i3 window manager + * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io> + * + * 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 "test_common.h" +#include "test_config.h" + +int main() { + test_bar(); + test_str_is_empty(); + test_config_load("i3cstat.conf.sample"); + test_trim(); +} diff --git a/tests/test_common.c b/tests/test_common.c new file mode 100644 index 0000000..e08c0ee --- /dev/null +++ b/tests/test_common.c @@ -0,0 +1,75 @@ +/** + * I3cstatus prints a configurable status bar for the i3 window manager + * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io> + * + * 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 "test_common.h" + +void test_str_is_empty() { + char* spaces=" "; + char* tabs="\t\t \t \t"; + char* empty=""; + char* alpha=" abc "; + char* alphanum=" abc1234 "; + char* fread=" \n"; + + assert_int("str_is_empty spaces ", str_is_empty(spaces), 1); + assert_int("str_is_empty tabs/spaces ", str_is_empty(tabs), 1); + assert_int("str_is_empty empty ", str_is_empty(empty), 1); + assert_int("str_is_empty letters ", str_is_empty(alpha), 0); + assert_int("str_is_empty alphanumeric", str_is_empty(alphanum), 0); + assert_int("str_is_empty fread ", str_is_empty(fread), 1); +} + +void test_bar() { + char buf[64] = {'\0'}; + char buf2[64] = "foo: "; + + // Fill is 0, so no colons or periods + print_bar(10, 0, buf); + assert_strncmp(buf, "[ ", 3); + + // Fill is 2, +.5, so three colons + print_bar(10, .25, buf); + assert_strncmp(buf, "[::: ", 5); + + // Fill is 2, +.3, so two colons and a period + print_bar(10, .23, buf); + assert_strncmp(buf, "[::. ", 5); + + // Fill is 2, +.3, so two colons and a period + print_bar(10, .23, &buf2[5]); + assert_strncmp(buf2, "foo: [::. ", 10); +} + +void test_trim() { + char buf[256]; + char none[64] = "needs none"; + char left[64] = " needs left"; + char right[64] = "needs right "; + char both[64] = " needs both "; + + strcpy(buf, trim(none)); + assert_strcmp(buf, "needs none"); + + strcpy(buf, trim(left)); + assert_strcmp(buf, "needs left"); + + strcpy(buf, trim(right)); + assert_strcmp(buf, "needs right"); + + strcpy(buf, trim(both)); + assert_strcmp(buf, "needs both"); +} diff --git a/tests/test_common.h b/tests/test_common.h new file mode 100644 index 0000000..f06f872 --- /dev/null +++ b/tests/test_common.h @@ -0,0 +1,28 @@ +/** + * I3cstatus prints a configurable status bar for the i3 window manager + * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io> + * + * 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 "../src/common.h" +#include "assert.h" + +#ifndef _TEST_COMMON +#define _TEST_COMMON + +void test_str_is_empty(); +void test_bar(); +void test_trim(); + +#endif diff --git a/tests/test_config.c b/tests/test_config.c new file mode 100644 index 0000000..d280895 --- /dev/null +++ b/tests/test_config.c @@ -0,0 +1,27 @@ +/** + * I3cstatus prints a configurable status bar for the i3 window manager + * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io> + * + * 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 "test_config.h" + +void test_config_load(char* path) { + void* config; + config = config_load(path); + + if(!config) { + printf("ERROR: Could not load test config file %s\n", path); + } +} diff --git a/tests/test_config.h b/tests/test_config.h new file mode 100644 index 0000000..8b32697 --- /dev/null +++ b/tests/test_config.h @@ -0,0 +1,27 @@ +/** + * I3cstatus prints a configurable status bar for the i3 window manager + * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io> + * + * 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 <stdio.h> +#include "assert.h" +#include "../src/config.h" + +#ifndef _TEST_CONFIG +#define _TEST_CONFIG + +void test_config_load(char*); + +#endif |