TEST_F(MHTMLTest, TestMHTMLEncoding) { addTestResources(); RefPtr<SharedBuffer> data = serialize("Test Serialization", "text/html", MHTMLArchive::UseDefaultEncoding); // Read the MHTML data line per line and do some pseudo-parsing to make sure the right encoding is used for the different sections. LineReader lineReader(std::string(data->data(), data->size())); int sectionCheckedCount = 0; const char* expectedEncoding = 0; std::string line; while (lineReader.getNextLine(&line)) { if (line.compare(0, 13, "Content-Type:") == 0) { ASSERT_FALSE(expectedEncoding); if (line.find("multipart/related;") != std::string::npos) { // Skip this one, it's part of the MHTML header. continue; } if (line.find("text/") != std::string::npos) expectedEncoding = "quoted-printable"; else if (line.find("image/") != std::string::npos) expectedEncoding = "base64"; else FAIL() << "Unexpected Content-Type: " << line; continue; } if (line.compare(0, 26, "Content-Transfer-Encoding:") == 0) { ASSERT_TRUE(expectedEncoding); EXPECT_NE(line.find(expectedEncoding), std::string::npos); expectedEncoding = 0; sectionCheckedCount++; } } EXPECT_EQ(12, sectionCheckedCount); }
void Filters::Load() { status_t err; // figure out where the file should be BPath path; err = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); if (err != B_NO_ERROR) return; path.Append(FileNames::filtersFileName); // open the file BFile* file = new BFile(path.Path(), B_READ_ONLY); if (file->InitCheck() != B_NO_ERROR) { delete file; return; } // load the text off_t fileSize; file->GetSize(&fileSize); char* text = new char[fileSize]; file->ReadAt(0, text, fileSize); delete file; // parse it TextReader reader(string_slice(text, text + fileSize)); FilterGroup* curGroup = NULL; while (!reader.AtEOF()) { // get the groupName string_slice groupName = reader.NextTabField(); if (groupName.length() > 0) { curGroup = GetFilterGroup(groupName); if (curGroup == NULL) { curGroup = new FilterGroup(groupName); AddFilterGroup(curGroup); } reader.NextLine(); } // if none, this is a filter line (if it's not blank) else { string_slice filterLine = reader.NextLine(); if (filterLine.length() > 0 && curGroup != NULL) { Filter* filter = new Filter(); TextReader lineReader(filterLine); filter->ReadFrom(&lineReader); curGroup->AddFilter(filter); } } } // clean up delete text; }
bool CBasicFastaWrapper::ReadFile(CNcbiIstream& iStream) { bool result = (iStream.good()); if (!result) { m_error = "Read Error: invalid stream.\n"; } else { CNcbiOstrstream oss; oss << iStream.rdbuf(); iStream.seekg(0); m_activeFastaString = CNcbiOstrstreamToString(oss); if (m_cacheRawFasta) m_rawFastaString = m_activeFastaString; // temporarily turn off warning messages (in case of '.' in *.a2m files) EDiagSev originalDiagSev = SetDiagPostLevel(eDiag_Error); try{ CStreamLineReader lineReader(iStream); CFastaReader fastaReader(lineReader, m_readFastaFlags); //CCounterManager counterMgr(reader.SetIDGenerator(), NULL); m_seqEntry = fastaReader.ReadSet(); // If there is only one sequence in the fasta, the Seq-entry returned is a Bioseq and not a Bioseq-set. // In that case, change the Bioseq to a Bioseq-set so caller doesn't have to manage multiple Seq-entry choices. if (m_seqEntry->IsSeq() && m_useBioseqSet) { CRef<CSeq_entry> bioseqFromFasta(new CSeq_entry); bioseqFromFasta->Assign(*m_seqEntry); m_seqEntry->Select(CSeq_entry::e_Set); m_seqEntry->SetSet().SetSeq_set().push_back(bioseqFromFasta); } } catch (...) { result = false; m_seqEntry.Reset(); } if (m_seqEntry.Empty()) { result = false; m_error = "Read Error: empty seq entry.\n"; } SetDiagPostLevel(originalDiagSev); } return result; }
TEST_F(WebPageNewSerializeTest, TestMHTMLEncodingWithMorphingDataURL) { // Load a page with some data urls. WebURL topFrameURL = toKURL(m_baseURL); registerMockedURLLoad(topFrameURL, WebString::fromUTF8("page_with_morphing_data.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType()); loadURLInTopFrame(topFrameURL); WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView()); ASSERT_FALSE(mhtmlData.isEmpty()); // Read the MHTML data line and check that the string data:image is found // exactly two times. size_t nbDataURLs = 0; LineReader lineReader(std::string(mhtmlData.data())); std::string line; while (lineReader.getNextLine(&line)) { if (line.find("data:text") != std::string::npos) nbDataURLs++; } EXPECT_EQ(2u, nbDataURLs); }
int main(int argc, char **argv){ int size = 1000; char *line = malloc(101); int len; HashTable *numbers; FILE *fp = NULL; numbers = createTable(size); if(argc == 2){ fp = fopen(argv[1], "r"); }else if(argc > 2){ printf("error\n"); return -1; }else if(argc < 2){ printf("error\n"); return -1; } if(fp == NULL){ printf("error\n"); return -1; } while(fgets(line, 100, fp) != NULL){ int i = lineReader(line, numbers); if(i == -1){ return -1; } } free(numbers->table); free(numbers); return 0; }