github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/tests/unary.c (about) 1 #include "tests.h" 2 #include <stdio.h> 3 4 #define START_TEST(t) \ 5 diag(#t); \ 6 test_##t(); 7 8 void test_notint() 9 { 10 int i = 0; 11 if (!i) { 12 pass("good"); 13 } else { 14 fail("fail"); 15 } 16 17 i = 123; 18 if (!i) { 19 fail("fail"); 20 } else { 21 pass("good"); 22 } 23 } 24 25 void test_notptr() 26 { 27 FILE* fp = NULL; 28 if (!fp) { 29 pass("good"); 30 } else { 31 fail("fail"); 32 } 33 34 fp = stdin; 35 if (!fp) { 36 fail("fail"); 37 } else { 38 pass("good"); 39 } 40 } 41 42 int conv(int i) 43 { 44 return i; 45 } 46 47 void test_sizeoftest() 48 { 49 // example : 50 // while ((n = fread(buf, sizeof *buf, sizeof buf, fin)) > 0) 51 // UnaryExprOrTypeTraitExpr 'unsigned long' sizeof 52 // `-UnaryOperator 0x2e1a880 'char' lvalue prefix '*' 53 // `-ImplicitCastExpr 0x2e1a868 'char *' <ArrayToPointerDecay> 54 // `-DeclRefExpr 0x2e1a840 'char [1024]' lvalue Var 0x2e19d78 'buf' 'char [1024]' 55 char* buf = NULL; 56 if (conv(sizeof *buf) > 0) { 57 pass("ok"); 58 } else { 59 fail("fail"); 60 } 61 (void)(buf); 62 } 63 64 int main() 65 { 66 plan(5); 67 68 START_TEST(notint) 69 START_TEST(notptr) 70 START_TEST(sizeoftest) 71 72 done_testing(); 73 }