email/pop3andsmtpmtm/clientmtms/test/src/ctestsmtpmobilitysettings.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "ctestsmtpmobilitysettings.h"
       
    17 #include "cimsmtpmobilitysettings.h"
       
    18 #include <smtpset.h>
       
    19 
       
    20 _LIT(KServerAddress, "Server address");
       
    21 _LIT(KEmailAlias, "Email alias");
       
    22 _LIT(KEmailAddress, "Email address");
       
    23 _LIT8(KLoginName, "Login name");
       
    24 _LIT8(KPassword, "Password");
       
    25 _LIT8(KTlsSslDomain, "TLS SSL domain");
       
    26 const TUint KPort = 12345678;
       
    27 const TUid KCharset = TUid::Uid(12345678);
       
    28 
       
    29 /**
       
    30 Constructor
       
    31 */
       
    32 CTestSmtpMobilitySettings::CTestSmtpMobilitySettings()
       
    33 	{
       
    34 	}
       
    35 
       
    36 /**
       
    37 Destructor
       
    38 */
       
    39 CTestSmtpMobilitySettings::~CTestSmtpMobilitySettings()
       
    40 	{
       
    41 	delete iSettings;
       
    42 	}
       
    43 
       
    44 /**
       
    45 Test setup
       
    46 */
       
    47 void CTestSmtpMobilitySettings::SetupL()
       
    48 	{
       
    49 	delete iSettings;
       
    50 	iSettings = NULL;
       
    51 	iSettings = CImSmtpMobilitySettings::NewL();
       
    52 	}
       
    53 
       
    54 /**
       
    55 Sets all the settings to known values
       
    56 */
       
    57 void CTestSmtpMobilitySettings::SetValuesL(CImSmtpMobilitySettings& aSettings)
       
    58 	{
       
    59 	aSettings.SetServerAddressL(KServerAddress);
       
    60 	aSettings.SetPort(KPort);
       
    61 	aSettings.SetSecureSockets(ETrue);
       
    62 	aSettings.SetSSLWrapper(ETrue);
       
    63 	aSettings.SetEmailAliasL(KEmailAlias);
       
    64 	aSettings.SetEmailAddressL(KEmailAddress);
       
    65 	aSettings.SetDefaultMsgCharSet(KCharset);
       
    66 	aSettings.SetLoginNameL(KLoginName);
       
    67 	aSettings.SetPasswordL(KPassword);
       
    68 	aSettings.SetSMTPAuth(ETrue);
       
    69 	aSettings.SetTlsSslDomainL(KTlsSslDomain);
       
    70 	}
       
    71 
       
    72 /**
       
    73 Check that the settings are empty.
       
    74 
       
    75 Note that the DefaultMsgCharset setting is not checked here, because the
       
    76 SMTP settings reset routine does not reset it to a default value.
       
    77 
       
    78 @param aSettings Settings to check
       
    79 */
       
    80 void CTestSmtpMobilitySettings::CheckSettingsEmpty(const CImSmtpMobilitySettings& aSettings)
       
    81 	{
       
    82 	ASSERT_EQUALS(aSettings.ServerAddress().Compare(KNullDesC), 0);
       
    83 	ASSERT_EQUALS(aSettings.Port(), static_cast<TUint>(KSMTPDefaultPortNumber));
       
    84 	ASSERT_FALSE(aSettings.SecureSockets());
       
    85 	ASSERT_FALSE(aSettings.SSLWrapper());
       
    86 	ASSERT_EQUALS(aSettings.EmailAlias().Compare(KNullDesC), 0);
       
    87 	ASSERT_EQUALS(aSettings.EmailAddress().Compare(KNullDesC), 0);
       
    88 	ASSERT_EQUALS(aSettings.LoginName().Compare(KNullDesC8), 0);
       
    89 	ASSERT_EQUALS(aSettings.Password().Compare(KNullDesC8), 0);
       
    90 	ASSERT_FALSE(aSettings.SMTPAuth());
       
    91 	ASSERT_EQUALS(aSettings.TlsSslDomain().Compare(KNullDesC8), 0);
       
    92 	}
       
    93 
       
    94 /**
       
    95 Checks that all the settings have been set to known values
       
    96 
       
    97 @param aSettings Settings to check
       
    98 */
       
    99 void CTestSmtpMobilitySettings::CheckSettingsSet(const CImSmtpMobilitySettings& aSettings)
       
   100 	{
       
   101 	ASSERT_EQUALS(aSettings.ServerAddress().Compare(KServerAddress), 0);
       
   102 	ASSERT_EQUALS(aSettings.Port(), KPort);
       
   103 	ASSERT_TRUE(aSettings.SecureSockets() || aSettings.SSLWrapper());
       
   104 	ASSERT_EQUALS(aSettings.EmailAlias().Compare(KEmailAlias), 0);
       
   105 	ASSERT_EQUALS(aSettings.EmailAddress().Compare(KEmailAddress), 0);
       
   106 	ASSERT_EQUALS(aSettings.DefaultMsgCharSet(), KCharset);
       
   107 	ASSERT_EQUALS(aSettings.LoginName().Compare(KLoginName), 0);
       
   108 	ASSERT_EQUALS(aSettings.Password().Compare(KPassword), 0);
       
   109 	ASSERT_TRUE(aSettings.SMTPAuth());
       
   110 	ASSERT_EQUALS(aSettings.TlsSslDomain().Compare(KTlsSslDomain), 0);
       
   111 	}
       
   112 
       
   113 /**
       
   114 Test create empty settings class
       
   115 */
       
   116 void CTestSmtpMobilitySettings::TestCreateEmptyL()
       
   117 	{
       
   118 	INFO_PRINTF1(_L("TestCreateEmptyL - Start"));
       
   119 
       
   120 	CImSmtpMobilitySettings* settings = CImSmtpMobilitySettings::NewLC();
       
   121 	CheckSettingsEmpty(*settings);
       
   122 	CleanupStack::PopAndDestroy(settings);
       
   123 
       
   124 	settings = CImSmtpMobilitySettings::NewL();
       
   125 	CheckSettingsEmpty(*settings);
       
   126 	delete settings;
       
   127 
       
   128 	INFO_PRINTF1(_L("TestCreateEmptyL - Complete"));
       
   129 	}
       
   130 
       
   131 /**
       
   132 Test set values
       
   133 */
       
   134 void CTestSmtpMobilitySettings::TestSetValuesL()
       
   135 	{
       
   136 	INFO_PRINTF1(_L("TestSetValuesL - Start"));
       
   137 
       
   138 	SetValuesL(*iSettings);
       
   139 
       
   140 	CheckSettingsSet(*iSettings);
       
   141 
       
   142 	INFO_PRINTF1(_L("TestSetValuesL - Complete"));
       
   143 	}
       
   144 
       
   145 /**
       
   146 Test class reset
       
   147 */
       
   148 void CTestSmtpMobilitySettings::TestResetL()
       
   149 	{
       
   150 	INFO_PRINTF1(_L("TestResetL - Start"));
       
   151 
       
   152 	SetValuesL(*iSettings);
       
   153 	iSettings->Reset();
       
   154 	CheckSettingsEmpty(*iSettings);
       
   155 
       
   156 	INFO_PRINTF1(_L("TestResetL - Complete"));
       
   157 	}
       
   158 
       
   159 /**
       
   160 Test class copy
       
   161 */
       
   162 void CTestSmtpMobilitySettings::TestCopyL()
       
   163 	{
       
   164 	INFO_PRINTF1(_L("TestCopyL - Start"));
       
   165 
       
   166 	SetValuesL(*iSettings);
       
   167 
       
   168 	CImSmtpMobilitySettings* settings = iSettings->CopyLC();
       
   169 	CheckSettingsSet(*settings);
       
   170 	CleanupStack::PopAndDestroy(settings);
       
   171 
       
   172 	settings = iSettings->CopyL();
       
   173 	CheckSettingsSet(*settings);
       
   174 	delete settings;
       
   175 
       
   176 	INFO_PRINTF1(_L("TestCopyL - Complete"));
       
   177 	}
       
   178 
       
   179 /**
       
   180 Test direct SMTP settings access
       
   181 */
       
   182 void CTestSmtpMobilitySettings::TestSmtpSettingsL()
       
   183 	{
       
   184 	INFO_PRINTF1(_L("TestSmtpSettingsL - Start"));
       
   185 	
       
   186 	CImSmtpSettings* smtpSettings = new(ELeave) CImSmtpSettings();
       
   187 
       
   188 	// Ownership of SMTP settings is passed to SMTP mobility settings class
       
   189 	iSettings->SetSmtpSettings(smtpSettings);
       
   190 
       
   191 	ASSERT_EQUALS(&(iSettings->SmtpSettings()), smtpSettings);
       
   192 
       
   193 	INFO_PRINTF1(_L("TestSmtpSettingsL - Complete"));
       
   194 	}
       
   195 
       
   196 CTestSuite* CTestSmtpMobilitySettings::CreateSuiteL(const TDesC& aName)
       
   197 	{
       
   198 	SUB_SUITE;
       
   199 	ADD_TEST_STEP(TestCreateEmptyL);
       
   200 	ADD_TEST_STEP(TestSetValuesL);
       
   201 	ADD_TEST_STEP(TestResetL);
       
   202 	ADD_TEST_STEP(TestCopyL);
       
   203 	ADD_TEST_STEP(TestSmtpSettingsL);
       
   204 	END_SUITE;
       
   205 	}