TEST_F( SystemInformation_TEST
      , SetUsageSwapAfterSettingTotalSwap__ReturnsTrue )
{
    std::string memory_total( "1060252k" );
    std::string memory_usage( "860252k" );
    EXPECT_TRUE( sys_info__.setTotalSwap( memory_total ) );

    EXPECT_TRUE( sys_info__.setSwapUsage( memory_usage ) );
}
TEST_F( SystemInformation_TEST
      , SetUsageSwapToEmptyString__ReturnsFalse )
{
    std::string memory_total( "1060252k" );
    std::string memory_usage( "" );
    EXPECT_TRUE( sys_info__.setTotalSwap( memory_total ) );

    EXPECT_FALSE( sys_info__.setSwapUsage( memory_usage ) );
}
TEST_F( SystemInformation_TEST
      , GetTotalSwap__ReturnsTotalInMegabytes )
{
    std::string memory_total( "1060252k" );
    int memory_rxed( 1035 );
    EXPECT_TRUE( sys_info__.setTotalSwap( memory_total ) );

    EXPECT_EQ( memory_rxed
             , sys_info__.getTotalSwap() );
}
TEST_F( SystemInformation_TEST
      , GetTotalMemory__ReturnsTotalInMegabytes )
{
    std::string memory_total( "513184k" );
    int memory_rxed( 501 );
    EXPECT_TRUE( sys_info__.setTotalMemory( memory_total ) );

    EXPECT_EQ( memory_rxed
             , sys_info__.getTotalMemory() );
}
TEST_F( SystemInformation_TEST
      , GetSwapUsage__ReturnsPercentageOfTotalSwapInUse )
{
    std::string memory_total( "1060252k" );
    std::string memory_usage( "860252k" );
    int memory_rxed( 81 );
    EXPECT_TRUE( sys_info__.setTotalSwap( memory_total ) );
    EXPECT_TRUE( sys_info__.setSwapUsage( memory_usage ) );

    EXPECT_EQ( memory_rxed
             , sys_info__.getSwapUsage() );
}
Beispiel #6
0
uint32_t meminfo_func(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
	char buf[1024];
	unsigned int total = memory_total();
	unsigned int free  = total - memory_use();
	sprintf(buf, "MemTotal: %d kB\nMemFree: %d kB\n", total, free);

	size_t _bsize = strlen(buf);
	if (offset > _bsize) return 0;
	if (size > _bsize - offset) size = _bsize - offset;

	memcpy(buffer, buf, size);
	return size;
}
TEST_F( SystemInformation_TEST
      , DISABLED_SetTotalSwapWithWrongFigures__ReturnsFalse )
{
    std::string memory_total( "4k 101318" );
    EXPECT_FALSE( sys_info__.setTotalSwap( memory_total ) );
}
TEST_F( SystemInformation_TEST
      , SetTotalSwap__ReturnsTrue )
{
    std::string memory_total( "1060252k" );
    EXPECT_TRUE( sys_info__.setTotalSwap( memory_total ) );
}
TEST_F( SystemInformation_TEST
      , SetTotalMemory__ReturnsTrue )
{
    std::string memory_total( "513184k" );
    EXPECT_TRUE( sys_info__.setTotalMemory( memory_total ) );
}