| | |
| |
|
| | #include <gtest/gtest.h> |
| | #include <gmock/gmock.h> |
| |
|
| | #include "App/Application.h" |
| | #include "App/Document.h" |
| | #include "App/StringHasher.h" |
| | #include "Base/Writer.h" |
| | #include <src/App/InitApplication.h> |
| |
|
| | using ::testing::Eq; |
| | using ::testing::Ne; |
| |
|
| | |
| |
|
| | class FakeWriter: public Base::Writer |
| | { |
| | void writeFiles() override |
| | {} |
| | std::ostream& Stream() override |
| | { |
| | return std::cout; |
| | } |
| | }; |
| |
|
| | class DocumentTest: public ::testing::Test |
| | { |
| | protected: |
| | static void SetUpTestSuite() |
| | { |
| | tests::initApplication(); |
| | } |
| |
|
| | void SetUp() override |
| | { |
| | _docName = App::GetApplication().getUniqueDocumentName("test"); |
| | _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); |
| | } |
| |
|
| | void TearDown() override |
| | { |
| | App::GetApplication().closeDocument(_docName.c_str()); |
| | } |
| |
|
| | App::Document* doc() |
| | { |
| | return _doc; |
| | } |
| |
|
| | private: |
| | std::string _docName; |
| | App::Document* _doc {}; |
| | }; |
| |
|
| |
|
| | TEST_F(DocumentTest, addStringHasherIndicatesUnwrittenWhenNew) |
| | { |
| | |
| | App::StringHasherRef hasher(new App::StringHasher); |
| |
|
| | |
| | auto addResult = doc()->addStringHasher(hasher); |
| |
|
| | |
| | EXPECT_TRUE(addResult.first); |
| | EXPECT_THAT(addResult.second, Ne(-1)); |
| | } |
| |
|
| | TEST_F(DocumentTest, addStringHasherIndicatesAlreadyWritten) |
| | { |
| | |
| | App::StringHasherRef hasher(new App::StringHasher); |
| | doc()->addStringHasher(hasher); |
| |
|
| | |
| | auto addResult = doc()->addStringHasher(hasher); |
| |
|
| | |
| | EXPECT_FALSE(addResult.first); |
| | } |
| |
|
| | TEST_F(DocumentTest, getStringHasherGivesExpectedHasher) |
| | { |
| | |
| | App::StringHasherRef hasher(new App::StringHasher); |
| | auto pair = doc()->addStringHasher(hasher); |
| | int index = pair.second; |
| |
|
| | |
| | auto foundHasher = doc()->getStringHasher(index); |
| |
|
| | |
| | EXPECT_EQ(hasher, foundHasher); |
| | } |
| |
|
| | |
| |
|