summaryrefslogtreecommitdiffhomepage
path: root/tests/test-file.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-05 10:37:41 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-05 10:37:41 +0100
commit0f2ac0c4311e4429bfa4ede1d96ce467b5dceb5b (patch)
treeb4dbe07617ca818b182a18f27d0d4e6bafc91841 /tests/test-file.cpp
parent0c0d858e4f9423fb9697bad9a012cb67fcee75e0 (diff)
Added tests
Diffstat (limited to 'tests/test-file.cpp')
-rw-r--r--tests/test-file.cpp56
1 files changed, 54 insertions, 2 deletions
diff --git a/tests/test-file.cpp b/tests/test-file.cpp
index 13d0ded..7c3b752 100644
--- a/tests/test-file.cpp
+++ b/tests/test-file.cpp
@@ -1,3 +1,55 @@
-getFile
+#include <gtest/gtest.h>
-getFile /proc
+#include "file.h"
+
+#include <filesystem>
+#include <fstream>
+#include <iostream>
+
+namespace fs = std::filesystem;
+
+namespace {
+ const fs::path testFilename{"testfile.txt"};
+} // namespace
+
+class FileTest: public ::testing::Test
+{
+protected:
+ FileTest(){
+ }
+
+ ~FileTest() override{
+ }
+
+ void SetUp() override
+ {
+ std::error_code ec;
+ fs::remove(testFilename, ec);
+ }
+
+ void TearDown() override
+ {
+ std::error_code ec;
+ fs::remove(testFilename, ec);
+ }
+
+};
+
+TEST_F(FileTest, getFile)
+{
+ {
+ std::ofstream of(testFilename, std::ios::binary);
+ of << "abc";
+ }
+
+ std::string s{Reichwein::File::getFile(testFilename)};
+
+ EXPECT_EQ(s, "abc");
+}
+
+TEST_F(FileTest, getFile_proc)
+{
+ std::string s{Reichwein::File::getFile("/proc/cmdline")};
+
+ EXPECT_GT(s.size(), 0);
+}