summaryrefslogtreecommitdiffstats
path: root/test/format.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:13:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:13:14 +0000
commit60e8a3d404f0640fa5a3f834eae54b4f1fb9127d (patch)
tree1da89a218d0ecf010c67a87cb2f625c4cb18e7d7 /test/format.c
parentAdding upstream version 0.37.0. (diff)
downloadmpv-60e8a3d404f0640fa5a3f834eae54b4f1fb9127d.tar.xz
mpv-60e8a3d404f0640fa5a3f834eae54b4f1fb9127d.zip
Adding upstream version 0.38.0.upstream/0.38.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/format.c')
-rw-r--r--test/format.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/test/format.c b/test/format.c
new file mode 100644
index 0000000..8033d1b
--- /dev/null
+++ b/test/format.c
@@ -0,0 +1,99 @@
+#include "test_utils.h"
+#include "common/common.h"
+
+int main(void)
+{
+ void *ta_ctx = talloc_new(NULL);
+
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, false, false, false), "123");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, false, false, true), "123");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, false, true, false), "123%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, false, true, true), "123%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, true, false, false), "+123");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, true, false, true), "+123");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, true, true, false), "+123%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 0, true, true, true), "+123%");
+
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, false, false), "-123");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, false, true), "-123");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, true, false), "-123%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, true, true), "-123%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true, false, false), "-123");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true, false, true), "-123");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true, true, false), "-123%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true, true, true), "-123%");
+
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, false, false, false), "123.46");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, false, false, true), "123.46");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, false, true, false), "123.46%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, false, true, true), "123.46%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, true, false, false), "+123.46");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, true, false, true), "+123.46");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, true, true, false), "+123.46%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 2, true, true, true), "+123.46%");
+
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, false, false), "-123.46");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, false, true), "-123.46");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, true, false), "-123.46%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, true, true), "-123.46%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true, false, false), "-123.46");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true, false, true), "-123.46");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true, true, false), "-123.46%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true, true, true), "-123.46%");
+
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, false, false, false), "123.456000");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, false, false, true), "123.456");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, false, true, false), "123.456000%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, false, true, true), "123.456%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, true, false, false), "+123.456000");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, true, false, true), "+123.456");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, true, true, false), "+123.456000%");
+ assert_string_equal(mp_format_double(ta_ctx, 123.456, 6, true, true, true), "+123.456%");
+
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, false, false), "-123.456000");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, false, true), "-123.456");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, true, false), "-123.456000%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, true, true), "-123.456%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true, false, false), "-123.456000");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true, false, true), "-123.456");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true, true, false), "-123.456000%");
+ assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true, true, true), "-123.456%");
+
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, false, false, false), "123.000000");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, false, false, true), "123");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, false, true, false), "123.000000%");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, false, true, true), "123%");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, true, false, false), "+123.000000");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, true, false, true), "+123");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, true, true, false), "+123.000000%");
+ assert_string_equal(mp_format_double(ta_ctx, 123, 6, true, true, true), "+123%");
+
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, false, false), "-123.000000");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, false, true), "-123");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, true, false), "-123.000000%");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, true, true), "-123%");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, true, false, false), "-123.000000");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, true, false, true), "-123");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, true, true, false), "-123.000000%");
+ assert_string_equal(mp_format_double(ta_ctx, -123, 6, true, true, true), "-123%");
+
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, false, false, false), "inf");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, false, false, true), "inf");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, false, true, false), "inf%");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, false, true, true), "inf%");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, true, false, false), "+inf");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, true, false, true), "+inf");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, true, true, false), "+inf%");
+ assert_string_equal(mp_format_double(ta_ctx, INFINITY, 6, true, true, true), "+inf%");
+
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, false, false), "-inf");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, false, true), "-inf");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, true, false), "-inf%");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, true, true), "-inf%");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true, false, false), "-inf");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true, false, true), "-inf");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true, true, false), "-inf%");
+ assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true, true, true), "-inf%");
+
+ talloc_free(ta_ctx);
+}