Exemple #1
0
 BINLINE void BContentStream::copyProperties(const PContentStream& rhs) {
   if (rhs) {
     contentType = rhs->getContentType();
     contentLength = rhs->getContentLength();
     fileName = rhs->getFileName();
     attachmentCode = rhs->getAttachmentCode();
     targetId = rhs->getTargetId();
   }
 }
  /**
  * Use class BContentStreamFile to transfer a stream.
  */
  void testRemoteStreamsOneFileStream() {
    l_info << L"testRemoteStreamsOneFileStream(";

    std::string fileContent = "hello";

    BFile file = BFile::createTempFile(L"byps", L".txt");
    byps_ptr<ofstream> fos = file.openWrite();
    (*fos) << fileContent;
    fos->close();

    PContentStream strm(new BContentStreamWrapper(file));

    PRemoteStreams remote = client->getRemoteStreams();
    l_info << L"remote->setImage ...";
    remote->setImage(strm);
    l_info << L"remote->setImage OK";

    strm.reset();
    file.delet();

    l_info << L"remote->getImage ...";
    PContentStream strmR = remote->getImage();
    l_info << L"remote->getImage OK";

    //TASSERT(L"Content-Type", "text/plain", strmR->getContentType()); // there is currently no Content-Type detection in BContentStreamFile

    l_info << L"getContentLength ...";
    int64_t contentLengthR = strmR->getContentLength();
    l_info << L"getContentLength OK, #=" << contentLengthR;
    TASSERT(L"wrong content length", fileContent.size(), (size_t)contentLengthR);

    TASSERT(L"FileName", file.getName(), strmR->getFileName());

    l_info << L"read ...";
    char buf[1000] = {0};
    int32_t len = strmR->read(buf, 0, sizeof(buf));
    l_info << L"read OK, len=" << len;

    TASSERT(L"wrong stream content", fileContent, std::string(buf));
    TASSERT(L"FileName", file.getName(), strmR->getFileName());
    TASSERT(L"wrong content length", fileContent.size(), (size_t)strmR->getContentLength());

    l_info << L")testRemoteStreamsOneFileStream";
  }