/* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4; c-file-style:"stroustrup" -*-
**
** Copyright (C) 1995-2007 Opera Software AS.  All rights reserved.
**
** This file is part of the Opera web browser.  It may not be distributed
** under any circumstances.
**
*/

group "quick.install_dictionary";
require init;
require INTERNAL_SPELLCHECK_SUPPORT;
require AUTO_UPDATE_SUPPORT;

include "adjunct/quick/dialogs/InstallLanguageDialog.h";

include "modules/util/opfile/opfile.h";
include "modules/prefsfile/prefsfile.h";
include "modules/prefs/prefsmanager/collections/pc_files.h";
include "modules/prefsfile/accessors/lnglight.h";
include "modules/locale/oplanguagemanager.h";

global
{
	OP_STATUS SetupPathString(OpString& str, const char* filename) {
		RETURN_IF_ERROR(g_folder_manager->GetFolderPath(OPFILE_SELFTEST_DATA_FOLDER, str));
		RETURN_IF_ERROR(str.AppendFormat(UNI_L("data%s%s"), UNI_L(PATHSEP), filename));
		RETURN_IF_ERROR(str.Append(filename));

		return OpStatus::OK;
	}

}

test("GetAvailableLanguages") 
{
	DictionaryHandler handler;
	SimpleTreeModel model(3);
	OpString path;
	OP_STATUS status = SetupPathString(path, "dictionary.xml");
	verify(OpStatus::IsSuccess(status));

	verify(OpStatus::IsSuccess(handler.GetAvailableDictionaries(model, path)));
	verify(model.GetCount() == 2);
}


test("GetDictionaryNameMatchingUILanguage")
{
    const OpStringC id_en    = UNI_L("en");
    const OpStringC id_en_gb = UNI_L("en-GB");
    const OpStringC id_en_xx = UNI_L("en-XX");
    const OpStringC id_xx    = UNI_L("xx");
    const OpStringC id_NULL  = UNI_L("");    
    
    OpString language_id;

    // Test "en"
    DictionaryHandler::GetBestLanguageMatch(id_en, language_id);
    verify(DictionaryHandler::CompareLanguageId(language_id.CStr(), id_en.CStr()));
    language_id.Empty();
    
    // Test "en-GB"
    DictionaryHandler::GetBestLanguageMatch(id_en_gb, language_id);
    verify(DictionaryHandler::CompareLanguageId(language_id.CStr(), id_en_gb.CStr()));
    language_id.Empty();
    
    // Test "en-XX"
    DictionaryHandler::GetBestLanguageMatch(id_en_xx, language_id);
    verify(DictionaryHandler::CompareLanguageId(language_id.CStr(), id_en.CStr()));
    language_id.Empty();
    
    // Test "xx"
    DictionaryHandler::GetBestLanguageMatch(id_xx, language_id);
    verify(DictionaryHandler::CompareLanguageId(language_id.CStr(), id_NULL.CStr()));

    // language_id.Empty(); Test non cleaned language_id parameter 
    DictionaryHandler::GetBestLanguageMatch(id_xx, language_id);
    verify(DictionaryHandler::CompareLanguageId(language_id.CStr(), id_NULL.CStr()));
    language_id.Empty();

}
