/** * I3cstatus prints a configurable status bar for the i3 window manager * Copyright (C) 2020 Aaron Ball * * 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 . */ #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); print_bar(8, 0, buf); assert_strcmp(buf, "[ ]"); print_bar(8, 1, buf); assert_strcmp(buf, "[::::::::]"); print_bar(8, .42, buf); assert_strcmp(buf, "[:::. ]"); // Fill is 0, so no colons or periods print_bar(10, .13, buf); assert_strcmp(buf, "[:. ]"); // Fill is 0, so no colons or periods print_bar(10, .17, buf); assert_strncmp(buf, "[:: ", 4); // 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"); }