Usermode/c++extras - Cleanup of cprintf code
[tpg/acess2.git] / Usermode / Libraries / libc++_extras.so_src / TEST_cprintf.cpp
index 6c02bd2..c99d1a7 100644 (file)
@@ -2,15 +2,28 @@
  */
 #include <cxxextras_printf>
 #include <cstdio>
+#include <stdexcept>
+
+void my_puts(const char *str, size_t len)
+{
+       fwrite(str, 1, len, stdout);
+}
+
+#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)
 
 int main()
 {
-       ::cxxextras::cprintf(
-               [](const char *str, size_t len){printf("%.*s", (unsigned int)len, str); return len;},
-               "%s %i %+#-010x",
-               "hello_world",
-               1337,
-               0x1234565);
+       printf("Success\n");
+       ::cxxextras::cprintf(my_puts, "%s %i %+#-010x\n", "hello_world", 1337, 0x1234565);
+       
+       printf("Too Few\n");
+       ASSERT_EXCEPTION( ::cxxextras::cprintf(my_puts, "%s %i %+#-010x\n"), ::cxxextras::cprintf_toofewargs );
+       printf("Too Many\n");
+       ASSERT_EXCEPTION( ::cxxextras::cprintf(my_puts, "%s\n", "tst", 12345), ::cxxextras::cprintf_toomanyargs );
+       
+       printf("Bad Format\n");
+       ASSERT_EXCEPTION( ::cxxextras::cprintf(my_puts, "%-\n"), ::cxxextras::cprintf_badformat );
+       
        return 0;
 }
 

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