all unit tests are gtests

This commit is contained in:
Marko Budiselic 2017-02-19 23:47:09 +01:00
parent 3642fb1312
commit 2a046bba78
5 changed files with 100 additions and 54 deletions

View File

@ -409,8 +409,16 @@ endif()
# -----------------------------------------------------------------------------
# make CLion aware of all source files so we get refactoring etc
# TODO: fix snapshots and everything from src and then add custom target
#file(GLOB_RECURSE __SOURCES ${CMAKE_SOURCE_DIR}/src/*.hpp ${CMAKE_SOURCE_DIR}/src/*.cpp)
#add_executable(__refactor_target ${__SOURCES})
#target_link_libraries(__refactor_target memgraph_lib stdc++fs Threads::Threads ${fmt_static_lib} ${yaml_static_lib} ${antlr_static_lib} antlr_opencypher_parser_lib dl)
#add_dependencies(__refactor_target generate_opencypher_parser)
file(GLOB_RECURSE __SOURCES ${CMAKE_SOURCE_DIR}/src/*.hpp ${CMAKE_SOURCE_DIR}/src/*.cpp)
# TODO: those files have to be refactored (snapshot & cleaner related)
list(REMOVE_ITEM __SOURCES ${CMAKE_SOURCE_DIR}/src/snapshot/snapshot_engine.cpp)
list(REMOVE_ITEM __SOURCES ${CMAKE_SOURCE_DIR}/src/snapshot/snapshot_decoder.cpp)
list(REMOVE_ITEM __SOURCES ${CMAKE_SOURCE_DIR}/src/snapshot/snapshot_encoder.cpp)
list(REMOVE_ITEM __SOURCES ${CMAKE_SOURCE_DIR}/src/snapshot/snapshoter.cpp)
list(REMOVE_ITEM __SOURCES ${CMAKE_SOURCE_DIR}/src/dbms/cleaner.cpp)
list(REMOVE_ITEM __SOURCES ${CMAKE_SOURCE_DIR}/src/storage/garbage/garbage.cpp)
# TODO: figure out why the file isn't compilable it should be (typed_value_store.cpp)
list(REMOVE_ITEM __SOURCES ${CMAKE_SOURCE_DIR}/src/storage/typed_value_store.cpp)
list(REMOVE_ITEM __SOURCES ${CMAKE_SOURCE_DIR}/src/io/network/tls.cpp)
add_executable(__refactor_target ${__SOURCES})
target_link_libraries(__refactor_target memgraph_lib stdc++fs Threads::Threads ${fmt_static_lib} ${yaml_static_lib} ${antlr_static_lib} antlr_opencypher_parser_lib dl)

View File

@ -1,11 +1,8 @@
#include <iostream>
#include "gtest/gtest.h"
#include "mvcc/id.hpp"
using std::cout;
using std::endl;
int main() {
TEST(IdTest, BasicUsageAndTotalOrdering) {
Id id0(0);
Id id1(1);
Id id2(1);
@ -13,21 +10,17 @@ int main() {
Id id4 = id3;
Id id5(5);
cout << id5 << " " << id0 << endl;
if (id0 < id5) cout << "id0 < id5" << endl;
if (id1 == id2) cout << "are equal" << endl;
if (id3 == id4) cout << "id3 == id4" << endl;
if (id5 > id0) cout << "id5 > id0" << endl;
if (id5 != id3) cout << "id5 != id3" << endl;
if (id1 >= id2) cout << "id1 >= id2" << endl;
if (id3 <= id4) cout << "id3 <= id4" << endl;
return 0;
ASSERT_EQ(id0 < id5, true);
ASSERT_EQ(id1 == id2, true);
ASSERT_EQ(id3 == id4, true);
ASSERT_EQ(id5 > id0, true);
ASSERT_EQ(id5 > id0, true);
ASSERT_EQ(id5 != id3, true);
ASSERT_EQ(id1 >= id2, true);
ASSERT_EQ(id3 <= id4, true);
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,25 +0,0 @@
#include "logging/logger.hpp"
#include "logging/logs/async_log.hpp"
#include "logging/logs/sync_log.hpp"
#include "logging/streams/stdout.hpp"
int main(void) {
// Log::uptr log = std::make_unique<SyncLog>();
Log::uptr log = std::make_unique<AsyncLog>();
log->pipe(std::make_unique<Stdout>());
auto logger = log->logger("main");
logger.info("This is very {}!", "awesome");
logger.warn("This is very {}!", "awesome");
logger.error("This is very {}!", "awesome");
logger.trace("This is very {}!", "awesome");
logger.debug("This is very {}!", "awesome");
using namespace std::chrono;
/* std::this_thread::sleep_for(1s); */
return 0;
}

62
tests/unit/logging.cpp Normal file
View File

@ -0,0 +1,62 @@
#include <atomic>
#include "gtest/gtest.h"
#include "logging/logger.hpp"
#include "logging/logs/async_log.hpp"
#include "logging/logs/sync_log.hpp"
#include "logging/streams/stdout.hpp"
class Testout : public Log::Stream {
public:
void emit(const Log::Record& record) override {
counter_.fetch_add(1);
sequence_.emplace_back(counter_.load());
texts_.insert(record.text());
}
std::atomic<int> counter_;
std::vector<int> sequence_;
std::set<std::string> texts_;
};
TEST(LoggingTest, SyncLogger) {
Log::uptr log = std::make_unique<SyncLog>();
auto test_stream = std::make_unique<Testout>();
auto check = test_stream.get();
log->pipe(std::move(test_stream));
auto logger = log->logger("sync_logger");
logger.info("{}", "info");
logger.warn("{}", "warn");
logger.error("{}", "error");
logger.trace("{}", "trace");
logger.debug("{}", "debug");
ASSERT_EQ(check->counter_, 5);
ASSERT_EQ(check->sequence_[4], 5);
ASSERT_EQ(check->texts_.size(), 5);
}
TEST(LoggingTest, AysncLogger) {
Log::uptr log = std::make_unique<AsyncLog>();
auto test_stream = std::make_unique<Testout>();
auto check = test_stream.get();
log->pipe(std::move(test_stream));
auto logger = log->logger("async_logger");
logger.info("{}", "info");
logger.warn("{}", "warn");
logger.error("{}", "error");
logger.trace("{}", "trace");
logger.debug("{}", "debug");
using namespace std::chrono;
std::this_thread::sleep_for(1s);
ASSERT_EQ(check->counter_, 5);
ASSERT_EQ(check->sequence_.size(), 5);
ASSERT_EQ(check->texts_.size(), 5);
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -2,9 +2,10 @@
#include <iostream>
#include <thread>
#include "gtest/gtest.h"
#include "utils/datetime/timestamp.hpp"
int main(void) {
TEST(TimestampTest, BasicUsage) {
auto timestamp = Timestamp::now();
std::cout << timestamp << std::endl;
@ -14,9 +15,16 @@ int main(void) {
std::cout << Timestamp::now().to_iso8601() << std::endl;
ASSERT_GT(Timestamp::now(), timestamp);
std::cout << std::boolalpha;
std::cout << (timestamp == Timestamp::now()) << std::endl;
return 0;
ASSERT_NE(timestamp, Timestamp::now());
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}