/// Loads data for testing the 'testFileName' file.
    void loadTestFileData(const char* testFileName) {

        fileName = getTestFileFullPath(SAMPLE_FILES_DIR, testFileName);
        const char* fileContent = loadTestFile(SAMPLE_FILES_DIR, testFileName, true);  // must be binary mode!
        int fileSize = (int)fgetsize(fileName.c_str());

        const WCHAR* wtestFileName = toWideChar(testFileName);
        
        FileData fileData;
        fileData.setName(wtestFileName);
        fileData.setSize(fileSize);
        fileData.setBody(fileContent, fileSize);

        unsigned long tstamp = getFileModTime(fileName);
        StringBuffer modTime = unixTimeToString(tstamp, true);  // file's mod time is already in UTC
        WString wmodTime;
        wmodTime = modTime;
        fileData.setModified(wmodTime);

        fileDataContent = fileData.format();
        fileDataSize = (int)strlen(fileDataContent);

        delete [] wtestFileName;
        delete [] fileContent;
    }
示例#2
0
    void testFillSyncItem(){
        StringBuffer inFile = getTestFileFullPath(TEST_INPUT_DIR, TEST_FILE_NAME1);
        SyncItem* si = fmss->fakeFillSyncItem(&inFile, true);

        StringBuffer* data = new StringBuffer((char*)si->getData());

        CPPUNIT_ASSERT(si != NULL);
        CPPUNIT_ASSERT(data != NULL);
      
        CPPUNIT_ASSERT(data->find("body") == StringBuffer::npos);
        CPPUNIT_ASSERT(data->find("size") != StringBuffer::npos);
    }
示例#3
0
    /// Util method: creates a OMA file data object
    FileData createFileData(const char* inputFileName) {

        // Read the input file
        char* content = NULL;
        size_t len;
        StringBuffer inFile = getTestFileFullPath(TEST_INPUT_DIR, inputFileName);
        bool fileLoaded = readFile(inFile.c_str(), &content, &len, true);
        CPPUNIT_ASSERT_MESSAGE("Failed to load test file", fileLoaded);

        FileData file;
        file.setBody(content, (int)len);
        file.setSize((int)len);
        WString wname;
        wname = inputFileName;
        file.setName(wname.c_str());

        delete [] content;
        return file;
    }
示例#4
0
    void insertRawItem(const char* testFileName, const int expectedResult, 
                       const WCHAR* inputItemKey, const WCHAR* expectedOutName) {


        // Read the input file
        char* content = NULL;
        size_t len;
        StringBuffer inFile = getTestFileFullPath(TEST_INPUT_DIR, testFileName);
        bool fileLoaded = readFile(inFile.c_str(), &content, &len, true);
        CPPUNIT_ASSERT_MESSAGE("Failed to load test file", fileLoaded);
        
        // Create a SyncItem containing the raw file data
        SyncItem item(inputItemKey);
        item.setData(content, (long)len);
        delete [] content;

        int ret = fmss->insertItem(item);

        // TESTS
        CPPUNIT_ASSERT_MESSAGE("wrong status returned", ret == expectedResult);
        if (fmss->isErrorCode(ret)) {
            return;
        }
        WString outKey(item.getKey());
        CPPUNIT_ASSERT_MESSAGE("wrong item's key returned", outKey == expectedOutName);

        StringBuffer outFile(outputDir);
        StringBuffer outName;
        outName.convert(expectedOutName);
        outFile.append(outName);
        CPPUNIT_ASSERT_MESSAGE("output file not found", fileExists(outFile.c_str()) );

        char* outContent = NULL;
        size_t outLen;
        readFile(outFile.c_str(), &outContent, &outLen, true);
        CPPUNIT_ASSERT( outLen == len );
        delete [] outContent;
    }
示例#5
0
    void testSetItemStatus(){
        StringBuffer inFile = getTestFileFullPath(TEST_INPUT_DIR, TEST_FILE_NAME1);
        SyncItem* si = fmss->fakeFillSyncItem(&inFile, true);

        const WCHAR* wKey = si->getKey();
        const char* key = toMultibyte(wKey);
        fmss->setItemStatus(wKey, 200, "Add");
        ArrayList luidToSend = fmss->getLUIDArray();

        bool luidPresent = false;
        for (int i = 0; i < luidToSend.size(); i++){
            if( strcmp( ((StringBuffer*)luidToSend.get(i))->c_str(), key) == 0 ){
                luidPresent = true;
            }
        }
        CPPUNIT_ASSERT(luidPresent);

        int ret = fmss->endSync();
        CPPUNIT_ASSERT( ret == 0 );
    
        StringBuffer propval = fmss->fakeReadCachePropertyValue(inFile.c_str());
        CPPUNIT_ASSERT( !propval.empty() );
    }