1 #include "powercap.hpp" 2 3 #include <experimental/filesystem> 4 #include <occ_events.hpp> 5 #include <occ_manager.hpp> 6 7 #include <gtest/gtest.h> 8 9 using namespace open_power::occ; 10 11 class VerifyOccInput : public ::testing::Test 12 { 13 public: 14 VerifyOccInput() : 15 rc(sd_event_default(&event)), eventP(event), manager(eventP), 16 occStatus(eventP, "/test/path/occ1", manager), pcap(occStatus) 17 { 18 EXPECT_GE(rc, 0); 19 event = nullptr; 20 } 21 ~VerifyOccInput() 22 { 23 } 24 25 sd_event* event; 26 int rc; 27 open_power::occ::EventPtr eventP; 28 29 Manager manager; 30 Status occStatus; 31 powercap::PowerCap pcap; 32 }; 33 34 TEST_F(VerifyOccInput, PcapDisabled) 35 { 36 uint32_t occInput = pcap.getOccInput(100, false); 37 EXPECT_EQ(occInput, 0); 38 } 39 40 TEST_F(VerifyOccInput, PcapEnabled) 41 { 42 uint32_t occInput = pcap.getOccInput(100, true); 43 EXPECT_EQ(occInput, 90); 44 } 45 46 TEST(VerifyPathParsing, EmptyPath) 47 { 48 std::experimental::filesystem::path path = ""; 49 std::string parsed = Device::getPathBack(path); 50 51 EXPECT_STREQ(parsed.c_str(), ""); 52 } 53 54 TEST(VerifyPathParsing, FilenamePath) 55 { 56 std::experimental::filesystem::path path = "/test/foo.bar"; 57 std::string parsed = Device::getPathBack(path); 58 59 EXPECT_STREQ(parsed.c_str(), "foo.bar"); 60 } 61 62 TEST(VerifyPathParsing, DirectoryPath) 63 { 64 std::experimental::filesystem::path path = "/test/bar/"; 65 std::string parsed = Device::getPathBack(path); 66 67 EXPECT_STREQ(parsed.c_str(), "bar"); 68 } 69