void testReadWriteEmptyArchive() { std::string archiveName = "emptyArchive.abc"; { AO::WriteArchive w; ABCA::MetaData m; m.set("Bleep", "bloop"); m.set("eep", ""); m.set("potato", "salad"); m.set("geoScope", "tasty"); ABCA::ArchiveWriterPtr a = w(archiveName, m); ABCA::ObjectWriterPtr archive = a->getTop(); TESTING_ASSERT(archive->getFullName() == "/"); Alembic::AbcCoreOgawa::ReadArchive r; // can't read an already open archive (for now) TESTING_ASSERT_THROW(r( archiveName ), Alembic::Util::Exception); } { AO::ReadArchive r; ABCA::ArchiveReaderPtr a = r( archiveName ); ABCA::ObjectReaderPtr archive = a->getTop(); ABCA::MetaData m = archive->getHeader().getMetaData(); TESTING_ASSERT(m.get("Bleep") == "bloop"); TESTING_ASSERT(m.get("eep") == ""); TESTING_ASSERT(m.get("potato") == "salad"); TESTING_ASSERT(m.get("geoScope") == "tasty"); TESTING_ASSERT(archive->getName() == "ABC"); TESTING_ASSERT(archive->getFullName() == "/"); TESTING_ASSERT(archive->getParent() == NULL); TESTING_ASSERT(archive->getNumChildren() == 0); // even though we didn't write anything make sure we intrincially have // the default sampling TESTING_ASSERT(a->getNumTimeSamplings() == 1); TESTING_ASSERT(*(a->getTimeSampling(0)) == ABCA::TimeSampling()); TESTING_ASSERT(a->getMaxNumSamplesForTimeSamplingIndex(0) == 0); ABCA::CompoundPropertyReaderPtr parent = archive->getProperties(); TESTING_ASSERT(parent->getNumProperties() == 0); // get it again to make sure we clean ourselves up properly AO::ReadArchive r2; ABCA::ArchiveReaderPtr a2 = r2( archiveName ); ABCA::ObjectReaderPtr archive2 = a2->getTop(); ABCA::CompoundPropertyReaderPtr p2 = archive2->getProperties(); TESTING_ASSERT(p2->getNumProperties() == 0); } }
void testReadWriteEmptyArchive() { std::string archiveName = "emptyArchive.abc"; { A5::WriteArchive w; ABCA::MetaData m; m.set("Bleep", "bloop"); m.set("eep", ""); m.set("potato", "salad"); m.set("geoScope", "tasty"); ABCA::ArchiveWriterPtr a = w(archiveName, m); ABCA::ObjectWriterPtr archive = a->getTop(); TESTING_ASSERT(archive->getFullName() == "/"); // use this to get current reporting mechanism, then supress it // since we expect to see H5F errors because we will be trying to open // a file that is already open for writing. H5E_auto_t func; void * client_data; H5Eget_auto2(H5E_DEFAULT, &func, &client_data); H5Eset_auto2(H5E_DEFAULT, NULL, NULL); // can't write an already open archive TESTING_ASSERT_THROW(w(archiveName, ABCA::MetaData()), Alembic::Util::Exception); Alembic::AbcCoreHDF5::ReadArchive r; // can't read an already open archive TESTING_ASSERT_THROW(r( archiveName ), Alembic::Util::Exception); // turn the error reporting back on for later tests H5Eset_auto2(H5E_DEFAULT, func, client_data); } { A5::ReadArchive r; ABCA::ArchiveReaderPtr a = r( archiveName ); ABCA::ObjectReaderPtr archive = a->getTop(); ABCA::MetaData m = archive->getHeader().getMetaData(); TESTING_ASSERT(m.get("Bleep") == "bloop"); TESTING_ASSERT(m.get("eep") == ""); TESTING_ASSERT(m.get("potato") == "salad"); TESTING_ASSERT(m.get("geoScope") == "tasty"); TESTING_ASSERT(archive->getName() == "ABC"); TESTING_ASSERT(archive->getFullName() == "/"); TESTING_ASSERT(archive->getParent() == NULL); TESTING_ASSERT(archive->getNumChildren() == 0); // even though we didn't write anything make sure we intrincially have // the default sampling TESTING_ASSERT(a->getNumTimeSamplings() == 1); TESTING_ASSERT(*(a->getTimeSampling(0)) == ABCA::TimeSampling()); TESTING_ASSERT(a->getMaxNumSamplesForTimeSamplingIndex(0) == 0); ABCA::CompoundPropertyReaderPtr parent = archive->getProperties(); TESTING_ASSERT(parent->getNumProperties() == 0); // get it again to make sure we clean ourselves up properly A5::ReadArchive r2; ABCA::ArchiveReaderPtr a2 = r2( archiveName ); ABCA::ObjectReaderPtr archive2 = a2->getTop(); ABCA::CompoundPropertyReaderPtr p2 = archive2->getProperties(); TESTING_ASSERT(p2->getNumProperties() == 0); } }
void testReadWriteTimeSamplingArchive() { std::string archiveName = "timeSampsArchive.abc"; { A5::WriteArchive w; ABCA::ArchiveWriterPtr a = w(archiveName, ABCA::MetaData()); // we always have 1 TESTING_ASSERT(a->getNumTimeSamplings() == 1); // getting a time sampling that doesn't exist should throw TESTING_ASSERT_THROW(a->getTimeSampling(43), Alembic::Util::Exception); TESTING_ASSERT( a->getMaxNumSamplesForTimeSamplingIndex(43) == INDEX_UNKNOWN); // first one is the default time sampling TESTING_ASSERT(*(a->getTimeSampling(0)) == ABCA::TimeSampling()); TESTING_ASSERT(a->getMaxNumSamplesForTimeSamplingIndex(0) == 0); std::vector< double > samps; // uniform sampling starts at second 34, 24fps samps.push_back(34.0); ABCA::TimeSampling ts(ABCA::TimeSamplingType(1.0/24.0), samps); uint32_t index = a->addTimeSampling(ts); TESTING_ASSERT(index == 1); // even though we add the same thing, we get the same index back index = a->addTimeSampling(ts); TESTING_ASSERT(index == 1); // cyclic sampling example samps.push_back(34.25); samps.push_back(34.5); ts = ABCA::TimeSampling(ABCA::TimeSamplingType(3, 1.0), samps); index = a->addTimeSampling(ts); TESTING_ASSERT(index == 2); // normally we wouldn't ever call this directly, call it here // for testing purposes only a->setMaxNumSamplesForTimeSamplingIndex(2, 42); // really weird acyclic example samps.push_back(300.0); samps.push_back(500.0); ts = ABCA::TimeSampling( ABCA::TimeSamplingType(ABCA::TimeSamplingType::kAcyclic), samps); index = a->addTimeSampling(ts); TESTING_ASSERT(index == 3); // now we should have 4 TESTING_ASSERT(a->getNumTimeSamplings() == 4); } { A5::ReadArchive r; ABCA::ArchiveReaderPtr a = r( archiveName ); TESTING_ASSERT(a->getNumTimeSamplings() == 4); // first one is the default time sampling TESTING_ASSERT(*(a->getTimeSampling(0)) == ABCA::TimeSampling()); std::vector< double > samps; // uniform sampling starts at second 34, 24fps samps.push_back(34.0); ABCA::TimeSampling ts(ABCA::TimeSamplingType(1.0/24.0), samps); TESTING_ASSERT( ts == *(a->getTimeSampling(1)) ); TESTING_ASSERT( a->getMaxNumSamplesForTimeSamplingIndex(1) == 0 ); // cyclic sampling example samps.push_back(34.25); samps.push_back(34.5); ts = ABCA::TimeSampling(ABCA::TimeSamplingType(3, 1.0), samps); TESTING_ASSERT( ts == *(a->getTimeSampling(2)) ); TESTING_ASSERT( a->getMaxNumSamplesForTimeSamplingIndex(2) == 42 ); // really weird acyclic example samps.push_back(300.0); samps.push_back(500.0); ts = ABCA::TimeSampling( ABCA::TimeSamplingType(ABCA::TimeSamplingType::kAcyclic), samps); TESTING_ASSERT( ts == *(a->getTimeSampling(3)) ); TESTING_ASSERT( a->getMaxNumSamplesForTimeSamplingIndex(3) == 0 ); } }