X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=tests%2Fstrutil.c;h=e2a0a20a86e3444007aeb2e5c310671c26900546;hb=bc294eaca829f7681c6d3a371a816e871aa9c4b8;hp=abc3e897c907bb733de60e5749be008145e7012f;hpb=d8df3c2a01883d0380561158ab4a34e172f4f2c4;p=libsigrok.git diff --git a/tests/strutil.c b/tests/strutil.c index abc3e897..e2a0a20a 100644 --- a/tests/strutil.c +++ b/tests/strutil.c @@ -65,6 +65,30 @@ static void test_sr_vsnprintf_ascii(const char *expected, char *format, ...) g_free(s); } +static void test_sr_vsprintf_ascii(const char *expected, char *format, ...) +{ + va_list args, args_copy; + char *s; + int len; + + /* Get length of buffer required. */ + va_start(args, format); + va_copy(args_copy, args); + len = sr_vsnprintf_ascii(NULL, 0, format, args); + va_end(args); + + /* Allocate buffer and write out command. */ + s = g_malloc0(len + 1); + len = sr_vsprintf_ascii(s, format, args_copy); + va_end(args_copy); + + fail_unless(s != NULL, + "Invalid result for '%s': len = %i.", expected, len); + fail_unless(!strcmp(s, expected), + "Invalid result for '%s': %s.", expected, s); + g_free(s); +} + static void test_samplerate(uint64_t samplerate, const char *expected) { char *s; @@ -146,6 +170,13 @@ START_TEST(test_locale) test_sr_vsnprintf_ascii("0.12345", "%.5f", (double)0.12345); test_sr_vsnprintf_ascii("0.123456", "%.6f", (double)0.123456); + test_sr_vsprintf_ascii("0.1", "%.1f", (double)0.1); + test_sr_vsprintf_ascii("0.12", "%.2f", (double)0.12); + test_sr_vsprintf_ascii("0.123", "%.3f", (double)0.123); + test_sr_vsprintf_ascii("0.1234", "%.4f", (double)0.1234); + test_sr_vsprintf_ascii("0.12345", "%.5f", (double)0.12345); + test_sr_vsprintf_ascii("0.123456", "%.6f", (double)0.123456); + #if 0 /* * These tests can be used to tell on which platforms the printf()