summaryrefslogtreecommitdiff
path: root/tests/test_common.c
blob: e08c0ee8b66a80c56e89e3f41083377c0d23b672 (plain)
    1 /**
    2  * I3cstatus prints a configurable status bar for the i3 window manager
    3  * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io>
    4  * 
    5  * This program is free software: you can redistribute it and/or modify
    6  * it under the terms of the GNU General Public License as published by
    7  * the Free Software Foundation, either version 3 of the License, or
    8  * (at your option) any later version.
    9  * 
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU General Public License for more details.
   14  * 
   15  * You should have received a copy of the GNU General Public License
   16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   17  */
   18 #include "test_common.h"
   19 
   20 void test_str_is_empty() {
   21   char* spaces="       ";
   22   char* tabs="\t\t  \t \t";
   23   char* empty="";
   24   char* alpha=" abc ";
   25   char* alphanum=" abc1234 ";
   26   char* fread="        \n";
   27 
   28   assert_int("str_is_empty spaces      ", str_is_empty(spaces), 1);
   29   assert_int("str_is_empty tabs/spaces ", str_is_empty(tabs), 1);
   30   assert_int("str_is_empty empty       ", str_is_empty(empty), 1);
   31   assert_int("str_is_empty letters     ", str_is_empty(alpha), 0);
   32   assert_int("str_is_empty alphanumeric", str_is_empty(alphanum), 0);
   33   assert_int("str_is_empty fread       ", str_is_empty(fread), 1);
   34 }
   35 
   36 void test_bar() {
   37   char buf[64] = {'\0'};
   38   char buf2[64] = "foo: ";
   39 
   40   // Fill is 0, so no colons or periods
   41   print_bar(10, 0, buf);
   42   assert_strncmp(buf, "[  ", 3);
   43 
   44   // Fill is 2, +.5, so three colons
   45   print_bar(10, .25, buf);
   46   assert_strncmp(buf, "[::: ", 5);
   47 
   48   // Fill is 2, +.3, so two colons and a period
   49   print_bar(10, .23, buf);
   50   assert_strncmp(buf, "[::. ", 5);
   51 
   52   // Fill is 2, +.3, so two colons and a period
   53   print_bar(10, .23, &buf2[5]);
   54   assert_strncmp(buf2, "foo: [::. ", 10);
   55 }
   56 
   57 void test_trim() {
   58   char buf[256];
   59   char none[64]  = "needs none";
   60   char left[64]  = "  needs left";
   61   char right[64] = "needs right  ";
   62   char both[64]  = "  needs both  ";
   63 
   64   strcpy(buf, trim(none));
   65   assert_strcmp(buf, "needs none");
   66 
   67   strcpy(buf, trim(left));
   68   assert_strcmp(buf, "needs left");
   69 
   70   strcpy(buf, trim(right));
   71   assert_strcmp(buf, "needs right");
   72 
   73   strcpy(buf, trim(both));
   74   assert_strcmp(buf, "needs both");
   75 }

Generated by cgit