Commit 63fd354ec037f2fa886b7053c75e3363fa8e2881
1 parent
54052aa6
Add registry and GModels unit tests.
Showing
2 changed files
with
216 additions
and
10 deletions
test/test_GModel.cpp
| ... | ... | @@ -68,13 +68,13 @@ void TestGModel::set(void) |
| 68 | 68 | |
| 69 | 69 | // Add spatial model tests |
| 70 | 70 | add_test(static_cast<pfunction>(&TestGModel::test_point_source), "Test GModelSpatialPointSource"); |
| 71 | - add_test(static_cast<pfunction>(&TestGModel::test_diffuse_const), "Test GModelSpatialDiffuseConst"); | |
| 72 | - add_test(static_cast<pfunction>(&TestGModel::test_diffuse_cube), "Test GModelSpatialDiffuseCube"); | |
| 73 | - add_test(static_cast<pfunction>(&TestGModel::test_diffuse_map), "Test GModelSpatialDiffuseMap"); | |
| 74 | 71 | add_test(static_cast<pfunction>(&TestGModel::test_radial_disk), "Test GModelSpatialRadialDisk"); |
| 75 | 72 | add_test(static_cast<pfunction>(&TestGModel::test_radial_gauss), "Test GModelSpatialRadialGauss"); |
| 76 | 73 | add_test(static_cast<pfunction>(&TestGModel::test_radial_shell), "Test GModelSpatialRadialShell"); |
| 77 | 74 | add_test(static_cast<pfunction>(&TestGModel::test_elliptical_disk), "Test GModelSpatialEllipticalDisk"); |
| 75 | + add_test(static_cast<pfunction>(&TestGModel::test_diffuse_const), "Test GModelSpatialDiffuseConst"); | |
| 76 | + add_test(static_cast<pfunction>(&TestGModel::test_diffuse_cube), "Test GModelSpatialDiffuseCube"); | |
| 77 | + add_test(static_cast<pfunction>(&TestGModel::test_diffuse_map), "Test GModelSpatialDiffuseMap"); | |
| 78 | 78 | add_test(static_cast<pfunction>(&TestGModel::test_spatial_model), "Test spatial model XML I/O"); |
| 79 | 79 | |
| 80 | 80 | // Add spatial model tests |
| ... | ... | @@ -93,6 +93,9 @@ void TestGModel::set(void) |
| 93 | 93 | // Add model container tests |
| 94 | 94 | add_test(static_cast<pfunction>(&TestGModel::test_models), "Test GModels"); |
| 95 | 95 | |
| 96 | + // Add model registry tests | |
| 97 | + add_test(static_cast<pfunction>(&TestGModel::test_model_registry), "Test model registries"); | |
| 98 | + | |
| 96 | 99 | // Return |
| 97 | 100 | return; |
| 98 | 101 | } |
| ... | ... | @@ -1772,13 +1775,14 @@ void TestGModel::test_xml_model(const std::string& name, |
| 1772 | 1775 | void TestGModel::test_spatial_model(void) |
| 1773 | 1776 | { |
| 1774 | 1777 | // Test spatial models XML interface |
| 1775 | - test_xml_model("GModelSpatialDiffuseConst", m_xml_model_diffuse_const); | |
| 1776 | - test_xml_model("GModelSpatialDiffuseCube", m_xml_model_diffuse_cube); | |
| 1777 | - test_xml_model("GModelSpatialDiffuseMap", m_xml_model_diffuse_map); | |
| 1778 | + test_xml_model("GModelSpatialPointSource", m_xml_model_point_plaw); | |
| 1778 | 1779 | test_xml_model("GModelSpatialRadialDisk", m_xml_model_radial_disk); |
| 1779 | 1780 | test_xml_model("GModelSpatialRadialGauss", m_xml_model_radial_gauss); |
| 1780 | 1781 | test_xml_model("GModelSpatialRadialShell", m_xml_model_radial_shell); |
| 1781 | 1782 | test_xml_model("GModelSpatialEllipticalDisk", m_xml_model_elliptical_disk); |
| 1783 | + test_xml_model("GModelSpatialDiffuseConst", m_xml_model_diffuse_const); | |
| 1784 | + test_xml_model("GModelSpatialDiffuseCube", m_xml_model_diffuse_cube); | |
| 1785 | + test_xml_model("GModelSpatialDiffuseMap", m_xml_model_diffuse_map); | |
| 1782 | 1786 | |
| 1783 | 1787 | // Return |
| 1784 | 1788 | return; |
| ... | ... | @@ -1791,10 +1795,13 @@ void TestGModel::test_spatial_model(void) |
| 1791 | 1795 | void TestGModel::test_spectral_model(void) |
| 1792 | 1796 | { |
| 1793 | 1797 | // Test spectral models XML interface |
| 1794 | - test_xml_model("GModelSpectralPlaw", m_xml_model_point_plaw); | |
| 1795 | - test_xml_model("GModelSpectralPlaw2", m_xml_model_point_plaw2); | |
| 1796 | - test_xml_model("GModelSpectralExpPaw", m_xml_model_point_eplaw); | |
| 1797 | - test_xml_model("GModelSpectralNodes", m_xml_model_point_nodes); | |
| 1798 | + test_xml_model("GModelSpectralConst", m_xml_model_point_const); | |
| 1799 | + test_xml_model("GModelSpectralPlaw", m_xml_model_point_plaw); | |
| 1800 | + test_xml_model("GModelSpectralPlaw2", m_xml_model_point_plaw2); | |
| 1801 | + test_xml_model("GModelSpectralExpPaw", m_xml_model_point_eplaw); | |
| 1802 | + test_xml_model("GModelSpectralLogParabola", m_xml_model_point_logparabola); | |
| 1803 | + test_xml_model("GModelSpectralNodes", m_xml_model_point_nodes); | |
| 1804 | + test_xml_model("GModelSpectralFunc", m_xml_model_point_filefct); | |
| 1798 | 1805 | |
| 1799 | 1806 | // Return |
| 1800 | 1807 | return; |
| ... | ... | @@ -1810,6 +1817,8 @@ void TestGModel::test_models(void) |
| 1810 | 1817 | test_try("Test void constructor"); |
| 1811 | 1818 | try { |
| 1812 | 1819 | GModels models; |
| 1820 | + test_assert(models.isempty(), "Model container not empty."); | |
| 1821 | + test_value(models.size(), 0); | |
| 1813 | 1822 | test_try_success(); |
| 1814 | 1823 | } |
| 1815 | 1824 | catch (std::exception &e) { |
| ... | ... | @@ -1834,12 +1843,48 @@ void TestGModel::test_models(void) |
| 1834 | 1843 | models.load("test.xml"); |
| 1835 | 1844 | models.save("test.xml"); |
| 1836 | 1845 | models.load("test.xml"); |
| 1846 | + test_try_success(); | |
| 1847 | + } | |
| 1848 | + catch (std::exception &e) { | |
| 1849 | + test_try_failure(e); | |
| 1850 | + } | |
| 1837 | 1851 | |
| 1852 | + // Test model manipulation | |
| 1853 | + test_try("Test model access"); | |
| 1854 | + try { | |
| 1855 | + GModels models(m_xml_file); | |
| 1856 | + models.reserve(5); | |
| 1857 | + test_assert(models.hasmodel("1FGL J0005.7+3815"), | |
| 1858 | + "Model \"1FGL J0005.7+3815\" not found."); | |
| 1859 | + test_assert(!models.hasmodel("2FGL J0005.7+3815"), | |
| 1860 | + "Model \"2FGL J0005.7+3815\" found but not expected."); | |
| 1861 | + test_assert(!models.isempty(), "Model container is empty."); | |
| 1862 | + test_value(models.size(), 1); | |
| 1863 | + models.append(*(models[0])); | |
| 1864 | + models.insert(0, *(models.at(0))); | |
| 1865 | + test_assert(!models.isempty(), "Model container is empty."); | |
| 1866 | + test_value(models.size(), 3); | |
| 1867 | + models.remove(0); | |
| 1868 | + test_assert(!models.isempty(), "Model container is empty."); | |
| 1869 | + test_value(models.size(), 2); | |
| 1870 | + models.remove(0); | |
| 1871 | + test_assert(!models.isempty(), "Model container is empty."); | |
| 1872 | + test_value(models.size(), 1); | |
| 1873 | + models.remove("1FGL J0005.7+3815"); | |
| 1874 | + test_assert(models.isempty(), "Model container is not empty."); | |
| 1875 | + test_value(models.size(), 0); | |
| 1876 | + models.load(m_xml_file); | |
| 1877 | + test_assert(!models.isempty(), "Model container is empty."); | |
| 1878 | + test_value(models.size(), 1); | |
| 1879 | + models.extend(models); | |
| 1880 | + test_assert(!models.isempty(), "Model container is empty."); | |
| 1881 | + test_value(models.size(), 2); | |
| 1838 | 1882 | test_try_success(); |
| 1839 | 1883 | } |
| 1840 | 1884 | catch (std::exception &e) { |
| 1841 | 1885 | test_try_failure(e); |
| 1842 | 1886 | } |
| 1887 | + | |
| 1843 | 1888 | |
| 1844 | 1889 | // Setup Crab model |
| 1845 | 1890 | GModelSky crab; |
| ... | ... | @@ -1862,6 +1907,7 @@ void TestGModel::test_models(void) |
| 1862 | 1907 | models.append(crab); |
| 1863 | 1908 | models.append(crab); |
| 1864 | 1909 | models.append(crab); |
| 1910 | + test_value(models.size(), 3); | |
| 1865 | 1911 | test_try_success(); |
| 1866 | 1912 | } |
| 1867 | 1913 | catch (std::exception &e) { |
| ... | ... | @@ -1896,6 +1942,165 @@ void TestGModel::test_models(void) |
| 1896 | 1942 | |
| 1897 | 1943 | |
| 1898 | 1944 | /***********************************************************************//** |
| 1945 | + * @brief Test model registry | |
| 1946 | + ***************************************************************************/ | |
| 1947 | +void TestGModel::test_model_registry(void) | |
| 1948 | +{ | |
| 1949 | + // Test GModelRegistry void constructor | |
| 1950 | + test_try("Test GModelRegistry void constructor"); | |
| 1951 | + try { | |
| 1952 | + GModelRegistry registry; | |
| 1953 | + test_try_success(); | |
| 1954 | + } | |
| 1955 | + catch (std::exception &e) { | |
| 1956 | + test_try_failure(e); | |
| 1957 | + } | |
| 1958 | + | |
| 1959 | + // Test GModelRegistry allocators | |
| 1960 | + test_try("Test GModelRegistry model allocation"); | |
| 1961 | + try { | |
| 1962 | + // Loop over all models in registry | |
| 1963 | + GModelRegistry registry; | |
| 1964 | + int num = registry.size(); | |
| 1965 | + for (int i = 0; i < num; ++i) { | |
| 1966 | + GModel* ptr = registry.alloc(registry.name(i)); | |
| 1967 | + test_assert(ptr != NULL, "Model pointer for \""+ \ | |
| 1968 | + registry.name(i)+"\" is NULL"); | |
| 1969 | + if (ptr != NULL) { | |
| 1970 | + | |
| 1971 | + // Test model type | |
| 1972 | + test_assert(ptr->type() == registry.name(i), | |
| 1973 | + "Expected \""+registry.name(i)+"\" instead" | |
| 1974 | + " of \""+ptr->type()+"\"."); | |
| 1975 | + | |
| 1976 | + // Free model | |
| 1977 | + delete ptr; | |
| 1978 | + } | |
| 1979 | + } // endfor: looped over all models | |
| 1980 | + test_try_success(); | |
| 1981 | + } | |
| 1982 | + catch (std::exception &e) { | |
| 1983 | + test_try_failure(e); | |
| 1984 | + } | |
| 1985 | + | |
| 1986 | + // Test GModelSpatialRegistry void constructor | |
| 1987 | + test_try("Test GModelSpatialRegistry void constructor"); | |
| 1988 | + try { | |
| 1989 | + GModelSpatialRegistry registry; | |
| 1990 | + test_try_success(); | |
| 1991 | + } | |
| 1992 | + catch (std::exception &e) { | |
| 1993 | + test_try_failure(e); | |
| 1994 | + } | |
| 1995 | + | |
| 1996 | + // Test GModelSpatialRegistry allocators | |
| 1997 | + test_try("Test GModelSpatialRegistry model allocation"); | |
| 1998 | + try { | |
| 1999 | + // Loop over all models in registry | |
| 2000 | + GModelSpatialRegistry registry; | |
| 2001 | + int num = registry.size(); | |
| 2002 | + for (int i = 0; i < num; ++i) { | |
| 2003 | + GModelSpatial* ptr = registry.alloc(registry.name(i)); | |
| 2004 | + test_assert(ptr != NULL, "Model pointer for \""+ \ | |
| 2005 | + registry.name(i)+"\" is NULL"); | |
| 2006 | + if (ptr != NULL) { | |
| 2007 | + | |
| 2008 | + // Test model type | |
| 2009 | + test_assert(ptr->type() == registry.name(i), | |
| 2010 | + "Expected \""+registry.name(i)+"\" instead" | |
| 2011 | + " of \""+ptr->type()+"\"."); | |
| 2012 | + | |
| 2013 | + // Free model | |
| 2014 | + delete ptr; | |
| 2015 | + } | |
| 2016 | + } // endfor: looped over all models | |
| 2017 | + test_try_success(); | |
| 2018 | + } | |
| 2019 | + catch (std::exception &e) { | |
| 2020 | + test_try_failure(e); | |
| 2021 | + } | |
| 2022 | + | |
| 2023 | + // Test GModelSpectralRegistry void constructor | |
| 2024 | + test_try("Test GModelSpectralRegistry void constructor"); | |
| 2025 | + try { | |
| 2026 | + GModelSpectralRegistry registry; | |
| 2027 | + test_try_success(); | |
| 2028 | + } | |
| 2029 | + catch (std::exception &e) { | |
| 2030 | + test_try_failure(e); | |
| 2031 | + } | |
| 2032 | + | |
| 2033 | + // Test GModelSpectralRegistry allocators | |
| 2034 | + test_try("Test GModelSpectralRegistry model allocation"); | |
| 2035 | + try { | |
| 2036 | + // Loop over all models in registry | |
| 2037 | + GModelSpectralRegistry registry; | |
| 2038 | + int num = registry.size(); | |
| 2039 | + for (int i = 0; i < num; ++i) { | |
| 2040 | + GModelSpectral* ptr = registry.alloc(registry.name(i)); | |
| 2041 | + test_assert(ptr != NULL, "Model pointer for \""+ \ | |
| 2042 | + registry.name(i)+"\" is NULL"); | |
| 2043 | + if (ptr != NULL) { | |
| 2044 | + | |
| 2045 | + // Test model type | |
| 2046 | + test_assert(ptr->type() == registry.name(i), | |
| 2047 | + "Expected \""+registry.name(i)+"\" instead" | |
| 2048 | + " of \""+ptr->type()+"\"."); | |
| 2049 | + | |
| 2050 | + // Free model | |
| 2051 | + delete ptr; | |
| 2052 | + } | |
| 2053 | + } // endfor: looped over all models | |
| 2054 | + test_try_success(); | |
| 2055 | + } | |
| 2056 | + catch (std::exception &e) { | |
| 2057 | + test_try_failure(e); | |
| 2058 | + } | |
| 2059 | + | |
| 2060 | + // Test GModelTemporalRegistry void constructor | |
| 2061 | + test_try("Test GModelTemporalRegistry void constructor"); | |
| 2062 | + try { | |
| 2063 | + GModelTemporalRegistry registry; | |
| 2064 | + test_try_success(); | |
| 2065 | + } | |
| 2066 | + catch (std::exception &e) { | |
| 2067 | + test_try_failure(e); | |
| 2068 | + } | |
| 2069 | + | |
| 2070 | + // Test GModelTemporalRegistry allocators | |
| 2071 | + test_try("Test GModelTemporalRegistry model allocation"); | |
| 2072 | + try { | |
| 2073 | + // Loop over all models in registry | |
| 2074 | + GModelTemporalRegistry registry; | |
| 2075 | + int num = registry.size(); | |
| 2076 | + for (int i = 0; i < num; ++i) { | |
| 2077 | + GModelTemporal* ptr = registry.alloc(registry.name(i)); | |
| 2078 | + test_assert(ptr != NULL, "Model pointer for \""+ \ | |
| 2079 | + registry.name(i)+"\" is NULL"); | |
| 2080 | + if (ptr != NULL) { | |
| 2081 | + | |
| 2082 | + // Test model type | |
| 2083 | + test_assert(ptr->type() == registry.name(i), | |
| 2084 | + "Expected \""+registry.name(i)+"\" instead" | |
| 2085 | + " of \""+ptr->type()+"\"."); | |
| 2086 | + | |
| 2087 | + // Free model | |
| 2088 | + delete ptr; | |
| 2089 | + } | |
| 2090 | + } // endfor: looped over all models | |
| 2091 | + test_try_success(); | |
| 2092 | + } | |
| 2093 | + catch (std::exception &e) { | |
| 2094 | + test_try_failure(e); | |
| 2095 | + } | |
| 2096 | + | |
| 2097 | + // Exit test | |
| 2098 | + return; | |
| 2099 | + | |
| 2100 | +} | |
| 2101 | + | |
| 2102 | + | |
| 2103 | +/***********************************************************************//** | |
| 1899 | 2104 | * @brief Main test function. |
| 1900 | 2105 | ***************************************************************************/ |
| 1901 | 2106 | int main(void) | ... | ... |