daeInt daeSTLDatabase::createDocument(const char *name, daeDocument** document) { // If a document already exists with the same name, error if(isDocumentLoaded(name)) { if (document) *document = NULL; return DAE_ERR_COLLECTION_ALREADY_EXISTS; } // Make the new document daeDocument *newDocument = new daeDocument; // Make a domCOLLADA to be the root of this new document (this makes a reference so the domCOLLADA won't delete itself daeElementRef myCOLLADA = topMeta->create(); // Set the domCollada's document to this one myCOLLADA->setDocument(newDocument); newDocument->setDomRoot(myCOLLADA); // Set and resolve the document URI newDocument->getDocumentURI()->setURI(name); newDocument->getDocumentURI()->validate(); newDocument->setModified(true); // Add this document to the list. documents.push_back(newDocument); // If the user gave us a place to put the document, send it back to them. if (document) *document = newDocument; return DAE_OK; }
void HTTPWSTest::testPaste() { try { // Load a document and make it empty, then paste some text into it. const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt"); const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); Poco::Net::WebSocket socket = *connectLOKit(request, _response); sendTextFrame(socket, "load url=" + documentURL); sendTextFrame(socket, "status"); CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket)); sendTextFrame(socket, "uno .uno:SelectAll"); sendTextFrame(socket, "uno .uno:Delete"); // Paste some text into it. sendTextFrame(socket, "paste mimetype=text/plain;charset=utf-8\naaa bbb ccc"); // Check if the document contains the pasted text. sendTextFrame(socket, "uno .uno:SelectAll"); sendTextFrame(socket, "gettextselection mimetype=text/plain;charset=utf-8"); std::string selection; int flags; int n; do { char buffer[READ_BUFFER_SIZE]; n = socket.receiveFrame(buffer, sizeof(buffer), flags); std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << '\n'; if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n'; const std::string line = LOOLProtocol::getFirstLine(buffer, n); const std::string prefix = "textselectioncontent: "; if (line.find(prefix) == 0) { selection = line.substr(prefix.length()); break; } } } while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE); socket.shutdown(); CPPUNIT_ASSERT_EQUAL(std::string("aaa bbb ccc"), selection); Util::removeFile(documentPath); } catch (const Poco::Exception& exc) { CPPUNIT_FAIL(exc.displayText()); } }
void HTTPWSTest::testLargePaste() { try { // Load a document and make it empty. const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt"); const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); Poco::Net::WebSocket socket = *connectLOKit(request, _response); sendTextFrame(socket, "load url=" + documentURL); sendTextFrame(socket, "status"); CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket)); sendTextFrame(socket, "uno .uno:SelectAll"); sendTextFrame(socket, "uno .uno:Delete"); // Paste some text into it. std::ifstream documentStream(documentPath); std::string documentContents((std::istreambuf_iterator<char>(documentStream)), std::istreambuf_iterator<char>()); sendTextFrame(socket, "paste mimetype=text/html\n" + documentContents); // Check if the server is still alive. // This resulted first in a hang, as respose for the message never arrived, then a bit later in a Poco::TimeoutException. sendTextFrame(socket, "gettextselection mimetype=text/plain;charset=utf-8"); std::string selection; int flags; int n; do { char buffer[READ_BUFFER_SIZE]; n = socket.receiveFrame(buffer, sizeof(buffer), flags); if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { std::cout << "Received message length " << n << ": " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n'; std::string line = LOOLProtocol::getFirstLine(buffer, n); std::string prefix = "textselectioncontent: "; if (line.find(prefix) == 0) break; } } while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE); socket.shutdown(); Util::removeFile(documentPath); } catch (const Poco::Exception& exc) { CPPUNIT_FAIL(exc.displayText()); } }
void HTTPWSTest::testExcelLoad() { try { // Load a document and make it empty. const std::string documentPath = Util::getTempFilePath(TDOC, "timeline.xlsx"); const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); Poco::Net::WebSocket socket = *connectLOKit(request, _response); sendTextFrame(socket, "load url=" + documentURL); sendTextFrame(socket, "status"); CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket)); std::string status; int flags; int n; do { char buffer[READ_BUFFER_SIZE]; n = socket.receiveFrame(buffer, sizeof(buffer), flags); std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << '\n'; if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n'; const std::string line = LOOLProtocol::getFirstLine(buffer, n); std::string prefix = "status: "; if (line.find(prefix) == 0) { status = line.substr(prefix.length()); break; } } } while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE); socket.shutdown(); Util::removeFile(documentPath); // Expected format is something like 'type=text parts=2 current=0 width=12808 height=1142'. Poco::StringTokenizer tokens(status, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), tokens.count()); } catch (const Poco::Exception& exc) { CPPUNIT_FAIL(exc.displayText()); } }
void HTTPWSTest::testCloseAfterClose() { try { int bytes; int flags; char buffer[READ_BUFFER_SIZE]; // Load a document and get its status. const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt"); const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); Poco::Net::WebSocket socket = *connectLOKit(request, _response); sendTextFrame(socket, "load url=" + documentURL); sendTextFrame(socket, "status"); CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket)); // send normal socket shutdown socket.shutdown(); // 5 seconds timeout socket.setReceiveTimeout(5000000); // receive close frame handshake do { bytes = socket.receiveFrame(buffer, sizeof(buffer), flags); } while ((flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE); // no more messages is received. bytes = socket.receiveFrame(buffer, sizeof(buffer), flags); std::string received(buffer); std::cout << received << "received " << bytes << " flags "<< flags << std::endl; CPPUNIT_ASSERT_EQUAL(0, bytes); CPPUNIT_ASSERT_EQUAL(0, flags); } catch (const Poco::Exception& exc) { CPPUNIT_FAIL(exc.displayText()); } }
void HTTPWSTest::loadDoc(const std::string& documentURL) { try { // Load a document and get its status. Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); Poco::Net::WebSocket socket = *connectLOKit(request, _response); sendTextFrame(socket, "load url=" + documentURL); sendTextFrame(socket, "status"); CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket)); std::string status; int flags; int n; do { char buffer[READ_BUFFER_SIZE]; n = socket.receiveFrame(buffer, sizeof(buffer), flags); std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << std::endl; if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << std::endl; const std::string line = LOOLProtocol::getFirstLine(buffer, n); const std::string prefix = "status: "; if (line.find(prefix) == 0) { status = line.substr(prefix.length()); // Might be too strict, consider something flexible instread. CPPUNIT_ASSERT_EQUAL(std::string("type=text parts=1 current=0 width=12808 height=16408"), status); break; } } } while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE); socket.shutdown(); } catch (const Poco::Exception& exc) { CPPUNIT_FAIL(exc.displayText()); } }
daeInt daeSTLDatabase::createDocument(const char *name, daeElement* dom, daeDocument** document) { // If a document already exists with the same name, error if(isDocumentLoaded(name)) { if (document) *document = NULL; return DAE_ERR_COLLECTION_ALREADY_EXISTS; } // Make a new document daeDocument *newDocument = new daeDocument; // Create a Reference on the domCOLLADA passed into us newDocument->setDomRoot(dom); // Set the domCollada's document to this one //dom->setDocument(newDocument); // Set and resolve the document URI newDocument->getDocumentURI()->setURI(name); newDocument->getDocumentURI()->validate(); //insertElement( newDocument, dom ); newDocument->setModified(true); // Push the connection into the database documents.push_back(newDocument); if (document) *document = newDocument; //check if an already loaded document has external references to this one and resolve them. for ( unsigned int i = 0; i < documents.size(); i++ ) { if ( documents[i] != newDocument ) { documents[i]->resolveExternals( name ); } } return DAE_OK; }
#define GT_METHOD_NAME "saveDocument" void GTUtilsDocument::saveDocument(HI::GUITestOpStatus &os, const QString &documentName) { Runnable *popupChooser = new PopupChooser(os, QStringList() << ACTION_PROJECT__SAVE_DOCUMENT, GTGlobals::UseMouse); GTUtilsDialog::waitForDialog(os, popupChooser); GTMouseDriver::moveTo(os, GTUtilsProjectTreeView::getItemCenter(os, documentName) + QPoint(1,0));//dirty hack GTMouseDriver::click(os, Qt::RightButton); GTGlobals::sleep(500); } #undef GT_METHOD_NAME #define GT_METHOD_NAME "unloadDocument" void GTUtilsDocument::unloadDocument(HI::GUITestOpStatus &os, const QString &documentName, bool waitForMessageBox) { GT_CHECK_RESULT( isDocumentLoaded(os, documentName), "Document is not loaded", ); Runnable *popupChooser = new PopupChooser(os, QStringList() << ACTION_PROJECT__UNLOAD_SELECTED, GTGlobals::UseMouse); if (waitForMessageBox) { MessageBoxDialogFiller *filler = new MessageBoxDialogFiller(os, "Yes"); GTUtilsDialog::waitForDialog(os, filler); } GTUtilsDialog::waitForDialog(os, popupChooser); GTMouseDriver::moveTo(os, GTUtilsProjectTreeView::getItemCenter(os, documentName) + QPoint(1,0));//dirty hack GTMouseDriver::click(os, Qt::RightButton); GTGlobals::sleep(500); } #undef GT_METHOD_NAME
void HTTPWSTest::testImpressPartCountChanged() { try { // Load a document const std::string documentPath = Util::getTempFilePath(TDOC, "insert-delete.odp"); const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); Poco::Net::WebSocket socket = *connectLOKit(request, _response); sendTextFrame(socket, "load url=" + documentURL); sendTextFrame(socket, "status"); CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket)); // check total slides 1 sendTextFrame(socket, "status"); std::string response; getResponseMessage(socket, "status:", response, true); CPPUNIT_ASSERT_MESSAGE("did not receive a status: message as expected", !response.empty()); { Poco::StringTokenizer tokens(response, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), tokens.count()); // Expected format is something like 'type= parts= current= width= height='. const std::string prefix = "parts="; const int totalParts = std::stoi(tokens[1].substr(prefix.size())); CPPUNIT_ASSERT_EQUAL(1, totalParts); } /* FIXME partscountchanged: was removed, update accordingly // insert 10 slides for (unsigned it = 1; it <= 10; it++) { sendTextFrame(socket, "uno .uno:InsertPage"); getResponseMessage(socket, "partscountchanged:", response, false); CPPUNIT_ASSERT_MESSAGE("did not receive a partscountchanged: message as expected", !response.empty()); { Poco::JSON::Parser parser; Poco::Dynamic::Var result = parser.parse(response); Poco::DynamicStruct values = *result.extract<Poco::JSON::Object::Ptr>(); CPPUNIT_ASSERT(values["action"] == "PartInserted"); } } // delete 10 slides for (unsigned it = 1; it <= 10; it++) { sendTextFrame(socket, "uno .uno:DeletePage"); getResponseMessage(socket, "partscountchanged:", response, false); CPPUNIT_ASSERT_MESSAGE("did not receive a partscountchanged: message as expected", !response.empty()); { Poco::JSON::Parser parser; Poco::Dynamic::Var result = parser.parse(response); Poco::DynamicStruct values = *result.extract<Poco::JSON::Object::Ptr>(); CPPUNIT_ASSERT(values["action"] == "PartDeleted"); } } // undo delete slides for (unsigned it = 1; it <= 10; it++) { sendTextFrame(socket, "uno .uno:Undo"); getResponseMessage(socket, "partscountchanged:", response, false); CPPUNIT_ASSERT_MESSAGE("did not receive a partscountchanged: message as expected", !response.empty()); { Poco::JSON::Parser parser; Poco::Dynamic::Var result = parser.parse(response); Poco::DynamicStruct values = *result.extract<Poco::JSON::Object::Ptr>(); CPPUNIT_ASSERT(values["action"] == "PartInserted"); } } // redo inserted slides for (unsigned it = 1; it <= 10; it++) { sendTextFrame(socket, "uno .uno:Redo"); getResponseMessage(socket, "partscountchanged:", response, false); CPPUNIT_ASSERT_MESSAGE("did not receive a partscountchanged: message as expected", !response.empty()); { Poco::JSON::Parser parser; Poco::Dynamic::Var result = parser.parse(response); Poco::DynamicStruct values = *result.extract<Poco::JSON::Object::Ptr>(); CPPUNIT_ASSERT(values["action"] == "PartDeleted"); } } */ socket.shutdown(); Util::removeFile(documentPath); } catch (const Poco::Exception& exc) { CPPUNIT_FAIL(exc.displayText()); } }
void HTTPWSTest::testPasswordProtectedDocumentWithCorrectPassword() { try { const std::string documentPath = Util::getTempFilePath(TDOC, "password-protected.ods"); const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); Poco::Net::WebSocket socket = *connectLOKit(request, _response); // Send a load request with correct password sendTextFrame(socket, "load url=" + documentURL + " password=1"); CPPUNIT_ASSERT_MESSAGE("cannot load the document with correct password " + documentURL, isDocumentLoaded(socket)); socket.shutdown(); Util::removeFile(documentPath); } catch (const Poco::Exception& exc) { CPPUNIT_FAIL(exc.displayText()); } }
void HTTPWSTest::testReloadWhileDisconnecting() { const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt"); const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); int kitcount = -1; try { // Load a document and get its status. Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); Poco::Net::WebSocket socket = *connectLOKit(request, _response); sendTextFrame(socket, "load url=" + documentURL); CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket)); sendTextFrame(socket, "uno .uno:SelectAll"); sendTextFrame(socket, "uno .uno:Delete"); sendTextFrame(socket, "paste mimetype=text/plain;charset=utf-8\naaa bbb ccc"); kitcount = countLoolKitProcesses(); // Shutdown abruptly. socket.shutdown(); } catch (const Poco::Exception& exc) { CPPUNIT_FAIL(exc.displayText()); } std::cout << "Loading again." << std::endl; try { // Load the same document and check that the last changes (pasted text) is saved. Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); Poco::Net::WebSocket socket = *connectLOKit(request, _response); sendTextFrame(socket, "load url=" + documentURL); sendTextFrame(socket, "status"); CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket)); // Should have no new instances. CPPUNIT_ASSERT_EQUAL(kitcount, countLoolKitProcesses()); // Check if the document contains the pasted text. sendTextFrame(socket, "uno .uno:SelectAll"); sendTextFrame(socket, "gettextselection mimetype=text/plain;charset=utf-8"); std::string selection; int flags; int n; do { char buffer[READ_BUFFER_SIZE]; n = socket.receiveFrame(buffer, sizeof(buffer), flags); std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << '\n'; if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n'; const std::string line = LOOLProtocol::getFirstLine(buffer, n); if (line.find("editlock: ") == 0) { // We must have the editlock, otherwise we aren't alone. CPPUNIT_ASSERT_EQUAL(std::string("editlock: 1"), line); } const std::string prefix = "textselectioncontent: "; if (line.find(prefix) == 0) { selection = line.substr(prefix.length()); break; } } } while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE); socket.shutdown(); Util::removeFile(documentPath); CPPUNIT_ASSERT_EQUAL(std::string("aaa bbb ccc"), selection); } catch (const Poco::Exception& exc) { CPPUNIT_FAIL(exc.displayText()); } }