From ae897d80e4c96eb497cc4aea466c9915a9352fde Mon Sep 17 00:00:00 2001 From: zhoub Date: Fri, 29 Mar 2013 14:55:34 +0800 Subject: [PATCH] Added and fixed the all unit tests. --- openvdb_1_0_0_library/CMakeLists.txt | 6 ++++++ openvdb_1_0_0_library/openvdb/CMakeLists.txt | 12 ++++++++---- openvdb_1_0_0_library/openvdb/metadata/MetaMap.h | 4 +++- .../openvdb/metadata/Metadata.h | 5 +++++ .../openvdb/metadata/StringMetadata.h | 7 +++++-- .../openvdb/unittest/TestFile.cc | 16 +++++++++------- .../openvdb/unittest/TestParticlesToLevelSet.cc | 2 +- .../openvdb/unittest/TestTree.cc | 2 +- .../openvdb/unittest/TestTreeCombine.cc | 14 +++++++------- openvdb_1_0_0_library/openvdb/util/Name.h | 8 ++++++-- 10 files changed, 51 insertions(+), 25 deletions(-) diff --git a/openvdb_1_0_0_library/CMakeLists.txt b/openvdb_1_0_0_library/CMakeLists.txt index 762c62e..f048902 100755 --- a/openvdb_1_0_0_library/CMakeLists.txt +++ b/openvdb_1_0_0_library/CMakeLists.txt @@ -7,3 +7,9 @@ SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON) SET(OPENVDB_DIR ${CMAKE_SOURCE_DIR}) ADD_SUBDIRECTORY(openvdb) + +SET(OPENVDB_INSTALL_BINARY_DIR "${CMAKE_INSTALL_PREFIX}/bin") +SET(OPENVDB_INSTALL_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/lib") +SET(OPENVDB_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include") +SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OPENVDB_INSTALL_BINARY_DIR}) +SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OPENVDB_INSTALL_LIBRARY_DIR}) diff --git a/openvdb_1_0_0_library/openvdb/CMakeLists.txt b/openvdb_1_0_0_library/openvdb/CMakeLists.txt index e89ddf0..15f37a2 100755 --- a/openvdb_1_0_0_library/openvdb/CMakeLists.txt +++ b/openvdb_1_0_0_library/openvdb/CMakeLists.txt @@ -65,17 +65,21 @@ FILE(GLOB OPENVDB_UTIL_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/util/*.h) SOURCE_GROUP(Util FILES ${OPENVDB_UTIL_SOURCE_FILES} ${OPENVDB_UTIL_HEADER_FILES}) -ADD_DEFINITIONS(-DOPENVDB_PRIVATE) - IF(MSVC) ADD_DEFINITIONS(-DNOMINMAX) ENDIF() -ADD_LIBRARY(OpenVDB SHARED ${OPENVDB_SOURCE_FILES} ${OPENVDB_HEADER_FILES} +ADD_DEFINITIONS(-DOPENVDB_PRIVATE) + +ADD_LIBRARY(vdb SHARED ${OPENVDB_SOURCE_FILES} ${OPENVDB_HEADER_FILES} ${OPENVDB_IO_SOURCE_FILES} ${OPENVDB_IO_HEADER_FILES} ${OPENVDB_MATH_SOURCE_FILES} ${OPENVDB_MATH_HEADER_FILES} ${OPENVDB_METADATA_SOURCE_FILES} ${OPENVDB_MATADATA_HEADER_FILES} ${OPENVDB_TOOLS_SOURCE_FILES} ${OPENVDB_TOOLS_HEADER_FILES} ${OPENVDB_TREE_SOURCE_FILES} ${OPENVDB_TREE_HEADER_FILES} ${OPENVDB_UTIL_SOURCE_FILES} ${OPENVDB_UTIL_HEADER_FILES}) -TARGET_LINK_LIBRARIES(OpenVDB Half tbb ${ZLIB_LIBRARIES}) +TARGET_LINK_LIBRARIES(vdb Half tbb ${ZLIB_LIBRARIES}) + +IF(DEFINED BUILD_UNITTEST AND BUILD_UNITTEST) + ADD_SUBDIRECTORY(unittest) +ENDIF() diff --git a/openvdb_1_0_0_library/openvdb/metadata/MetaMap.h b/openvdb_1_0_0_library/openvdb/metadata/MetaMap.h index 71734a6..25c18dc 100755 --- a/openvdb_1_0_0_library/openvdb/metadata/MetaMap.h +++ b/openvdb_1_0_0_library/openvdb/metadata/MetaMap.h @@ -214,7 +214,9 @@ MetaMap::getValidTypedMetadata(const Name &name) const // cast. This is slower than doing a dynamic_pointer_cast, but is safer when // pointers cross dso boundaries. typename TypedMetadata::Ptr m; - if (iter->second->typeName() == TypedMetadata::staticTypeName()) { + const std::string &typeName = iter->second->typeName(); + const std::string &staticTypeName = TypedMetadata::staticTypeName(); + if (typeName == staticTypeName) { m = boost::static_pointer_cast, Metadata>(iter->second); } if (!m) OPENVDB_THROW(TypeError, "Invalid type for metadata " << name); diff --git a/openvdb_1_0_0_library/openvdb/metadata/Metadata.h b/openvdb_1_0_0_library/openvdb/metadata/Metadata.h index d579bb6..736a0cf 100755 --- a/openvdb_1_0_0_library/openvdb/metadata/Metadata.h +++ b/openvdb_1_0_0_library/openvdb/metadata/Metadata.h @@ -393,8 +393,13 @@ operator<<(std::ostream& ostr, const Metadata& metadata) typedef TypedMetadata BoolMetadata; typedef TypedMetadata DoubleMetadata; typedef TypedMetadata FloatMetadata; +#if _MSC_VER < 1600 typedef TypedMetadata Int32Metadata; typedef TypedMetadata Int64Metadata; +#else +typedef TypedMetadata Int32Metadata; +typedef TypedMetadata Int64Metadata; +#endif typedef TypedMetadata Vec2DMetadata; typedef TypedMetadata Vec2IMetadata; typedef TypedMetadata Vec2SMetadata; diff --git a/openvdb_1_0_0_library/openvdb/metadata/StringMetadata.h b/openvdb_1_0_0_library/openvdb/metadata/StringMetadata.h index 2b0a2bf..c4aefed 100755 --- a/openvdb_1_0_0_library/openvdb/metadata/StringMetadata.h +++ b/openvdb_1_0_0_library/openvdb/metadata/StringMetadata.h @@ -54,8 +54,11 @@ template<> inline void StringMetadata::readValue(std::istream& is, Index32 size) { - mValue.resize(size, '\0'); - is.read(&mValue[0], size); + if (size) + { + mValue.resize(size, '\0'); + is.read(&mValue[0], size); + } } template<> diff --git a/openvdb_1_0_0_library/openvdb/unittest/TestFile.cc b/openvdb_1_0_0_library/openvdb/unittest/TestFile.cc index 5efd1ab..cb12985 100755 --- a/openvdb_1_0_0_library/openvdb/unittest/TestFile.cc +++ b/openvdb_1_0_0_library/openvdb/unittest/TestFile.cc @@ -181,13 +181,15 @@ TestFile::testWriteGrid() // Write out the grid. file.writeGrid(gd, grid, ostr, /*seekable=*/true); + const std::string ostr_content = ostr.str(); + CPPUNIT_ASSERT(gd.getGridPos() != 0); CPPUNIT_ASSERT(gd.getBlockPos() != 0); CPPUNIT_ASSERT(gd.getEndPos() != 0); // Read in the grid descriptor. GridDescriptor gd2; - std::istringstream istr(ostr.str(), std::ios_base::binary); + std::istringstream istr(ostr_content, std::ios_base::binary); // Since the input is only a fragment of a VDB file (in particular, // it doesn't have a header), set the file format version number explicitly. @@ -724,7 +726,7 @@ TestFile::testGridNaming() gridVec[n]->insertMeta("index", Int32Metadata(n)); } - const char* filename = "/tmp/testGridNaming.vdb2"; + const char* filename = "testGridNaming.vdb2"; boost::shared_ptr scopedFile(filename, ::remove); // Test first with grid instancing disabled, then with instancing enabled. @@ -849,7 +851,7 @@ TestFile::testEmptyFile() using namespace openvdb; using namespace openvdb::io; - const char* filename = "/tmp/testEmptyFile.vdb2"; + const char* filename = "testEmptyFile.vdb2"; boost::shared_ptr scopedFile(filename, ::remove); { @@ -879,7 +881,7 @@ TestFile::testEmptyGridIO() typedef Int32Grid GridType; typedef GridType::TreeType TreeType; - const char* filename = "/tmp/something.vdb2"; + const char* filename = "something.vdb2"; boost::shared_ptr scopedFile(filename, ::remove); File file(filename); @@ -1308,7 +1310,7 @@ TestFile::testReadGridMetadata() openvdb::initialize(); - const char* filename = "/tmp/testReadGridMetadata.vdb2"; + const char* filename = "testReadGridMetadata.vdb2"; boost::shared_ptr scopedFile(filename, ::remove); // Create grids @@ -1782,7 +1784,7 @@ TestFile::testNameIterator() // Register types. openvdb::initialize(); - const char* filename = "/tmp/testNameIterator.vdb2"; + const char* filename = "testNameIterator.vdb2"; boost::shared_ptr scopedFile(filename, ::remove); // Write the grids out to a file. @@ -1854,7 +1856,7 @@ TestFile::testCompression() grids.push_back(lsGrid); grids.push_back(fogGrid); - const char* filename = "/tmp/testCompression.vdb2"; + const char* filename = "testCompression.vdb2"; boost::shared_ptr scopedFile(filename, ::remove); size_t uncompressedSize = 0; diff --git a/openvdb_1_0_0_library/openvdb/unittest/TestParticlesToLevelSet.cc b/openvdb_1_0_0_library/openvdb/unittest/TestParticlesToLevelSet.cc index 571339b..eab91a2 100755 --- a/openvdb_1_0_0_library/openvdb/unittest/TestParticlesToLevelSet.cc +++ b/openvdb_1_0_0_library/openvdb/unittest/TestParticlesToLevelSet.cc @@ -51,7 +51,7 @@ class TestParticlesToLevelSet: public CppUnit::TestFixture grid->setName("TestParticlesToLevelSet"); openvdb::GridPtrVec grids; grids.push_back(grid); - openvdb::io::File file("/tmp/" + fileName + ".vdb"); + openvdb::io::File file(fileName + ".vdb"); file.write(grids); file.close(); } diff --git a/openvdb_1_0_0_library/openvdb/unittest/TestTree.cc b/openvdb_1_0_0_library/openvdb/unittest/TestTree.cc index 0a0de52..a95b16a 100755 --- a/openvdb_1_0_0_library/openvdb/unittest/TestTree.cc +++ b/openvdb_1_0_0_library/openvdb/unittest/TestTree.cc @@ -808,7 +808,7 @@ TestTree::testIterators() void TestTree::testIO() { - const char* filename = "/tmp/test.dbg"; + const char* filename = "test.dbg"; boost::shared_ptr scopedFile(filename, ::remove); { ValueType background=5.0f; diff --git a/openvdb_1_0_0_library/openvdb/unittest/TestTreeCombine.cc b/openvdb_1_0_0_library/openvdb/unittest/TestTreeCombine.cc index 86dece1..83ed7b2 100755 --- a/openvdb_1_0_0_library/openvdb/unittest/TestTreeCombine.cc +++ b/openvdb_1_0_0_library/openvdb/unittest/TestTreeCombine.cc @@ -625,7 +625,7 @@ TestTreeCombine::testCsg() timer.start(); #endif - const std::string testDir("/work/rd/fx_tools/vdb_unittest/TestGridCombine::testCsg/"); + const std::string testDir("./"); smallTree1 = Local::readFile(testDir + "small1.vdb2 LevelSet"); CPPUNIT_ASSERT(smallTree1.get() != NULL); smallTree2 = Local::readFile(testDir + "small2.vdb2 Cylinder"); @@ -644,30 +644,30 @@ TestTreeCombine::testCsg() #endif refTree = Local::readFile(testDir + "small_union.vdb2"); outTree = visitCsg(*smallTree1, *smallTree2, *refTree, Local::visitorUnion); - //Local::writeFile(outTree, "/tmp/small_union_out.vdb2"); + //Local::writeFile(outTree, "small_union_out.vdb2"); refTree = Local::readFile(testDir + "large_union.vdb2"); outTree = visitCsg(*largeTree1, *largeTree2, *refTree, Local::visitorUnion); - //Local::writeFile(outTree, "/tmp/large_union_out.vdb2"); + //Local::writeFile(outTree, "large_union_out.vdb2"); #if TEST_CSG_VERBOSE std::cerr << "\n\n"; #endif refTree = Local::readFile(testDir + "small_intersection.vdb2"); outTree = visitCsg(*smallTree1, *smallTree2, *refTree, Local::visitorIntersect); - //Local::writeFile(outTree, "/tmp/small_intersection_out.vdb2"); + //Local::writeFile(outTree, "small_intersection_out.vdb2"); refTree = Local::readFile(testDir + "large_intersection.vdb2"); outTree = visitCsg(*largeTree1, *largeTree2, *refTree, Local::visitorIntersect); - //Local::writeFile(outTree, "/tmp/large_intersection_out.vdb2"); + //Local::writeFile(outTree, "large_intersection_out.vdb2"); #if TEST_CSG_VERBOSE std::cerr << "\n\n"; #endif refTree = Local::readFile(testDir + "small_difference.vdb2"); outTree = visitCsg(*smallTree1, *smallTree2, *refTree, Local::visitorDiff); - //Local::writeFile(outTree, "/tmp/small_difference_out.vdb2"); + //Local::writeFile(outTree, "small_difference_out.vdb2"); refTree = Local::readFile(testDir + "large_difference.vdb2"); outTree = visitCsg(*largeTree1, *largeTree2, *refTree, Local::visitorDiff); - //Local::writeFile(outTree, "/tmp/large_difference_out.vdb2"); + //Local::writeFile(outTree, "large_difference_out.vdb2"); } diff --git a/openvdb_1_0_0_library/openvdb/util/Name.h b/openvdb_1_0_0_library/openvdb/util/Name.h index 51cf919..a670c0d 100755 --- a/openvdb_1_0_0_library/openvdb/util/Name.h +++ b/openvdb_1_0_0_library/openvdb/util/Name.h @@ -47,9 +47,13 @@ inline Name readString(std::istream& is) { uint32_t size; + std::string buffer; is.read(reinterpret_cast(&size), sizeof(uint32_t)); - std::string buffer(size, ' '); - is.read(&buffer[0], size); + if (size) + { + buffer.resize(size, ' '); + is.read(&buffer[0], size); + } return buffer; }