UT_Error IE_Exp_EPUB::_writeDocument() { UT_Error errOptions = doOptions(); if (errOptions == UT_SAVE_CANCELLED) //see Bug 10840 { return UT_SAVE_CANCELLED; } else if (errOptions != UT_OK) { return UT_ERROR; } m_root = gsf_outfile_zip_new(getFp(), NULL); if (m_root == NULL) { UT_DEBUGMSG(("ZIP output is null\n")); return UT_ERROR; } m_oebps = gsf_outfile_new_child(m_root, "OEBPS", TRUE); if (m_oebps == NULL) { UT_DEBUGMSG(("Can`t create oebps output object\n")); return UT_ERROR; } // mimetype must a first file in archive GsfOutput *mimetype = gsf_outfile_new_child_full(m_root, "mimetype", FALSE, "compression-level", 0, NULL); gsf_output_write(mimetype, strlen(EPUB_MIMETYPE), (const guint8*) EPUB_MIMETYPE); gsf_output_close(mimetype); // We need to create temporary directory to which // HTML plugin will export our document m_baseTempDir = UT_go_filename_to_uri(g_get_tmp_dir()); m_baseTempDir += G_DIR_SEPARATOR_S; // To generate unique directory name we`ll use document UUID m_baseTempDir += getDoc()->getDocUUIDString(); // We should delete any previous temporary data for this document to prevent // odd files appearing in the container UT_go_file_remove(m_baseTempDir.c_str(), NULL); UT_go_directory_create(m_baseTempDir.c_str(), NULL); if (writeContainer() != UT_OK) { UT_DEBUGMSG(("Failed to write container\n")); return UT_ERROR; } if (writeStructure() != UT_OK) { UT_DEBUGMSG(("Failed to write document structure\n")); return UT_ERROR; } if (writeNavigation() != UT_OK) { UT_DEBUGMSG(("Failed to write navigation\n")); return UT_ERROR; } if (package() != UT_OK) { UT_DEBUGMSG(("Failed to package document\n")); return UT_ERROR; } gsf_output_close(m_oebps); gsf_output_close(GSF_OUTPUT(m_root)); // After doing all job we should delete temporary files UT_go_file_remove(m_baseTempDir.c_str(), NULL); return UT_OK; }
void NavigationSeriesTest::navigationTest() { CPPUNIT_ASSERT(m_series); ::fwMedData::NavigationSeries::ContainerType positions = { {0., {-514.1606513019431, -94.68116795798758, 979.3785055174628}} }; ::fwMedData::NavigationSeries::ContainerType move = { {0., {0.897820633950464, 0.13607544320686907, -1.2769419285130967}}, {1421.375, {2.322431935080602, 0.33708203932328956, -3.734284956660633}}, {2114.208, {2.43713135678714, -0.049220088700801926, -3.266794030753196}}, {3377.9159999999997, {0., 0., 0.}}, {4027.6536502546687, {-3.964310130780936, 0.08006285575503613, 5.313864037415808}}, {6237.149579831932, {0., 0., 0.}}, {6500.074702886248, {-0.8058588959846187, 1.6088833889257592, -2.2406369414514837}}, {7616.651952461799, {0.15881288125106394, 0.9634983958585909, -3.792280054764281}}, {9291.517826825127, {15.00876504273313, 1.948698699541007, 9.621351972786318}}, {10328.339558573854, {8.746762102220163, -1.3252231011236748, 0.40990799919194243}}, {11344.944, {3.107379091978582, 0.24758149132857085, -1.7704233405817775}}, {13717.94906621392, {-14.868514648384936, -0.06864726970614742, -1.8512522029189045}}, {14874.404074702887, {-2.1505985395333633, 0.0025699595738454374, -0.5800507110513734}}, {15472.570458404074, {0.5463244285267206, -0.009449336194383946, -4.067785389892101}}, {18862.179966044143, {0., 0., 0.}}, {20576.923599320886, {-1.4763543428185393, 0.6215147468157091, 4.983670944496179}}, {23208.855687606112, {0., 0., 0.}} }; ::fwMedData::NavigationSeries::ContainerType lookAt = { {0., {216.48659596562175, -109.43725495319805, 0.}}, {4027.6536502546687, {206.6271751068543, -90.3143606602177, -7.6435594203111314}}, {6500.074702886248, {206.6271751068543, -90.3143606602177, -7.6435594203111314}} }; // Test add API for(const auto& elt : positions) { m_series->addPosition(elt.first, elt.second); } for(const auto& elt : move) { m_series->addMove(elt.first, elt.second); } for(const auto& elt : lookAt) { m_series->addLookAt(elt.first, elt.second); } CPPUNIT_ASSERT_EQUAL(positions.size(), m_series->getPositionMap().size()); CPPUNIT_ASSERT_EQUAL(move.size(), m_series->getMoveMap().size()); CPPUNIT_ASSERT_EQUAL(lookAt.size(), m_series->getLookAtMap().size()); CPPUNIT_ASSERT(positions == m_series->getPositionMap()); CPPUNIT_ASSERT(move == m_series->getMoveMap()); CPPUNIT_ASSERT(lookAt == m_series->getLookAtMap()); // Create Path const ::boost::filesystem::path path = ::fwTools::System::getTemporaryFolder() / "navigationtest"; ::boost::filesystem::create_directories(path); const std::string jsonzFile = "NavigationSeriesTest.jsonz"; ::fwAtoms::Object::sptr atom1 = ::fwAtomConversion::convert(m_series); writeNavigation((path/jsonzFile), atom1); ::fwAtoms::Object::sptr atom2 = readNavigation(path/jsonzFile); ::fwData::Object::sptr object; ::fwMedData::NavigationSeries::sptr navigationSeries; object = ::fwAtomConversion::convert(atom2, ::fwAtomConversion::AtomVisitor::ChangePolicy()); navigationSeries = ::fwMedData::NavigationSeries::dynamicCast(object); // Test get API CPPUNIT_ASSERT(navigationSeries); CPPUNIT_ASSERT_EQUAL(positions.size(), navigationSeries->getPositionMap().size()); CPPUNIT_ASSERT_EQUAL(move.size(), navigationSeries->getMoveMap().size()); CPPUNIT_ASSERT_EQUAL(lookAt.size(), navigationSeries->getLookAtMap().size()); CPPUNIT_ASSERT(positions == navigationSeries->getPositionMap()); CPPUNIT_ASSERT(move == navigationSeries->getMoveMap()); CPPUNIT_ASSERT(lookAt == navigationSeries->getLookAtMap()); // Test erase API double timestamp = positions.begin()->first; navigationSeries->erasePosition(timestamp); CPPUNIT_ASSERT(navigationSeries->getPositionMap().find(timestamp) == navigationSeries->getPositionMap().end()); timestamp = move.begin()->first; navigationSeries->eraseMove(timestamp); CPPUNIT_ASSERT(navigationSeries->getMoveMap().find(timestamp) == navigationSeries->getMoveMap().end()); timestamp = lookAt.begin()->first; navigationSeries->eraseLookAt(timestamp); CPPUNIT_ASSERT(navigationSeries->getLookAtMap().find(timestamp) == navigationSeries->getLookAtMap().end()); // Test clear API navigationSeries->clearPosition(); CPPUNIT_ASSERT(navigationSeries->getPositionMap().empty()); navigationSeries->clearMove(); CPPUNIT_ASSERT(navigationSeries->getMoveMap().empty()); navigationSeries->clearLookAt(); CPPUNIT_ASSERT(navigationSeries->getLookAtMap().empty()); }