-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test - introduce unit tests for telemetry::Holder
- Loading branch information
1 parent
0d166c3
commit 7a822bb
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* @file | ||
* @author Lukas Hutak <hutak@cesnet.cz> | ||
* @brief Unit tests of telemetry::Holder class | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#include <telemetry/directory.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace telemetry { | ||
|
||
/** | ||
* @test Test checking availability of read operation. | ||
*/ | ||
TEST(TelemetryHolder, create) | ||
{ | ||
Holder holder; | ||
} | ||
|
||
/** | ||
* @test Test adding various entries to the holder. | ||
*/ | ||
TEST(TelemetryHolder, add) | ||
{ | ||
auto root = Directory::create(); | ||
|
||
{ | ||
Holder holder; | ||
|
||
{ | ||
auto file = root->addFile("file", {}); | ||
auto dir = root->addDir("dir"); | ||
|
||
holder.add(file); | ||
holder.add(dir); | ||
} | ||
|
||
// Check if entries still exists | ||
EXPECT_NE(nullptr, root->getEntry("file")); | ||
EXPECT_NE(nullptr, root->getEntry("dir")); | ||
} | ||
|
||
// After holder destruction, entries should be gone... | ||
EXPECT_EQ(nullptr, root->getEntry("file")); | ||
EXPECT_EQ(nullptr, root->getEntry("dir")); | ||
} | ||
|
||
/** | ||
* @test Test disabling callbacks of held files. | ||
*/ | ||
TEST(TelemetryHolder, disableFiles) | ||
{ | ||
auto root = Directory::create(); | ||
FileOps ops = {}; | ||
ops.read = []() { return Scalar {"value"}; }; | ||
ops.clear = []() {}; | ||
|
||
Holder holder; | ||
|
||
auto dir = root->addDir("dir"); | ||
auto file = root->addFile("file", ops); | ||
holder.add(file); | ||
|
||
EXPECT_TRUE(file->hasRead()); | ||
EXPECT_TRUE(file->hasClear()); | ||
|
||
holder.disableFiles(); | ||
|
||
EXPECT_FALSE(file->hasRead()); | ||
EXPECT_FALSE(file->hasClear()); | ||
} | ||
|
||
} // namespace telemetry |