John Edward Broadbent | 5d799bb | 2022-03-22 16:14:24 -0700 | [diff] [blame] | 1 | #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 | |
| 9 | namespace estoraged_test |
| 10 | { |
| 11 | using estoraged::util::findPredictedMediaLifeLeftPercent; |
| 12 | |
| 13 | TEST(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 | |
| 25 | TEST(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 | |
| 39 | TEST(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 |