github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/tests/stdbool.c (about) 1 #include "tests.h" 2 #include <stdbool.h> 3 #include <stdio.h> 4 5 _Bool f(_Bool b) 6 { 7 return b; 8 } 9 10 int main() 11 { 12 plan(12); 13 14 bool trueBool = true; 15 bool falseBool = false; 16 17 is_true(trueBool); 18 is_false(falseBool); 19 20 if (trueBool) { 21 pass("%s", "true") 22 } else { 23 fail("%s", "should not reach here") 24 } 25 26 if (!trueBool) { 27 fail("%s", "should not reach here") 28 } else { 29 pass("%s", "true") 30 } 31 32 if (falseBool) { 33 fail("%s", "should not reach here") 34 } else { 35 pass("%s", "false") 36 } 37 38 if (!falseBool) { 39 pass("%s", "false") 40 } else { 41 fail("%s", "should not reach here") 42 } 43 44 _Bool var = true; 45 if (var) { 46 pass("%s", "ok") 47 } else { 48 fail("%s", "should not reach here") 49 } 50 51 var = true; 52 if (var - var) { 53 fail("%s", "should not reach here") 54 } else { 55 pass("%s", "ok") 56 } 57 58 var = true; 59 if (var - var == false) { 60 pass("%s", "ok") 61 } else { 62 fail("%s", "should not reach here") 63 } 64 65 _Bool b = 0; // false 66 if (b) { 67 b++; 68 } 69 if (b == false) // b = 0 70 { 71 pass("%s", "ok") 72 } 73 74 _Bool c = f(b); 75 b = b + c; 76 if (b == false) { 77 pass("%s", "ok") 78 } 79 int i = (int)(b); 80 if (i == 0) { 81 pass("%s", "ok") 82 } 83 84 done_testing(); 85 }