summaryrefslogtreecommitdiff
path: root/test/libapt/getlanguages_test.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2014-04-25 13:51:50 +0200
committerMichael Vogt <mvo@debian.org>2014-04-25 13:51:50 +0200
commit15ccc2a685b0b884b393e356f9960e86f97f532d (patch)
tree920a1fcf6fa2c92a05d0d1d2ccb22eb32b88522e /test/libapt/getlanguages_test.cc
parenta40c6649b99814c7d30964accdd5ecc4f1ce369a (diff)
parent506ab3c78fb67f5e452a1748f4870af767de5ebb (diff)
Merge branch 'debian/sid' into ubuntu/master
Conflicts: debian/changelog
Diffstat (limited to 'test/libapt/getlanguages_test.cc')
-rw-r--r--test/libapt/getlanguages_test.cc412
1 files changed, 223 insertions, 189 deletions
diff --git a/test/libapt/getlanguages_test.cc b/test/libapt/getlanguages_test.cc
index 15aa4e879..c50ff6ff8 100644
--- a/test/libapt/getlanguages_test.cc
+++ b/test/libapt/getlanguages_test.cc
@@ -2,199 +2,233 @@
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/fileutl.h>
-#include "assert.h"
+#include <algorithm>
+#include <iostream>
#include <string>
#include <vector>
-#include <iostream>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <gtest/gtest.h>
+
+#include "file-helpers.h"
+
+TEST(LanguagesTest,Environment)
+{
+ _config->Clear();
+
+ char const* env[2];
+ env[0] = "de_DE.UTF-8";
+ env[1] = "";
+
+ std::vector<std::string> vec = APT::Configuration::getLanguages(false, false, env);
+ ASSERT_EQ(3 ,vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ // Special: Check if the cache is actually in use
+ env[0] = "en_GB.UTF-8";
+ vec = APT::Configuration::getLanguages(false, true, env);
+ ASSERT_EQ(3, vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ env[0] = "en_GB.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ ASSERT_EQ(2, vec.size());
+ EXPECT_EQ("en_GB", vec[0]);
+ EXPECT_EQ("en", vec[1]);
+
+ // esperanto
+ env[0] = "eo.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ ASSERT_EQ(2, vec.size());
+ EXPECT_EQ("eo", vec[0]);
+ EXPECT_EQ("en", vec[1]);
+
+ env[0] = "tr_DE@euro";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(3, vec.size());
+ EXPECT_EQ("tr_DE", vec[0]);
+ EXPECT_EQ("tr", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ 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);
+ EXPECT_EQ(6, vec.size());
+ EXPECT_EQ("de_NO", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en_GB", vec[2]);
+ EXPECT_EQ("nb_NO", vec[3]);
+ EXPECT_EQ("nb", vec[4]);
+ EXPECT_EQ("en", vec[5]);
+
+ env[0] = "pt_PR.UTF-8";
+ env[1] = "";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(3, vec.size());
+ EXPECT_EQ("pt_PR", vec[0]);
+ EXPECT_EQ("pt", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ env[0] = "ast_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env); // bogus, but syntactical correct
+ EXPECT_EQ(3, vec.size());
+ EXPECT_EQ("ast_DE", vec[0]);
+ EXPECT_EQ("ast", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ env[0] = "C";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("en", vec[0]);
+
+ _config->Set("Acquire::Languages", "none");
+ env[0] = "C";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_TRUE(vec.empty());
+
+ _config->Set("Acquire::Languages", "environment");
+ env[0] = "C";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("en", vec[0]);
+
+ _config->Set("Acquire::Languages", "de");
+ env[0] = "C";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("de", vec[0]);
+
+ _config->Set("Acquire::Languages", "fr");
+ env[0] = "ast_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("fr", vec[0]);
+
+ _config->Set("Acquire::Languages", "environment,en");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(3, vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+ _config->Set("Acquire::Languages", "");
+
+ _config->Set("Acquire::Languages::1", "environment");
+ _config->Set("Acquire::Languages::2", "en");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(3, vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ _config->Set("Acquire::Languages::3", "de");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(3, vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ _config->Clear();
+}
-int main(int argc,char *argv[])
+TEST(LanguagesTest,TranslationFiles)
{
- if (argc != 2) {
- std::cout << "One parameter expected - given " << argc << std::endl;
- return 100;
- }
-
- char const* env[2];
- env[0] = "de_DE.UTF-8";
- env[1] = "";
-
- std::vector<std::string> 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");
-
- // 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");
-
- 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");
-
- 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", "environment,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", "");
-
- _config->Set("Acquire::Languages::1", "environment");
- _config->Set("Acquire::Languages::2", "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");
- 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");
- env[0] = "de_DE.UTF-8";
- vec = APT::Configuration::getLanguages(false, false, env);
- equals(vec.size(), 0);
- 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");
- 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");
- 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");
- 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");
- env[0] = "de_DE.UTF-8";
- vec = APT::Configuration::getLanguages(true, false, env);
- equals(vec.size(), 1);
- equals(vec[0], "en");
-
- return 0;
+ _config->Clear();
+ _config->Set("Acquire::Languages::1", "environment");
+ _config->Set("Acquire::Languages::2", "en");
+ _config->Set("Acquire::Languages::3", "de");
+
+ char const* env[2];
+ env[0] = "de_DE.UTF-8";
+ env[1] = "";
+
+ std::string tempdir;
+ createTemporaryDirectory("languages", tempdir);
+
+#define createTranslation(lang) \
+ createFile(tempdir, std::string("/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-").append(lang));
+
+ createTranslation("tr");
+ createTranslation("pt");
+ createTranslation("se~");
+ createTranslation("st.bak");
+ createTranslation("ast_DE");
+ createTranslation("tlh%5fDE");
+
+ _config->Set("Dir::State::lists", tempdir);
+ std::vector<std::string> vec = APT::Configuration::getLanguages(true, false, env);
+ EXPECT_EQ(8, vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+ EXPECT_EQ("none", vec[3]);
+ EXPECT_NE(vec.end(), std::find(vec.begin(), vec.end(), "pt"));
+ EXPECT_NE(vec.end(), std::find(vec.begin(), vec.end(), "tr"));
+ EXPECT_NE(vec.end(), std::find(vec.begin(), vec.end(), "ast_DE"));
+ EXPECT_NE(vec.end(), std::find(vec.begin(), vec.end(), "tlh_DE"));
+ EXPECT_NE(vec[4], vec[5]);
+ EXPECT_NE(vec[4], vec[6]);
+ EXPECT_NE(vec[4], vec[7]);
+ EXPECT_NE(vec[5], vec[6]);
+ EXPECT_NE(vec[5], vec[7]);
+ EXPECT_NE(vec[6], vec[7]);
+
+ _config->Set("Acquire::Languages", "none");
+ vec = APT::Configuration::getLanguages(true, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("none", vec[0]);
+ _config->Set("Acquire::Languages", "");
+
+ _config->Set("Dir::State::lists", "/non-existing-dir");
+ _config->Set("Acquire::Languages::1", "none");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_TRUE(vec.empty());
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ EXPECT_EQ(2, vec.size());
+ EXPECT_EQ("en", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+
+ _config->Set("Acquire::Languages::1", "fr");
+ _config->Set("Acquire::Languages", "de_DE");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+
+ _config->Set("Acquire::Languages", "none");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("none", vec[0]);
+
+ _config->Set("Acquire::Languages", "");
+ //FIXME: Remove support for this deprecated setting
+ _config->Set("APT::Acquire::Translation", "ast_DE");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ EXPECT_EQ(2, vec.size());
+ EXPECT_EQ("ast_DE", vec[0]);
+ EXPECT_EQ("en", vec[1]);
+ _config->Set("APT::Acquire::Translation", "none");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("en", vec[0]);
+
+
+ EXPECT_EQ(0, system(std::string("rm -rf ").append(tempdir).c_str()));
+ _config->Clear();
}