Blame tests/broker/enchant_broker_request_dict_tests.cpp

Packit Service bc2325
/* Copyright (c) 2007 Eric Scott Albright
Packit Service bc2325
 * 
Packit Service bc2325
 * Permission is hereby granted, free of charge, to any person obtaining a copy
Packit Service bc2325
 * of this software and associated documentation files (the "Software"), to deal
Packit Service bc2325
 * in the Software without restriction, including without limitation the rights
Packit Service bc2325
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Packit Service bc2325
 * copies of the Software, and to permit persons to whom the Software is
Packit Service bc2325
 * furnished to do so, subject to the following conditions:
Packit Service bc2325
 * 
Packit Service bc2325
 * The above copyright notice and this permission notice shall be included in
Packit Service bc2325
 * all copies or substantial portions of the Software.
Packit Service bc2325
 * 
Packit Service bc2325
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service bc2325
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service bc2325
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit Service bc2325
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit Service bc2325
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Packit Service bc2325
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Packit Service bc2325
 * THE SOFTWARE.
Packit Service bc2325
 */
Packit Service bc2325

Packit Service bc2325
#include <UnitTest++.h>
Packit Service bc2325
#include <enchant.h>
Packit Service bc2325
#include "EnchantBrokerTestFixture.h"
Packit Service bc2325

