Usermode/c++extras - Cleanup of cprintf code
[tpg/acess2.git] / Usermode / Libraries / libc++_extras.so_src / TEST_cprintf.cpp
1 /*
2  */
3 #include <cxxextras_printf>
4 #include <cstdio>
5 #include <stdexcept>
6
7 void my_puts(const char *str, size_t len)
8 {
9         fwrite(str, 1, len, stdout);
10 }
11
12 #define ASSERT_EXCEPTION(expr, Exception) do{bool _ok=false; try { expr; } catch(const Exception& e){_ok=true;}if(!_ok)throw ::std::runtime_error("Didn't throw "#Exception);}while(0)
13
14 int main()
15 {
16         printf("Success\n");
17         ::cxxextras::cprintf(my_puts, "%s %i %+#-010x\n", "hello_world", 1337, 0x1234565);
18         
19         printf("Too Few\n");
20         ASSERT_EXCEPTION( ::cxxextras::cprintf(my_puts, "%s %i %+#-010x\n"), ::cxxextras::cprintf_toofewargs );
21         printf("Too Many\n");
22         ASSERT_EXCEPTION( ::cxxextras::cprintf(my_puts, "%s\n", "tst", 12345), ::cxxextras::cprintf_toomanyargs );
23         
24         printf("Bad Format\n");
25         ASSERT_EXCEPTION( ::cxxextras::cprintf(my_puts, "%-\n"), ::cxxextras::cprintf_badformat );
26         
27         return 0;
28 }
29

UCC git Repository :: git.ucc.asn.au