From 6601d11398e9325f1b8d9322d022f816f18b4f4b Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 8 Nov 2011 08:45:39 +0100 Subject: removed orphaned files --- src/base/language.cpp | 218 ------------------------------------------------- src/base/language.hpp | 92 --------------------- test/base/database.cpp | 128 ----------------------------- test/base/language.cpp | 86 ------------------- 4 files changed, 524 deletions(-) delete mode 100644 src/base/language.cpp delete mode 100644 src/base/language.hpp delete mode 100644 test/base/database.cpp delete mode 100644 test/base/language.cpp diff --git a/src/base/language.cpp b/src/base/language.cpp deleted file mode 100644 index 646194c2..00000000 --- a/src/base/language.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* - * UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#include -#include -#include - -#include "language.hpp" -#include "utils/unicode_file.hpp" - -// namespace alias for shorter class names -namespace fs = boost::filesystem; - -namespace usdx -{ - Language* Language::instance = NULL; - - log4cxx::LoggerPtr Language::log = - log4cxx::Logger::getLogger("usdx.base.language"); - - LanguageNotFound::LanguageNotFound(const std::wstring& language) : - BaseException("Language not found!"), - language(language) - { - } - - const std::wstring& LanguageNotFound::get_language() const - { - return language; - } - - - Language::Language(void) : current_translation(NULL), default_translation(NULL) - { - } - - void remove_element(std::pair*> element) - { - if (element.second) { - element.second->clear(); - } - - delete element.second; - element.second = NULL; - } - - Language::~Language(void) - { - // clear memory for all elements in the map - std::for_each(translations.begin(), translations.end(), - remove_element); - translations.clear(); - - // remove reference from singleton to make regeneration possible - instance = NULL; - } - - Language* Language::get_instance(void) - { - if (instance == NULL) { - instance = new Language(); - } - - return instance; - } - - void Language::parse_translation(const std::wstring& line, std::map& map) - { - size_t found = line.find(L"="); - if (found != std::wstring::npos) { - // copy the substring until '=' and - // transform to upper case - std:: wstring key(found, L' '); - std::transform(line.begin(), line.begin() + found, - key.begin(), toupper); - boost::trim(key); - - std::wstring value(line.substr(found + 1)); - boost::trim_if(value, boost::is_cntrl()); - boost::trim(value); - - LOG4CXX_TRACE(log, L"Found translation from " << - key << L" to " << value); - - map[key] = value; - } - } - - void Language::load_language(const std::wstring& language) - { - fs::wpath source_path = language_dir / (language + L".ini"); - - if (exists(source_path)) { - std::map *map = - new std::map(); - - UnicodeFile source(source_path); - - bool started = false; - std::wstring line; - - while (source.stream().good()) { - getline(source.stream(), line); - - if (started) { - if (line[0] == L'[' && line[line.length() - 1] == L']') { - break; - } - - parse_translation(line, *map); - } - else { - if (line.compare(L"[Text]")) { - started = true; - } - } - } - - translations[basename(source_path)] = map; - } - } - - void Language::load_default_language(const std::wstring& default_language) - { - std::map*>::iterator it = translations.find(default_language); - if (it != translations.end()) { - LOG4CXX_DEBUG(log, L"Loading default language: " << default_language); - load_language(default_language); - current_translation = default_translation = translations[default_language]; - current_language = default_language; - } - } - - void Language::init(const fs::wpath& language_dir, const std::wstring& default_language) - { - if (!is_directory(language_dir)) { - throw std::invalid_argument("language_dir should be a directory"); - } - - this->language_dir = language_dir; - - // default construction yields past-the-end - fs::wdirectory_iterator end_it; - for (fs::wdirectory_iterator it(language_dir); it != end_it; ++it) - { - if (!is_directory(it->status()) && - extension(it->path()) == L".ini") - { - translations[basename(it->path())] = NULL; - } - } - - load_default_language(default_language); - } - - void Language::set_language(const std::wstring& language) - { - std::map*>::iterator it = translations.find(language); - if (it == translations.end()) { - throw LanguageNotFound(language); - } - - if (it->second == NULL) { - load_language(language); - } - - current_language = std::wstring(language); - current_translation = translations[current_language]; - } - - const std::wstring& Language::get_language(void) const - { - return current_language; - } - - const std::wstring& Language::translate(const std::wstring& source) const - { - if (current_translation) { - std::map::iterator it = current_translation->find(source); - if (it != current_translation->end()) { - return it->second; - } - } - - if (default_translation) { - std::map::iterator it = default_translation->find(source); - if (it != default_translation->end()) { - return it->second; - } - } - - - return source; - } -}; diff --git a/src/base/language.hpp b/src/base/language.hpp deleted file mode 100644 index b3aff24d..00000000 --- a/src/base/language.hpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#ifndef LANGUAGE_HPP -#define LANGUAGE_HPP - -#include -#include -#include -#include -#include "utils/base_exception.hpp" - -/** - * Helper macro for translating strings with a short pseudo function call. - */ -#define _(x) Language::get_instance()->translate(x) - -namespace usdx -{ - class LanguageNotFound : public BaseException - { - private: - std::wstring language; - public: - LanguageNotFound(const std::wstring& language); - ~LanguageNotFound () throw () {}; - - const std::wstring& get_language() const; - }; - - class Language - { - private: - static log4cxx::LoggerPtr log; - - boost::filesystem::wpath language_dir; - - std::map* current_translation; - std::wstring current_language; - - std::map* default_translation; - - std::map*> translations; - - void parse_translation(const std::wstring& line, - std::map& map); - - void load_language(const std::wstring& language); - void load_default_language(const std::wstring& language); - - Language(); - - static Language* instance; - public: - virtual ~Language(); - - static Language* get_instance(); - - void init(const boost::filesystem::wpath& language_dir, - const std::wstring& default_language = L"English"); - - void set_language(const std::wstring& language); - const std::wstring& get_language(void) const; - - const std::wstring& translate(const std::wstring& source) const; - }; -}; - -#endif diff --git a/test/base/database.cpp b/test/base/database.cpp deleted file mode 100644 index 8ba7f44d..00000000 --- a/test/base/database.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#define STAT_DATABASE_TEST - -#include "stats_database.hpp" -#include -#include -#include - -namespace usdx -{ - class StatDatabaseTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StatDatabaseTest); -/* CPPUNIT_TEST(testNotNull); - CPPUNIT_TEST(testGetVersion); - CPPUNIT_TEST(testSetAndGetVersion); - CPPUNIT_TEST(testSizeOfTime_t); - CPPUNIT_TEST(testGetStatReset); -*/ - CPPUNIT_TEST(testFormatDate); -/* CPPUNIT_TEST(testTableExists); - CPPUNIT_TEST(testTableNotExists); - CPPUNIT_TEST(testTableColumnExists); - CPPUNIT_TEST(testTableColumnNotExists); - CPPUNIT_TEST(testTableColumnTableNotExists); -*/ - CPPUNIT_TEST_SUITE_END(); - private: - StatDatabase *db; - public: - void setUp() - { -// StatDatabase::init("../game/Ultrastar.db"); - } - - void tearDown() - { -// delete StatDatabase::get_instance(); - } - -/* void testNotNull() - { - CPPUNIT_ASSERT( NULL != StatDatabase::get_instance() ); - } - - void testGetVersion() - { - CPPUNIT_ASSERT( 1 == StatDatabase::get_instance()->get_version() ); - } - - void testSetAndGetVersion() - { - CPPUNIT_ASSERT( 1 == StatDatabase::get_instance()->get_version() ); - StatDatabase::get_instance()->set_version(0); - CPPUNIT_ASSERT( 0 == StatDatabase::get_instance()->get_version() ); - StatDatabase::get_instance()->set_version(1); - CPPUNIT_ASSERT( 1 == StatDatabase::get_instance()->get_version() ); - } - - void testSizeOfTime_t() - { - CPPUNIT_ASSERT( sizeof(time_t) == sizeof(long) ); - } - - void testGetStatReset() - { - CPPUNIT_ASSERT( 1000000000 < StatDatabase::get_instance()->get_stat_reset() ); - } -*/ - void testFormatDate() - { - char buf[9]; - StatDatabase::format_date(buf, 9, 1262433600); - CPPUNIT_ASSERT( strcmp(buf, "13.02.09") ); - } -/* - void testTableExists() - { - CPPUNIT_ASSERT( true == StatDatabase::get_instance()->sqlite_table_exists("us_songs") ); - } - - void testTableNotExists() - { - CPPUNIT_ASSERT( false == StatDatabase::get_instance()->sqlite_table_exists("abc") ); - } - - void testTableColumnExists() - { - CPPUNIT_ASSERT( true == StatDatabase::get_instance()->sqlite_table_contains_column("us_songs", "Title") ); - } - - void testTableColumnNotExists() - { - CPPUNIT_ASSERT( false == StatDatabase::get_instance()->sqlite_table_contains_column("us_songs", "title") ); - } - - void testTableColumnTableNotExists() - { - CPPUNIT_ASSERT( false == StatDatabase::get_instance()->sqlite_table_contains_column("abc", "Title") ); - } -*/ }; - - CPPUNIT_TEST_SUITE_REGISTRATION(StatDatabaseTest); -}; diff --git a/test/base/language.cpp b/test/base/language.cpp deleted file mode 100644 index 0e20c1c3..00000000 --- a/test/base/language.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#include "language.hpp" - -#include -#include -#include - -namespace usdx -{ - class LanguageTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(LanguageTest); - CPPUNIT_TEST(testInit); - CPPUNIT_TEST_EXCEPTION(testLangDirIsFile, std::invalid_argument); - CPPUNIT_TEST_EXCEPTION(testLangDirNotExists, std::invalid_argument); - CPPUNIT_TEST(testNoInit); - CPPUNIT_TEST_SUITE_END(); - private: - static log4cxx::LoggerPtr log; - public: - void setUp() - { - } - - void tearDown() - { - delete Language::get_instance(); - } - - void testInit() - { - Language::get_instance()->init(L"../game/languages/"); - LOG4CXX_DEBUG(log, L" -" << _(L"SING_SONG_SELECTION_DESC") << "-"); - CPPUNIT_ASSERT(_(L"SING_SONG_SELECTION_DESC") == L"choose your song"); - - Language::get_instance()->set_language(L"German"); - LOG4CXX_DEBUG(log, L" -" << _(L"SING_SONG_SELECTION_DESC") << "-"); - CPPUNIT_ASSERT(_(L"SING_SONG_SELECTION_DESC") == L"Wähle deinen Song"); - } - - void testLangDirIsFile() - { - Language::get_instance()->init(L"../game/languages/English.ini"); - } - - void testLangDirNotExists() - { - Language::get_instance()->init(L"../foo/blub/"); - } - - void testNoInit() - { - LOG4CXX_DEBUG(log, L" -" << _(L"SING_SONG_SELECTION_DESC") << "-"); - CPPUNIT_ASSERT(_(L"SING_SONG_SELECTION_DESC") == L"SING_SONG_SELECTION_DESC"); - } - }; - - log4cxx::LoggerPtr LanguageTest::log = - log4cxx::Logger::getLogger("test.usdx.base.language"); - - CPPUNIT_TEST_SUITE_REGISTRATION(LanguageTest); -}; -- cgit v1.2.3