Packit Service bc2325
static bool requestDictionaryCalled;
Packit Service bc2325
static EnchantDict * RequestDictionary (EnchantProvider *me, const char *tag)
Packit Service bc2325
{
Packit Service bc2325
    requestDictionaryCalled = true;
Packit Service bc2325
    return MockEnGbAndQaaProviderRequestDictionary(me, tag);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
static void Request_Dictionary_ProviderConfiguration (EnchantProvider * me, const char *)
Packit Service bc2325
{
Packit Service bc2325
     me->request_dict = RequestDictionary;
Packit Service bc2325
     me->dispose_dict = MockProviderDisposeDictionary;
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
struct EnchantBrokerRequestDictionary_TestFixture : EnchantBrokerTestFixture
Packit Service bc2325
{
Packit Service bc2325
    //Setup
Packit Service bc2325
    EnchantBrokerRequestDictionary_TestFixture():
Packit Service bc2325
            EnchantBrokerTestFixture(Request_Dictionary_ProviderConfiguration)
Packit Service bc2325
    { 
Packit Service bc2325
        _dict = NULL;
Packit Service bc2325
        requestDictionaryCalled = false;
Packit Service bc2325
    }
Packit Service bc2325

Packit Service bc2325
    //Teardown
Packit Service bc2325
    ~EnchantBrokerRequestDictionary_TestFixture()
Packit Service bc2325
    {
Packit Service bc2325
        FreeDictionary(_dict);
Packit Service bc2325
    }
Packit Service bc2325

Packit Service bc2325
    EnchantDict* _dict;
Packit Service bc2325
};
Packit Service bc2325

Packit Service bc2325
/**
Packit Service bc2325
 * enchant_broker_request_dict
Packit Service bc2325
 * @broker: A non-null #EnchantBroker
Packit Service bc2325
 * @tag: The non-null language tag you wish to request a dictionary for ("en_US", "de_DE", ...)
Packit Service bc2325
 *
Packit Service bc2325
 * Returns: An #EnchantDict, or %null if no suitable dictionary could be found.
Packit Service bc2325
 */
Packit Service bc2325

Packit Service bc2325

Packit Service bc2325

Packit Service bc2325
/////////////////////////////////////////////////////////////////////////////
Packit Service bc2325
// Test Normal Operation
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_ProviderHas_CallsProvider)
Packit Service bc2325
{
Packit Service bc2325
    _dict = enchant_broker_request_dict(_broker, "en_GB");
Packit Service bc2325
    CHECK(_dict);
Packit Service bc2325
    CHECK(requestDictionaryCalled);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_CalledTwice_CallsProviderOnceReturnsSame)
Packit Service bc2325
{
Packit Service bc2325
    _dict = enchant_broker_request_dict(_broker, "en_GB");
Packit Service bc2325
    requestDictionaryCalled = false;
Packit Service bc2325
    EnchantDict* dict = enchant_broker_request_dict(_broker, "en_GB");
Packit Service bc2325
    CHECK(!requestDictionaryCalled);
Packit Service bc2325

Packit Service bc2325
    CHECK_EQUAL(_dict, dict);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_ProviderDoesNotHave_CallsProvider)
Packit Service bc2325
{
Packit Service bc2325
    _dict = enchant_broker_request_dict(_broker, "en");
Packit Service bc2325
    CHECK_EQUAL((void*)NULL, (void*)_dict);
Packit Service bc2325
    CHECK(requestDictionaryCalled);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_ProviderHasBase_CallsProvider)
Packit Service bc2325
{
Packit Service bc2325
    _dict = enchant_broker_request_dict(_broker, "qaa_CA");
Packit Service bc2325
    CHECK(_dict);
Packit Service bc2325
    CHECK(requestDictionaryCalled);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_WhitespaceSurroundingLanguageTag_Removed)
Packit Service bc2325
{
Packit Service bc2325
    _dict = enchant_broker_request_dict(_broker, "\n\r en_GB \t\f");
Packit Service bc2325
    CHECK(_dict);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
/* Vertical tab is not considered to be whitespace in glib!
Packit Service bc2325
    See bug# 59388 http://bugzilla.gnome.org/show_bug.cgi?id=59388
Packit Service bc2325
*/
Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_VerticalTabBeforeLanguageTag_NotRemoved)
Packit Service bc2325
{
Packit Service bc2325
  _dict = enchant_broker_request_dict(_broker, "\ven_GB");
Packit Service bc2325
  CHECK_EQUAL((void*)NULL, (void*)_dict);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_VerticalTabAfterLanguageTag_NotRemoved)
Packit Service bc2325
{
Packit Service bc2325
  _dict = enchant_broker_request_dict(_broker, "en_GB\v");
Packit Service bc2325
  CHECK_EQUAL((void*)NULL, (void*)_dict);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_AtSignInLanguageTag_RemovesToTail)
Packit Service bc2325
{
Packit Service bc2325
    _dict = enchant_broker_request_dict(_broker, "en_GB@euro");
Packit Service bc2325
    CHECK(_dict);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_PeriodInLanguageTag_RemovesToTail)
Packit Service bc2325
{
Packit Service bc2325
    _dict = enchant_broker_request_dict(_broker, "en_GB.UTF-8");
Packit Service bc2325
    CHECK(_dict);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_HyphensInLanguageTag_SubstitutedWithUnderscore)
Packit Service bc2325
{
Packit Service bc2325
    _dict = enchant_broker_request_dict(_broker, "en-GB");
Packit Service bc2325
    CHECK(_dict);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_DifferentCase_Finds)
Packit Service bc2325
{
Packit Service bc2325
  _dict = enchant_broker_request_dict(_broker, "En_gb");
Packit Service bc2325
  CHECK(_dict);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_DifferentCase_NoRegion_Finds)
Packit Service bc2325
{
Packit Service bc2325
  _dict = enchant_broker_request_dict(_broker, "QAA");
Packit Service bc2325
  CHECK(_dict);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_HasPreviousError_ErrorCleared)
Packit Service bc2325
{
Packit Service bc2325
  SetErrorOnMockProvider("something bad happened");
Packit Service bc2325

Packit Service bc2325
  _dict = enchant_broker_request_dict(_broker, "en-GB");
Packit Service bc2325

Packit Service bc2325
  CHECK_EQUAL((void*)NULL, (void*)enchant_broker_get_error(_broker));
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
// ordering of providers for request is tested by enchant_broker_set_ordering tests
Packit Service bc2325

Packit Service bc2325
/////////////////////////////////////////////////////////////////////////////
Packit Service bc2325
// Test Error Conditions
Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
Packit Service bc2325
             EnchantBrokerRequestDictionary_NullBroker_NULL)
Packit Service bc2325
{
Packit Service bc2325
    _dict = enchant_broker_request_dict(NULL, "en_GB");
Packit Service bc2325

Packit Service bc2325
    CHECK_EQUAL((void*)NULL, (void*)_dict);
Packit Service bc2325
    CHECK(!requestDictionaryCalled);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
Packit Service bc2325
             EnchantBrokerRequestDictionary_NullLanguageTag_NULL)
Packit Service bc2325
{
Packit Service bc2325
    _dict = enchant_broker_request_dict(_broker, NULL);
Packit Service bc2325

Packit Service bc2325
    CHECK_EQUAL((void*)NULL, (void*)_dict);
Packit Service bc2325
    CHECK(!requestDictionaryCalled);
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
Packit Service bc2325
             EnchantBrokerRequestDictionary_EmptyLanguageTag_NULL)
Packit Service bc2325
{
Packit Service bc2325
    _dict = enchant_broker_request_dict(_broker, "");
Packit Service bc2325

Packit Service bc2325
    CHECK_EQUAL((void*)NULL, _dict);
Packit Service bc2325
    CHECK(!requestDictionaryCalled);
Packit Service bc2325

Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture, 
Packit Service bc2325
             EnchantBrokerRequestDictionary_InvalidTag_NULL_ErrorSet)
Packit Service bc2325
{
Packit Service bc2325
    _dict = enchant_broker_request_dict(_broker, "en~US");
Packit Service bc2325
    CHECK_EQUAL((void*)NULL, _dict);
Packit Service bc2325
    CHECK(NULL != enchant_broker_get_error(_broker));
Packit Service bc2325
}
Packit Service bc2325

Packit Service bc2325
TEST_FIXTURE(EnchantBrokerTestFixture,
Packit Service bc2325
             EnchantBrokerRequestDictionary_ProviderLacksListDictionaries_CallbackNeverCalled)
Packit Service bc2325
{
Packit Service bc2325
    requestDictionaryCalled = false;
Packit Service bc2325
    EnchantDict* dict = enchant_broker_request_dict(_broker, "en_GB");
Packit Service bc2325

Packit Service bc2325
    CHECK_EQUAL((void*)NULL, dict);
Packit Service bc2325
    CHECK(!requestDictionaryCalled);
Packit Service bc2325
}