/// 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; }
/// 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; }
void insertItem(const char* testFileName, const int expectedResult, const char* expectedOutName, const char* forceFileName = NULL) { FileData file = createFileData(testFileName); if (forceFileName) { WString wname; StringBuffer tmp(forceFileName); wname = tmp; file.setName(wname.c_str()); } // Create a SyncItem containing the OMA file data SyncItem item(TEXT("test1")); char* data = file.format(); item.setData(data, (long)strlen(data)); delete [] data; int ret = fmss->insertItem(item); // TESTS CPPUNIT_ASSERT_MESSAGE("wrong status returned", ret == expectedResult); if (fmss->isErrorCode(ret)) { return; } StringBuffer outKey; outKey.convert(item.getKey()); CPPUNIT_ASSERT_MESSAGE("wrong item's key returned", outKey == expectedOutName); StringBuffer outFile(outputDir); outFile.append(expectedOutName); 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( (int)outLen == file.getSize() ); delete [] outContent; }