Beispiel #1
0
void KGT_g_OpenIniFileFromArgumentsTest::Test_g_OpenFileFromArguments_09()
{
    int nResult = false;
    int nRetCode = false;

    IIniFile *piIniFile = NULL;
    char *szArgv[] = {
        "KG_GoddessD.exe",
        "--Database.password="******"value的长度为0", "");

    piIniFile = g_OpenIniFileFromArguments(nArgc, szArgv);
    KG_PROCESS_ERROR(piIniFile);

    nRetCode = piIniFile->GetSectionCount();
    KG_PROCESS_ERROR(nRetCode == 1);

    nRetCode = piIniFile->GetString("Database", "password", "root", szRetValue, sizeof(szRetValue) / sizeof(szRetValue[0]));
    KG_PROCESS_ERROR(nRetCode);

    KG_PROCESS_ERROR(szRetValue[0] == '\0');

    nResult = true;
Exit0:
    KG_COM_RELEASE(piIniFile);
    CPPUNIT_ASSERT(nResult);
}
Beispiel #2
0
void KGT_g_OpenIniFileFromArgumentsTest::Test_ErrorInput()
{
    int nResult = true;
    int nRetCode = false;

    int i = 0;
    int j = 0;
    int nErrorIndex = 0;
    int nPrevSpace = 0;
    int nArgc = 0;
    char szArgv[10][IIniFile::INI_MAX_SUPPORT_SECTION_AND_KEY_SIZE];
    IIniFile *piIniFile = NULL;
    char *pszArgv[10] = {0};

    nRetCode = _LoadFile();
    KG_PROCESS_ERROR(nRetCode);

    ASSERT(m_szErrorInput[0]);

    i = 0;
    while (m_szErrorInput[i] != '\0')
    {
        nArgc = 0;
        ZeroMemory(szArgv, sizeof(szArgv));
        nPrevSpace = i;
        while (m_szErrorInput[i] != '\n' && m_szErrorInput[i] != '\0')
        {
            if (m_szErrorInput[i] == ' ')
            {
                strncpy(szArgv[nArgc], m_szErrorInput + nPrevSpace, i - nPrevSpace);

                szArgv[nArgc][i - nPrevSpace] = '\0';
                pszArgv[nArgc] = szArgv[nArgc];
                nArgc++;
                nPrevSpace = i;
            }
            i++;
        }
        //最后一个空格到'\n'或'\0'
        strncpy(szArgv[nArgc], m_szErrorInput + nPrevSpace, i - nPrevSpace);
        szArgv[nArgc][i - nPrevSpace] = '\0';
        pszArgv[nArgc] = szArgv[nArgc];
        nArgc++;
        i++;
        nPrevSpace = i;

        if (nArgc == 0)
            continue;
        
        piIniFile = g_OpenIniFileFromArguments(nArgc, pszArgv);
        if (!piIniFile)
        {  
            ASSERT(nErrorIndex < sizeof(g_pcszErrorMessage) / sizeof(g_pcszErrorMessage[0]));
            printf("%s\n", g_pcszErrorMessage[nErrorIndex]);
            nResult = false;
        }
        nRetCode = piIniFile->GetSectionCount();
        if (nRetCode != 0)
        {
            ASSERT(nErrorIndex < sizeof(g_pcszErrorMessage) / sizeof(g_pcszErrorMessage[0]));
            printf("%s\n", g_pcszErrorMessage[nErrorIndex]);    
            nResult = false;
        }
        KG_COM_RELEASE(piIniFile);
        nErrorIndex++;
    }

/*    printf("%d\n", nErrorIndex);*/
Exit0:
    CPPUNIT_ASSERT(nResult);
}