enum TVerdict CEsockTest2_5::easyTestStepL()
	{
	TESTL(EPass == TestStepResult());
	
	// get port numbers
	TInt port1, port2;
	TESTL(GetIntFromConfig(SectionName(_L("Test_2.5")), _L("port1"), port1));
	TESTL(GetIntFromConfig(SectionName(_L("Test_2.5")), _L("port2"), port2));
	
	// set the local port number to port1
	TInt nRet = iEsockSuite->GetSocketHandle(1).SetLocalPort(port1);
	TESTEL(nRet == KErrNone, nRet);
	
	// check port has been set correctly
	TUint port = iEsockSuite->GetSocketHandle(1).LocalPort();
	TESTL(port == (TUint)port1);
	
	// set the local port number to port2
	// check that this is not successful
	nRet = iEsockSuite->GetSocketHandle(1).SetLocalPort(port2);
	TESTEL(nRet == KErrAlreadyExists, nRet);
	
	// check port has not been changed
	port = iEsockSuite->GetSocketHandle(1).LocalPort();
	TESTL(port == (TUint)port1);
	
	return EPass;
	}
void CSettingTypeApplication::Save(int /*Index*/, uint32_t Value)
{
    if (m_DefaultSetting != Default_None &&
        ((m_DefaultSetting == Default_Constant && m_DefaultValue == Value) ||
        (m_DefaultSetting != Default_Constant && g_Settings->LoadDword(m_DefaultSetting) == Value)))
    {
        m_SettingsIniFile->SaveString(SectionName(), m_KeyNameIdex.c_str(), NULL);
    }
    else
    {
        m_SettingsIniFile->SaveNumber(SectionName(), m_KeyNameIdex.c_str(), Value);
    }
}
Пример #3
0
	void HistoryModel::Add (const HistoryItem& histItem, int section)
	{
		while (section >= rowCount ())
		{
			const auto& folderIcon = Core::Instance ().GetProxy ()->
					GetIconThemeManager ()->GetIcon ("document-open-folder");

			const QList<QStandardItem*> sectItems
			{
				new QStandardItem { folderIcon, SectionName (rowCount ()) },
				new QStandardItem,
				new QStandardItem
			};
			for (const auto item : sectItems)
				item->setEditable (false);

			appendRow (sectItems);
		}

		const auto icon = Core::Instance ().GetIcon (QUrl { histItem.URL_ });
		auto normalizeText = [] (QString text)
		{
			return text.trimmed ().replace ('\n', ' ');
		};
		const QList<QStandardItem*> items
		{
			new QStandardItem { icon, normalizeText (histItem.Title_) },
			new QStandardItem { normalizeText (histItem.URL_) },
			new QStandardItem { QLocale {}.toString (histItem.DateTime_, QLocale::ShortFormat) }
		};
		for (const auto item : items)
			item->setEditable (false);
		item (section)->appendRow (items);
	}
enum TVerdict CEsockTest2_1::easyTestStepL()
	{
	TESTL(EPass == TestStepResult());
	TInt nSockets = iEsockSuite->GetSocketListCount();
	// bind to n sockets on port 0
	
	// get ip address
	TInetAddr addr, addr1;
	TESTL(GetIpAddressFromConfig(SectionName(_L("Test_2.1")), _L("ipAddress"), addr));
	
	// set the port number to 0
	addr.SetPort(0);
	
	// for each open socket
	TInt nRet;
	TUint port;
	for (TInt n = 0; n < nSockets; n++)
		{
		// bind the socket
		nRet = iEsockSuite->GetSocketHandle(n + 1).Bind(addr);
		TESTEL(nRet == KErrNone, nRet);
		
		// get the socket name
		iEsockSuite->GetSocketHandle(n + 1).LocalName(addr1);
		
		// check address has been set correctly
		TESTL(addr.Match(addr1));
		
		// get port number - check it is non-zero
		port = iEsockSuite->GetSocketHandle(n + 1).LocalPort();
		TESTL(port > 0);
		}
	
	return EPass;
	}
enum TVerdict CEsockTest2_4::easyTestStepL()
	{
	TESTL(EPass == TestStepResult());
	// double bind on different sockets
	
	// get IP address
	TInetAddr addr;
	TESTL(GetIpAddressFromConfig(SectionName(_L("Test_2.4")), _L("ipAddress"), addr));
	
	// set port number to a valid value
	addr.SetPort(9);
	
	// socket already opened - retrieve
	// socket handle and bind
	TInt nRet = iEsockSuite->GetSocketHandle(1).Bind(addr);
	
	// bind should succeed
	TESTEL(nRet == KErrNone, nRet);
	
	// socket already opened - retrieve
	// socket handle and bind again to same address
	nRet = iEsockSuite->GetSocketHandle(2).Bind(addr);
	
	// second bind should fail
	TESTEL(nRet == KErrInUse, nRet);
	
	return EPass;
	}
