blob: 8f53510f089d05f3a20c823bcc810ea7cfdb26f5 [file] [log] [blame]
John Edward Broadbent5d799bb2022-03-22 16:14:24 -07001#include <util.hpp>
2
3#include <fstream>
4
5#include <gmock/gmock-matchers.h>
6#include <gmock/gmock.h>
7#include <gtest/gtest.h>
8
9namespace estoraged_test
10{
11using estoraged::util::findPredictedMediaLifeLeftPercent;
12
13TEST(utilTest, passFindPredictedMediaLife)
14{
15 std::string prefixName = ".";
16 std::string testFileName = prefixName + "/life_time";
17 std::ofstream testFile;
18 testFile.open(testFileName,
19 std::ios::out | std::ios::binary | std::ios::trunc);
20 testFile << "0x07 0x04";
21 testFile.close();
22 EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 40);
23}
24
25TEST(utilTest, estimatesSame)
26{
27
28 std::string prefixName = ".";
29 std::string testFileName = prefixName + "/life_time";
30 std::ofstream testFile;
31 testFile.open(testFileName,
32 std::ios::out | std::ios::binary | std::ios::trunc);
33 testFile << "0x04 0x04";
34 testFile.close();
35
36 EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 70);
37}
38
39TEST(utilTest, estimatesNotAvailable)
40{
41
42 std::string prefixName = ".";
43 std::string testFileName = prefixName + "/life_time";
44 std::ofstream testFile;
45 testFile.open(testFileName,
46 std::ios::out | std::ios::binary | std::ios::trunc);
47 testFile.close();
48
49 EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 255);
50}
51
52} // namespace estoraged_test