Skip to content

Commit

Permalink
FindLevelDB work in ubuntu and util.hpp improve
Browse files Browse the repository at this point in the history
- FindLevelDB now links with snappy if finds
- util.hpp now have ASSERT/EXPECT for specific status
  • Loading branch information
ony committed Apr 18, 2014
1 parent 4d817ac commit a27ac81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
9 changes: 8 additions & 1 deletion cmake_modules/FindLevelDB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ find_library(LevelDB_LIBRARY
NAMES leveldb
)

mark_as_advanced(LevelDB_INCLUDE_DIR LevelDB_LIBRARY)
find_library(Snappy_LIBRARY
NAMES snappy
)

mark_as_advanced(LevelDB_INCLUDE_DIR LevelDB_LIBRARY Snappy_LIBRARY)

include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)

Expand All @@ -24,4 +28,7 @@ set(LevelDB_FOUND ${LEVELDB_FOUND})
if(LevelDB_FOUND)
set(LevelDB_INCLUDE_DIRS ${LevelDB_INCLUDE_DIR})
set(LevelDB_LIBRARIES ${LevelDB_LIBRARY})
if(NOT Snappy_LIBRARY STREQUAL "Snappy_LIBRARY-NOTFOUND")
set(LevelDB_LIBRARIES ${LevelDB_LIBRARIES} ${Snappy_LIBRARY})
endif()
endif()
18 changes: 12 additions & 6 deletions test/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ namespace leveldb {
{ *os << ::testing::PrintToString(s.ToString()); }
}

inline ::testing::AssertionResult ok(leveldb::Status s)
inline ::testing::AssertionResult check(
const leveldb::Status &s,
std::function<bool(const leveldb::Status &)> pred = [](const leveldb::Status &s) { return s.ok(); }
)
{
if (s.ok()) return ::testing::AssertionSuccess() << s.ToString();
if (pred(s)) return ::testing::AssertionSuccess() << s.ToString();
else return ::testing::AssertionFailure() << s.ToString();
}

constexpr bool hostIsNetwork()
{ return *reinterpret_cast<const short*>("\x01\x02") == 0x0102; }

#define ASSERT_OK(E) ASSERT_TRUE(ok(E))
#define EXPECT_OK(E) EXPECT_TRUE(ok(E))
#define ASSERT_OK(E) ASSERT_TRUE(check(E))
#define EXPECT_OK(E) EXPECT_TRUE(check(E))

#define ASSERT_FAIL(E) ASSERT_FALSE(ok(E))
#define EXPECT_FAIL(E) EXPECT_FALSE(ok(E))
#define ASSERT_FAIL(E) ASSERT_FALSE(check(E))
#define EXPECT_FAIL(E) EXPECT_FALSE(check(E))

#define ASSERT_STATUS(M, E) ASSERT_TRUE(check(E, [](const leveldb::Status &s) { return s.Is ## M(); }))
#define EXPECT_STATUS(M, E) EXPECT_TRUE(check(E, [](const leveldb::Status &s) { return s.Is ## M(); }))

0 comments on commit a27ac81

Please sign in to comment.