bool CSettingTypeApplication::Load ( int /*Index*/, bool & Value ) const
{
    bool bRes = false;

    if (!m_UseRegistry)
    {
        uint32_t dwValue;
        bRes = m_SettingsIniFile->GetNumber(SectionName(),m_KeyNameIdex.c_str(),Value,dwValue);
        if (bRes)
        {
            Value = dwValue != 0;
        }
    } else {
        g_Notify->BreakPoint(__FILEW__,__LINE__);
    }

    if (!bRes && m_DefaultSetting != Default_None)
    {
        if (m_DefaultSetting == Default_Constant)
        {
            Value = m_DefaultValue != 0;
        } else {
            g_Settings->LoadBool(m_DefaultSetting,Value);
        }
    }
    return bRes;
}
bool CSettingTypeApplication::Load(int Index, stdstr & Value) const
{
    bool bRes = m_SettingsIniFile ? m_SettingsIniFile->GetString(SectionName(), m_KeyNameIdex.c_str(), m_DefaultStr, Value) : false;
    if (!bRes)
    {
        CSettingTypeApplication::LoadDefault(Index, Value);
    }
    return bRes;
}
void CSettingTypeApplication::Save ( int /*Index*/, uint32_t Value )
{
    if (!m_UseRegistry)
    {
        m_SettingsIniFile->SaveNumber(SectionName(),m_KeyNameIdex.c_str(),Value);
    } else {
        g_Notify->BreakPoint(__FILEW__,__LINE__);
    }
}
void CSettingTypeApplication::Save ( int /*Index*/, const stdstr & Value )
{
    if (!m_UseRegistry)
    {
        m_SettingsIniFile->SaveString(SectionName(),m_KeyNameIdex.c_str(),Value.c_str());
    } else {
        g_Notify->BreakPoint(__FILEW__,__LINE__);
    }
}
void CSettingTypeApplication::Delete( int /*Index*/ )
{
    if (!m_UseRegistry)
    {
        m_SettingsIniFile->SaveString(SectionName(),m_KeyNameIdex.c_str(),NULL);
    } else {
        g_Notify->BreakPoint(__FILEW__,__LINE__);
    }
}
stdstr CSettingTypeApplication::FixSectionName(const char * Section)
{
    stdstr SectionName(Section);

    if (SectionName.empty())
    {
        SectionName = "default";
    }
    SectionName.Replace("\\", "-");
    return SectionName;
}
bool CSettingTypeApplication::Load ( int Index, stdstr & Value ) const
{
    bool bRes = false;
    if (!m_UseRegistry)
    {
        bRes = m_SettingsIniFile ? m_SettingsIniFile->GetString(SectionName(),m_KeyNameIdex.c_str(),m_DefaultStr,Value) : false;
    } else {
        g_Notify->BreakPoint(__FILEW__,__LINE__);
    }
    if (!bRes)
    {
        CSettingTypeApplication::LoadDefault(Index,Value);
    }
    return bRes;
}
bool CSettingTypeApplication::Load(int /*Index*/, uint32_t & Value) const
{
    bool bRes = m_SettingsIniFile->GetNumber(SectionName(), m_KeyNameIdex.c_str(), Value, Value);
    if (!bRes && m_DefaultSetting != Default_None)
    {
        if (m_DefaultSetting == Default_Constant)
        {
            Value = m_DefaultValue;
        }
        else
        {
            g_Settings->LoadDword(m_DefaultSetting, Value);
        }
    }
    return bRes;
}
Пример #14
0
enum TVerdict CEsockTest2_3::easyTestStepL()
	{
	TESTL(EPass == TestStepResult());
	// bind to an illegal address
	
	// get IP address
	TInetAddr addr;
	TESTL(GetIpAddressFromConfig(SectionName(_L("Test_2.3")), _L("ipAddress"), addr));
	
	// set port number to a valid value
	addr.SetPort(7);
	
	// socket already opened - retrieve
	// socket handle and bind
	TInt nRet = iEsockSuite->GetSocketHandle(1).Bind(addr);
	
	TESTEL(nRet == KErrNotFound, nRet);
	
	return EPass;
	}
