X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/f932cd7c75cd7b0da99c97064f8d112075ccd7f5..2a49601f69e08f06fb2727d869d420daacdd09d5:/test/libapt/getlanguages_test.cc diff --git a/test/libapt/getlanguages_test.cc b/test/libapt/getlanguages_test.cc index fd3c8269f..cef89bde6 100644 --- a/test/libapt/getlanguages_test.cc +++ b/test/libapt/getlanguages_test.cc @@ -7,85 +7,184 @@ #include -// simple helper to quickly output a vector of strings -void dumpVector(std::vector vec) { - for (std::vector::const_iterator v = vec.begin(); - v != vec.end(); v++) - std::cout << *v << std::endl; -} - int main(int argc,char *argv[]) { - std::vector vec = APT::Configuration::getLanguages(false, false, "de_DE.UTF-8"); - equals(vec.size(), 2); - equals(vec[0], "de"); - equals(vec[1], "en"); + if (argc != 2) { + std::cout << "One parameter expected - given " << argc << std::endl; + return 100; + } - // Special: Check if the cache is actually in use - vec = APT::Configuration::getLanguages(false, true, "en_GB.UTF-8"); - equals(vec.size(), 2); - equals(vec[0], "de"); - equals(vec[1], "en"); + char const* env[2]; + env[0] = "de_DE.UTF-8"; + env[1] = ""; - vec = APT::Configuration::getLanguages(false, false, "en_GB.UTF-8"); + std::vector vec = APT::Configuration::getLanguages(false, false, env); + equals(vec.size(), 3); + equals(vec[0], "de_DE"); + equals(vec[1], "de"); + equals(vec[2], "en"); + + // Special: Check if the cache is actually in use + env[0] = "en_GB.UTF-8"; + vec = APT::Configuration::getLanguages(false, true, env); + equals(vec.size(), 3); + equals(vec[0], "de_DE"); + equals(vec[1], "de"); + equals(vec[2], "en"); + + env[0] = "en_GB.UTF-8"; + vec = APT::Configuration::getLanguages(false, false, env); equals(vec.size(), 2); equals(vec[0], "en_GB"); equals(vec[1], "en"); - vec = APT::Configuration::getLanguages(false, false, "pt_PR.UTF-8"); + // esperanto + env[0] = "eo.UTF-8"; + vec = APT::Configuration::getLanguages(false, false, env); + equals(vec.size(), 2); + equals(vec[0], "eo"); + equals(vec[1], "en"); + + env[0] = "tr_DE@euro"; + vec = APT::Configuration::getLanguages(false, false, env); + equals(vec.size(), 3); + equals(vec[0], "tr_DE"); + equals(vec[1], "tr"); + equals(vec[2], "en"); + + env[0] = "de_NO"; + env[1] = "de_NO:en_GB:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en"; + vec = APT::Configuration::getLanguages(false, false, env); + equals(vec.size(), 6); + equals(vec[0], "de_NO"); + equals(vec[1], "de"); + equals(vec[2], "en_GB"); + equals(vec[3], "nb_NO"); + equals(vec[4], "nb"); + equals(vec[5], "en"); + + env[0] = "pt_PR.UTF-8"; + env[1] = ""; + vec = APT::Configuration::getLanguages(false, false, env); equals(vec.size(), 3); equals(vec[0], "pt_PR"); equals(vec[1], "pt"); equals(vec[2], "en"); - vec = APT::Configuration::getLanguages(false, false, "ast_DE.UTF-8"); // bogus, but syntactical correct - equals(vec.size(), 2); - equals(vec[0], "ast"); - equals(vec[1], "en"); + env[0] = "ast_DE.UTF-8"; + vec = APT::Configuration::getLanguages(false, false, env); // bogus, but syntactical correct + equals(vec.size(), 3); + equals(vec[0], "ast_DE"); + equals(vec[1], "ast"); + equals(vec[2], "en"); - vec = APT::Configuration::getLanguages(false, false, "C"); + env[0] = "C"; + vec = APT::Configuration::getLanguages(false, false, env); equals(vec.size(), 1); equals(vec[0], "en"); + _config->Set("Acquire::Languages", "none"); + env[0] = "C"; + vec = APT::Configuration::getLanguages(false, false, env); + equals(vec.size(), 0); + + _config->Set("Acquire::Languages", "environment"); + env[0] = "C"; + vec = APT::Configuration::getLanguages(false, false, env); + equals(vec.size(), 1); + equals(vec[0], "en"); + + _config->Set("Acquire::Languages", "de"); + env[0] = "C"; + vec = APT::Configuration::getLanguages(false, false, env); + equals(vec.size(), 1); + equals(vec[0], "de"); + + _config->Set("Acquire::Languages", "fr"); + env[0] = "ast_DE.UTF-8"; + vec = APT::Configuration::getLanguages(false, false, env); + equals(vec.size(), 1); + equals(vec[0], "fr"); + _config->Set("Acquire::Languages", ""); + _config->Set("Acquire::Languages::1", "environment"); _config->Set("Acquire::Languages::2", "en"); - vec = APT::Configuration::getLanguages(false, false, "de_DE.UTF-8"); - equals(vec.size(), 2); - equals(vec[0], "de"); - equals(vec[1], "en"); + env[0] = "de_DE.UTF-8"; + vec = APT::Configuration::getLanguages(false, false, env); + equals(vec.size(), 3); + equals(vec[0], "de_DE"); + equals(vec[1], "de"); + equals(vec[2], "en"); _config->Set("Acquire::Languages::3", "de"); - vec = APT::Configuration::getLanguages(false, false, "de_DE.UTF-8"); - equals(vec.size(), 2); - equals(vec[0], "de"); - equals(vec[1], "en"); + env[0] = "de_DE.UTF-8"; + vec = APT::Configuration::getLanguages(false, false, env); + equals(vec.size(), 3); + equals(vec[0], "de_DE"); + equals(vec[1], "de"); + equals(vec[2], "en"); + + _config->Set("Dir::State::lists", argv[1]); + vec = APT::Configuration::getLanguages(true, false, env); + equals(vec.size(), 8); + equals(vec[0], "de_DE"); + equals(vec[1], "de"); + equals(vec[2], "en"); + equals(vec[3], "none"); + equalsOr4(vec[4], "pt", "tr", "ast_DE", "tlh_DE"); + equalsOr4(vec[5], "tr", "pt", "ast_DE", "tlh_DE"); + equalsOr4(vec[6], "tr", "pt", "ast_DE", "tlh_DE"); + equalsOr4(vec[7], "tr", "pt", "ast_DE", "tlh_DE"); + equalsNot(vec[4], vec[5]); + equalsNot(vec[4], vec[6]); + equalsNot(vec[4], vec[7]); + equalsNot(vec[5], vec[6]); + equalsNot(vec[5], vec[7]); + equalsNot(vec[6], vec[7]); + + _config->Set("Acquire::Languages", "none"); + vec = APT::Configuration::getLanguages(true, false, env); + equals(vec.size(), 1); + equals(vec[0], "none"); + _config->Set("Acquire::Languages", ""); + _config->Set("Dir::State::lists", "/non-existing-dir"); _config->Set("Acquire::Languages::1", "none"); - vec = APT::Configuration::getLanguages(false, false, "de_DE.UTF-8"); + env[0] = "de_DE.UTF-8"; + vec = APT::Configuration::getLanguages(false, false, env); equals(vec.size(), 0); - vec = APT::Configuration::getLanguages(true, false, "de_DE.UTF-8"); + env[0] = "de_DE.UTF-8"; + vec = APT::Configuration::getLanguages(true, false, env); + equals(vec.size(), 2); equals(vec[0], "en"); equals(vec[1], "de"); _config->Set("Acquire::Languages::1", "fr"); _config->Set("Acquire::Languages", "de_DE"); - vec = APT::Configuration::getLanguages(false, false, "de_DE.UTF-8"); + env[0] = "de_DE.UTF-8"; + vec = APT::Configuration::getLanguages(false, false, env); equals(vec.size(), 1); equals(vec[0], "de_DE"); _config->Set("Acquire::Languages", "none"); - vec = APT::Configuration::getLanguages(true, false, "de_DE.UTF-8"); - equals(vec.size(), 0); + env[0] = "de_DE.UTF-8"; + vec = APT::Configuration::getLanguages(true, false, env); + equals(vec.size(), 1); + equals(vec[0], "none"); _config->Set("Acquire::Languages", ""); //FIXME: Remove support for this deprecated setting _config->Set("APT::Acquire::Translation", "ast_DE"); - vec = APT::Configuration::getLanguages(true, false, "de_DE.UTF-8"); - equals(vec.size(), 1); + env[0] = "de_DE.UTF-8"; + vec = APT::Configuration::getLanguages(true, false, env); + equals(vec.size(), 2); equals(vec[0], "ast_DE"); + equals(vec[1], "en"); _config->Set("APT::Acquire::Translation", "none"); - vec = APT::Configuration::getLanguages(true, false, "de_DE.UTF-8"); - equals(vec.size(), 0); + env[0] = "de_DE.UTF-8"; + vec = APT::Configuration::getLanguages(true, false, env); + equals(vec.size(), 1); + equals(vec[0], "en"); return 0; }