Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gabime/spdlog.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgabime <gmelman1@gmail.com>2015-12-13 15:59:48 +0300
committergabime <gmelman1@gmail.com>2015-12-13 15:59:48 +0300
commit3d420a3bcf1364407904e1d664621bc66b8c02a6 (patch)
tree29659a1e7d4567e5bcae00e1a4aea953091a212b /tests/utils.cpp
parent6feaa29c621ce6c8da8860e18df5b0c905940eb9 (diff)
tests refactoring
Diffstat (limited to 'tests/utils.cpp')
-rw-r--r--tests/utils.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/utils.cpp b/tests/utils.cpp
index 5ae8ea8f..ef6018b6 100644
--- a/tests/utils.cpp
+++ b/tests/utils.cpp
@@ -9,3 +9,37 @@ void prepare_logdir()
auto rv = system("rm -f logs/*");
#endif
}
+
+
+std::string file_contents(const std::string& filename)
+{
+ std::ifstream ifs(filename);
+ if (!ifs)
+ throw std::runtime_error("Failed open file ");
+ return std::string((std::istreambuf_iterator<char>(ifs)),
+ (std::istreambuf_iterator<char>()));
+
+}
+
+std::size_t count_lines(const std::string& filename)
+{
+ std::ifstream ifs(filename);
+ if (!ifs)
+ throw std::runtime_error("Failed open file ");
+
+ std::string line;
+ size_t counter = 0;
+ while(std::getline(ifs, line))
+ counter++;
+ return counter;
+}
+
+std::ifstream::pos_type filesize(const std::string& filename)
+{
+ std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary);
+ if (!ifs)
+ throw std::runtime_error("Failed open file ");
+
+ return ifs.tellg();
+}
+