summaryrefslogtreecommitdiff
path: root/tests/assert.c
blob: 01a7e3b0ba788c0f37d627dcb6ae8cc553823a6e (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 "assert.h"
   19 
   20 int assert_strncmp(char* s1, char* s2, size_t n) {
   21   if(strncmp(s1, s2, n) == 0) {
   22     printf("[%sPASS%s]   First %d chars of '%s' are '%s'\n",
   23         CGREEN, CRESET, (int)n, s1, s2);
   24     return 1;
   25   }
   26 
   27   printf("[%sFAIL%s]   First %d chars of '%s' are NOT '%s'\n",
   28       CRED, CRESET, (int)n, s1, s2);
   29   return -1;
   30 }
   31 
   32 int assert_strcmp(char* s1, char* s2) {
   33   if(strcmp(s1, s2) == 0) {
   34     printf("[%sPASS%s]   '%s' == '%s'\n",
   35         CGREEN, CRESET, s1, s2);
   36     return 1;
   37   }
   38 
   39   printf("[%sFAIL%s]   '%s' != '%s'\n",
   40       CRED, CRESET, s1, s2);
   41   return -1;
   42 }
   43 
   44 int assert_int(char* name, int ret, int expected) {
   45   if(ret == expected) {
   46     printf("[%sPASS%s]", CGREEN, CRESET);
   47   } else {
   48     printf("[%sFAIL%s]", CRED, CRESET);
   49   }
   50   printf("   %s returned %d (expected %d)\n", name, ret, expected);
   51   return -1;
   52 }

Generated by cgit