summaryrefslogtreecommitdiff
path: root/src/tests/eina/eina_test_value.c
diff options
context:
space:
mode:
authorkabeer khan <kabeer.khan@samsung.com>2014-10-23 08:34:14 -0400
committerChris Michael <cp.michael@samsung.com>2014-10-23 08:34:14 -0400
commit5289a4375d9eb71ca4297bd6e4e8083108c6e870 (patch)
treecf2a4bf80c6efbc7c37de02e162b8994552469dc /src/tests/eina/eina_test_value.c
parent0446fd2d7fbacc71bbb41dec93c345ed1c3181d0 (diff)
Eina Test : Added test case for convert float in eina_test_value
Summary: Signed-off-by: kabeer khan <kabeer.khan@samsung.com> Reviewers: cedric, devilhorns Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D1567
Diffstat (limited to 'src/tests/eina/eina_test_value.c')
-rw-r--r--src/tests/eina/eina_test_value.c177
1 files changed, 177 insertions, 0 deletions
diff --git a/src/tests/eina/eina_test_value.c b/src/tests/eina/eina_test_value.c
index a7d253179b..6f9d147a2d 100644
--- a/src/tests/eina/eina_test_value.c
+++ b/src/tests/eina/eina_test_value.c
@@ -22,6 +22,7 @@
22 22
23#include <stdio.h> 23#include <stdio.h>
24#include <inttypes.h> 24#include <inttypes.h>
25#include <float.h>
25 26
26#include "eina_suite.h" 27#include "eina_suite.h"
27#include "Eina.h" 28#include "Eina.h"
@@ -1777,6 +1778,181 @@ START_TEST(eina_value_test_convert_ulong)
1777} 1778}
1778END_TEST 1779END_TEST
1779 1780
1781START_TEST(eina_value_test_convert_float)
1782{
1783 Eina_Value *value, conv;
1784 char c;
1785 short s;
1786 int i;
1787 long l;
1788 int64_t i64;
1789 unsigned char uc;
1790 unsigned short us;
1791 unsigned int ui;
1792 unsigned long ul;
1793 uint64_t u64;
1794 float f;
1795 double d;
1796 const char *str;
1797
1798 float max_float_value = FLT_MAX;
1799 float min_float_value = FLT_MIN;
1800
1801 eina_init();
1802
1803 value = eina_value_new(EINA_VALUE_TYPE_FLOAT);
1804 fail_unless(value != NULL);
1805
1806 fail_unless(eina_value_set(value, 42.354645));
1807
1808 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1809 fail_unless(eina_value_convert(value, &conv));
1810 fail_unless(eina_value_get(&conv, &uc));
1811 fail_unless(uc == 42);
1812 eina_value_flush(&conv);
1813
1814 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1815 fail_unless(eina_value_convert(value, &conv));
1816 fail_unless(eina_value_get(&conv, &us));
1817 fail_unless(us == 42);
1818 eina_value_flush(&conv);
1819
1820 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
1821 fail_unless(eina_value_convert(value, &conv));
1822 fail_unless(eina_value_get(&conv, &ui));
1823 fail_unless(ui == 42);
1824 eina_value_flush(&conv);
1825
1826 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
1827 fail_unless(eina_value_convert(value, &conv));
1828 fail_unless(eina_value_get(&conv, &ul));
1829 fail_unless(ul == 42ul);
1830 eina_value_flush(&conv);
1831
1832 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
1833 fail_unless(eina_value_convert(value, &conv));
1834 fail_unless(eina_value_get(&conv, &u64));
1835 fail_unless(ul == 42ull);
1836 eina_value_flush(&conv);
1837
1838 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
1839 fail_unless(eina_value_convert(value, &conv));
1840 fail_unless(eina_value_get(&conv, &c));
1841 fail_unless(c == 42);
1842 eina_value_flush(&conv);
1843
1844 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
1845 fail_unless(eina_value_convert(value, &conv));
1846 fail_unless(eina_value_get(&conv, &s));
1847 fail_unless(s == 42);
1848 eina_value_flush(&conv);
1849
1850 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
1851 fail_unless(eina_value_convert(value, &conv));
1852 fail_unless(eina_value_get(&conv, &i));
1853 fail_unless(i == 42);
1854 eina_value_flush(&conv);
1855
1856 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
1857 fail_unless(eina_value_convert(value, &conv));
1858 fail_unless(eina_value_get(&conv, &l));
1859 fail_unless(l == 42l);
1860 eina_value_flush(&conv);
1861
1862 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
1863 fail_unless(eina_value_convert(value, &conv));
1864 fail_unless(eina_value_get(&conv, &i64));
1865 fail_unless(i64 == 42ll);
1866 eina_value_flush(&conv);
1867
1868 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
1869 fail_unless(eina_value_convert(value, &conv));
1870 fail_unless(eina_value_get(&conv, &f));
1871 fail_unless(CHECK_FP(f, max_float_value));
1872 eina_value_flush(&conv);
1873
1874 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
1875 fail_unless(eina_value_convert(value, &conv));
1876 fail_unless(eina_value_get(&conv, &d));
1877 fail_unless(CHECK_FP(d, max_float_value));
1878 eina_value_flush(&conv);
1879
1880 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
1881 fail_unless(eina_value_convert(value, &conv));
1882 fail_unless(eina_value_get(&conv, &str));
1883 fail_unless(str != NULL);
1884 ck_assert_str_eq(str, "42.354645");
1885 eina_value_flush(&conv);
1886
1887 fail_unless(eina_value_set(value, max_float_value));
1888
1889 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
1890 fail_unless(eina_value_convert(value, &conv));
1891 fail_unless(eina_value_get(&conv, &f));
1892 fail_unless(CHECK_FP(f, max_float_value));
1893 eina_value_flush(&conv);
1894
1895 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
1896 fail_unless(eina_value_convert(value, &conv));
1897 fail_unless(eina_value_get(&conv, &d));
1898 fail_unless(CHECK_FP(d, max_float_value));
1899 eina_value_flush(&conv);
1900
1901 fail_unless(eina_value_set(value, min_float_value));
1902
1903 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
1904 fail_unless(eina_value_convert(value, &conv));
1905 fail_unless(eina_value_get(&conv, &f));
1906 fail_unless(CHECK_FP(f, min_float_value));
1907 eina_value_flush(&conv);
1908
1909 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
1910 fail_unless(eina_value_convert(value, &conv));
1911 fail_unless(eina_value_get(&conv, &d));
1912 fail_unless(CHECK_FP(d, min_float_value));
1913 eina_value_flush(&conv);
1914
1915 fail_unless(eina_value_set(value, -max_float_value));
1916
1917 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
1918 fail_unless(eina_value_convert(value, &conv));
1919 fail_unless(eina_value_get(&conv, &f));
1920 fail_unless(CHECK_FP(f, -max_float_value));
1921 eina_value_flush(&conv);
1922
1923 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
1924 fail_unless(eina_value_convert(value, &conv));
1925 fail_unless(eina_value_get(&conv, &d));
1926 fail_unless(CHECK_FP(d, -max_float_value));
1927 eina_value_flush(&conv);
1928
1929 /* negative tests */
1930 fail_unless(eina_value_set(value, -max_float_value));
1931 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
1932 fail_if(eina_value_convert(value, &conv));
1933 eina_value_flush(&conv);
1934
1935 fail_unless(eina_value_set(value, -max_float_value));
1936 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
1937 fail_if(eina_value_convert(value, &conv));
1938 eina_value_flush(&conv);
1939
1940 fail_unless(eina_value_set(value, -max_float_value));
1941 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
1942 fail_if(eina_value_convert(value, &conv));
1943 eina_value_flush(&conv);
1944
1945 fail_unless(eina_value_set(value, -max_float_value));
1946 fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
1947 fail_if(eina_value_convert(value, &conv));
1948 eina_value_flush(&conv);
1949
1950 eina_value_free(value);
1951 eina_shutdown();
1952
1953}
1954END_TEST
1955
1780START_TEST(eina_value_test_array) 1956START_TEST(eina_value_test_array)
1781{ 1957{
1782 Eina_Value *value, other; 1958 Eina_Value *value, other;
@@ -2612,6 +2788,7 @@ eina_test_value(TCase *tc)
2612 tcase_add_test(tc, eina_value_test_convert_uint); 2788 tcase_add_test(tc, eina_value_test_convert_uint);
2613 tcase_add_test(tc, eina_value_test_convert_long); 2789 tcase_add_test(tc, eina_value_test_convert_long);
2614 tcase_add_test(tc, eina_value_test_convert_ulong); 2790 tcase_add_test(tc, eina_value_test_convert_ulong);
2791 tcase_add_test(tc, eina_value_test_convert_float);
2615 // TODO: other converters... 2792 // TODO: other converters...
2616 tcase_add_test(tc, eina_value_test_array); 2793 tcase_add_test(tc, eina_value_test_array);
2617 tcase_add_test(tc, eina_value_test_list); 2794 tcase_add_test(tc, eina_value_test_list);