From 510a52deaed8e5ee6d2873dd21cada09ade70c50 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 2 Aug 2016 08:58:47 +0200 Subject: Test filebin_helper Signed-off-by: Florian Pritz --- application/test/tests/test_filebin_helper.php | 70 ++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 application/test/tests/test_filebin_helper.php (limited to 'application/test') diff --git a/application/test/tests/test_filebin_helper.php b/application/test/tests/test_filebin_helper.php new file mode 100644 index 000000000..edebb13ca --- /dev/null +++ b/application/test/tests/test_filebin_helper.php @@ -0,0 +1,70 @@ + + * + * Licensed under AGPLv3 + * (see COPYING for full license text) + * + */ + +namespace test\tests; + +class test_filebin_helper extends \test\Test { + + public function __construct() + { + parent::__construct(); + } + + public function init() + { + } + + public function cleanup() + { + } + + public function test_format_bytes() + { + $this->t->is(format_bytes(500), "500B", "500B"); + $this->t->is(format_bytes(1500), "1500B", "1500B"); + $this->t->is(format_bytes(1500*1024), "1500.00KiB", "1500.00KiB"); + $this->t->is(format_bytes(1500*1024*1024), "1500.00MiB", "1500.00MiB"); + $this->t->is(format_bytes(1500*1024*1024*1024), "1500.00GiB", "1500.00GiB"); + $this->t->is(format_bytes(1500*1024*1024*1024*1024), "1500.00TiB", "1500.00TiB"); + $this->t->is(format_bytes(1500*1024*1024*1024*1024*1024), "1500.00PiB", "1500.00PiB"); + } + + public function test_even_odd() + { + $this->t->is(even_odd(true), "odd", "odd after reset"); + $this->t->is(even_odd(), "even", "even"); + $this->t->is(even_odd(), "odd", "odd"); + $this->t->is(even_odd(true), "odd", "odd after reset"); + } + + public function test_mb_str_pad() + { + $this->t->is(mb_str_pad('test', 6), 'test ', 'Simple test with length=6'); + $this->t->is(mb_str_pad('絫ö', 6), '絫ö ', 'UTF8 test with length=6'); + } + + public function test_files_are_equal() + { + $a1 = FCPATH.'/data/tests/message1.bin'; + $a2 = FCPATH.'/data/tests/message2.bin'; + $b = FCPATH.'/data/tests/simple.pdf'; + $this->t->is(files_are_equal($a1, $a2), false, "Same hash, but different file"); + $this->t->is(files_are_equal($a1, $b), false, "Different filesize"); + $this->t->is(files_are_equal($a1, $a1), true, "Same file"); + $this->t->is(files_are_equal($a2, $a2), true, "Same file"); + } + + public function test_return_bytes() + { + $this->t->is(return_bytes("1k"), 1*1024, "1k"); + $this->t->is(return_bytes("1M"), 1*1024*1024, "1M"); + $this->t->is(return_bytes("1G"), 1*1024*1024*1024, "1G"); + $this->t->is(return_bytes("1P"), "1P", "unhandled text: 1P"); + } +} -- cgit v1.2.3-24-g4f1b