Skip to content

Commit

Permalink
Added and fixed the all unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoub committed Mar 29, 2013
1 parent 0df570c commit ae897d8
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 25 deletions.
6 changes: 6 additions & 0 deletions openvdb_1_0_0_library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
12 changes: 8 additions & 4 deletions openvdb_1_0_0_library/openvdb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 3 additions & 1 deletion openvdb_1_0_0_library/openvdb/metadata/MetaMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>::Ptr m;
if (iter->second->typeName() == TypedMetadata<T>::staticTypeName()) {
const std::string &typeName = iter->second->typeName();
const std::string &staticTypeName = TypedMetadata<T>::staticTypeName();
if (typeName == staticTypeName) {
m = boost::static_pointer_cast<TypedMetadata<T>, Metadata>(iter->second);
}
if (!m) OPENVDB_THROW(TypeError, "Invalid type for metadata " << name);
Expand Down
5 changes: 5 additions & 0 deletions openvdb_1_0_0_library/openvdb/metadata/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,13 @@ operator<<(std::ostream& ostr, const Metadata& metadata)
typedef TypedMetadata<bool> BoolMetadata;
typedef TypedMetadata<double> DoubleMetadata;
typedef TypedMetadata<float> FloatMetadata;
#if _MSC_VER < 1600
typedef TypedMetadata<boost::int32_t> Int32Metadata;
typedef TypedMetadata<boost::int64_t> Int64Metadata;
#else
typedef TypedMetadata<int32_t> Int32Metadata;
typedef TypedMetadata<int64_t> Int64Metadata;
#endif
typedef TypedMetadata<Vec2d> Vec2DMetadata;
typedef TypedMetadata<Vec2i> Vec2IMetadata;
typedef TypedMetadata<Vec2s> Vec2SMetadata;
Expand Down
7 changes: 5 additions & 2 deletions openvdb_1_0_0_library/openvdb/metadata/StringMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<>
Expand Down
16 changes: 9 additions & 7 deletions openvdb_1_0_0_library/openvdb/unittest/TestFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<const char> scopedFile(filename, ::remove);

// Test first with grid instancing disabled, then with instancing enabled.
Expand Down Expand Up @@ -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<const char> scopedFile(filename, ::remove);

{
Expand Down Expand Up @@ -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<const char> scopedFile(filename, ::remove);

File file(filename);
Expand Down Expand Up @@ -1308,7 +1310,7 @@ TestFile::testReadGridMetadata()

openvdb::initialize();

const char* filename = "/tmp/testReadGridMetadata.vdb2";
const char* filename = "testReadGridMetadata.vdb2";
boost::shared_ptr<const char> scopedFile(filename, ::remove);

// Create grids
Expand Down Expand Up @@ -1782,7 +1784,7 @@ TestFile::testNameIterator()
// Register types.
openvdb::initialize();

const char* filename = "/tmp/testNameIterator.vdb2";
const char* filename = "testNameIterator.vdb2";
boost::shared_ptr<const char> scopedFile(filename, ::remove);

// Write the grids out to a file.
Expand Down Expand Up @@ -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<const char> scopedFile(filename, ::remove);

size_t uncompressedSize = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion openvdb_1_0_0_library/openvdb/unittest/TestTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ TestTree::testIterators()
void
TestTree::testIO()
{
const char* filename = "/tmp/test.dbg";
const char* filename = "test.dbg";
boost::shared_ptr<const char> scopedFile(filename, ::remove);
{
ValueType background=5.0f;
Expand Down
14 changes: 7 additions & 7 deletions openvdb_1_0_0_library/openvdb/unittest/TestTreeCombine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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<intersection>\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<difference>\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");
}


Expand Down
8 changes: 6 additions & 2 deletions openvdb_1_0_0_library/openvdb/util/Name.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ inline Name
readString(std::istream& is)
{
uint32_t size;
std::string buffer;
is.read(reinterpret_cast<char*>(&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;
}

Expand Down

0 comments on commit ae897d8

Please sign in to comment.