bool CSettingTypeApplication::Load(int /*Index*/, bool & Value) const
{
    bool bRes = false;

    uint32_t dwValue = 0;
    bRes = m_SettingsIniFile ? m_SettingsIniFile->GetNumber(SectionName(), m_KeyNameIdex.c_str(), Value, dwValue) : false;
    if (bRes)
    {
        Value = dwValue != 0;
    }

    if (!bRes && m_DefaultSetting != Default_None)
    {
        if (m_DefaultSetting == Default_Constant)
        {
            Value = m_DefaultValue != 0;
        }
        else
        {
            g_Settings->LoadBool(m_DefaultSetting, Value);
        }
    }
    return bRes;
}
void CSettingTypeApplication::Save(int /*Index*/, const char * Value)
{
    m_SettingsIniFile->SaveString(SectionName(), m_KeyNameIdex.c_str(), Value);
}
bool CSettingTypeApplication::IsSettingSet(void) const
{
    return m_SettingsIniFile ? m_SettingsIniFile->EntryExists(SectionName(), m_KeyNameIdex.c_str()) : false;
}
void CSettingTypeApplication::Delete(int /*Index*/)
{
    m_SettingsIniFile->SaveString(SectionName(), m_KeyNameIdex.c_str(), NULL);
}
Пример #19
0
void CIniFileBase::SaveCurrentSection ( void )
{
	if (!m_CurrentSectionDirty)
	{
		return;
	}
	m_CurrentSectionDirty = false;
	if (m_CurrentSection.length() == 0)
	{
		m_CurrentSection = "default";
	}

	int lineFeedLen = (int)strlen(m_LineFeed);

	if (m_CurrentSectionFilePos == -1)
	{
		//Section has not been added yet
		m_File.Seek(0,CFileBase::end);

		int len = (int)m_CurrentSection.length() + (lineFeedLen * 2) + 5;
		AUTO_PTR<char> SectionName(new char[len]);
		if (m_File.GetLength() < (int)strlen(m_LineFeed))
		{
			sprintf(SectionName.get(),"[%s]%s",m_CurrentSection.c_str(),m_LineFeed);
		}
		else
		{
			sprintf(SectionName.get(),"%s[%s]%s",m_LineFeed,m_CurrentSection.c_str(),m_LineFeed);
		}
		m_File.Write(SectionName.get(),(int)strlen(SectionName.get()));
		m_CurrentSectionFilePos = m_File.GetPosition();
		m_SectionsPos.insert(FILELOC::value_type(m_CurrentSection,m_CurrentSectionFilePos));
	}
	else
	{
		//increase/decrease space needed
		int NeededBufferLen = 0;
		{
			AUTO_PTR<char> LineData(NULL);
			int len = 0;

			for (KeyValueList::iterator iter = m_CurrentSectionData.begin(); iter != m_CurrentSectionData.end(); iter++)
			{
				int newLen = (int)iter->first.length() + (int)iter->second.length() + lineFeedLen + 5;
				if (newLen > len)
				{
					LineData.reset(new char[newLen]);
					len = newLen;
				}
				sprintf(LineData.get(),"%s=%s%s",iter->first.c_str(),iter->second.c_str(),m_LineFeed);
				NeededBufferLen += (int)strlen(LineData.get());
			}
		}
		int currentLen = 0;

		m_File.Seek(m_CurrentSectionFilePos, CFileBase::begin);

		int MaxDataSize = 0, DataSize = 0, ReadPos = 0, result;
		char *Input = NULL, *Data = NULL;
	
		//Skip first line as it is the section name
		int StartPos = m_CurrentSectionFilePos;
		int EndPos = StartPos;
		do {
			result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos);
			if (result <= 1) { continue; }
			if (strlen(CleanLine(Input)) <= 1 || Input[0] != '[')
			{
				EndPos = ((m_File.GetPosition() - DataSize) + ReadPos);

				continue; 
			}
			if (Input[0] == '[')
			{
				NeededBufferLen += lineFeedLen;
			}
			break;
		} while (result >= 0);
		currentLen = EndPos - StartPos;

		if (Data) {  delete [] Data;  Data = NULL; }

		if (NeededBufferLen != currentLen)
		{
			fInsertSpaces(StartPos,NeededBufferLen - currentLen);
			m_File.Flush();
			ClearSectionPosList(StartPos);
		}
		//set pointer to beginning of the start pos
		m_File.Seek(StartPos, CFileBase::begin);
	}


	{
		AUTO_PTR<char> LineData(NULL);
		int len = 0;
		
		for (KeyValueList::iterator iter = m_CurrentSectionData.begin(); iter != m_CurrentSectionData.end(); iter++)
		{
			int newLen = (int)iter->first.length() + (int)iter->second.length() + lineFeedLen + 5;
			if (newLen > len)
			{
				LineData.reset(new char[newLen]);
				len = newLen;
			}
			sprintf(LineData.get(),"%s=%s%s",iter->first.c_str(),iter->second.c_str(),m_LineFeed);
			m_File.Write(LineData.get(),(int)strlen(LineData.get()));
		}
	}
	m_File.Flush();
}
void CSettingTypeApplication::Save ( int /*Index*/, uint32_t Value )
{
    m_SettingsIniFile->SaveNumber(SectionName(),m_KeyNameIdex.c_str(),Value);
}