2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-11-07 13:37:58 +01:00
|
|
|
|
2017-05-15 15:51:39 +02:00
|
|
|
#include "base/perfdatavalue.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/pluginutility.hpp"
|
2016-09-07 08:20:51 +02:00
|
|
|
#include <BoostTestTargetConfig.h>
|
2013-11-07 13:37:58 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(icinga_perfdata)
|
|
|
|
|
2013-11-08 08:39:05 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(empty)
|
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
Array::Ptr pd = PluginUtility::SplitPerfdata("");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pd->GetLength(), 0);
|
2013-11-08 08:39:05 +01:00
|
|
|
}
|
|
|
|
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(simple)
|
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
PerfdataValue::Ptr pdv = PerfdataValue::Parse("test=123456");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pdv->GetLabel(), "test");
|
|
|
|
BOOST_CHECK_EQUAL(pdv->GetValue(), 123456);
|
2013-11-07 13:37:58 +01:00
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
String str = pdv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=123456");
|
2013-11-07 13:37:58 +01:00
|
|
|
}
|
|
|
|
|
2013-11-13 15:42:58 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(quotes)
|
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
Array::Ptr pd = PluginUtility::SplitPerfdata("'hello world'=123456");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pd->GetLength(), 1);
|
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
PerfdataValue::Ptr pdv = PerfdataValue::Parse("'hello world'=123456");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pdv->GetLabel(), "hello world");
|
|
|
|
BOOST_CHECK_EQUAL(pdv->GetValue(), 123456);
|
2013-11-13 15:42:58 +01:00
|
|
|
}
|
|
|
|
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(multiple)
|
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
Array::Ptr pd = PluginUtility::SplitPerfdata("testA=123456 testB=123456");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pd->GetLength(), 2);
|
2013-11-07 13:37:58 +01:00
|
|
|
|
|
|
|
String str = PluginUtility::FormatPerfdata(pd);
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "testA=123456 testB=123456");
|
2013-11-07 13:37:58 +01:00
|
|
|
}
|
|
|
|
|
2021-08-13 10:18:08 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(multiline)
|
|
|
|
{
|
|
|
|
Array::Ptr pd = PluginUtility::SplitPerfdata(" 'testA'=123456 'testB'=123456");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pd->GetLength(), 2);
|
2021-08-13 10:18:08 +02:00
|
|
|
|
|
|
|
String str = PluginUtility::FormatPerfdata(pd);
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "testA=123456 testB=123456");
|
2021-08-13 10:18:08 +02:00
|
|
|
|
|
|
|
pd = PluginUtility::SplitPerfdata(" 'testA'=123456 \n'testB'=123456");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pd->GetLength(), 2);
|
2021-08-13 10:18:08 +02:00
|
|
|
|
|
|
|
str = PluginUtility::FormatPerfdata(pd);
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "testA=123456 testB=123456");
|
2021-08-13 10:18:08 +02:00
|
|
|
}
|
|
|
|
|
2021-05-11 16:47:03 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(normalize)
|
|
|
|
{
|
|
|
|
Array::Ptr pd = PluginUtility::SplitPerfdata("testA=2m;3;4;1;5 testB=2foobar");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pd->GetLength(), 2);
|
2021-05-11 16:47:03 +02:00
|
|
|
|
|
|
|
String str = PluginUtility::FormatPerfdata(pd, true);
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "testA=120s;180;240;60;300 testB=2");
|
2021-05-11 16:47:03 +02:00
|
|
|
}
|
|
|
|
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(uom)
|
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
PerfdataValue::Ptr pv = PerfdataValue::Parse("test=123456B");
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 123456);
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_CHECK(!pv->GetCounter());
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "bytes");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
2013-11-07 13:37:58 +01:00
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
String str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=123456B");
|
2013-12-17 14:47:19 +01:00
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
pv = PerfdataValue::Parse("test=1000ms;200;500");
|
2013-12-17 14:47:19 +01:00
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "seconds");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), 0.2);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), 0.5);
|
2013-12-17 14:47:19 +01:00
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
pv = PerfdataValue::Parse("test=1000ms");
|
2013-12-17 14:47:19 +01:00
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "seconds");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
2013-12-17 14:47:19 +01:00
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1s");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1kAm");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 60 * 1000);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "ampere-seconds");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=60000As");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1MA");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1000 * 1000);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "amperes");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1000000A");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1gib");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1024 * 1024 * 1024);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "bits");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1073741824b");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1dBm");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "decibel-milliwatts");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1dBm");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1C");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "degrees-celsius");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1C");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1F");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "degrees-fahrenheit");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1F");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1K");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "degrees-kelvin");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1K");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1t");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1000 * 1000);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "grams");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1000000g");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1hl");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 100);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "liters");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=100l");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1lm");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "lumens");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1lm");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1TO");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1000.0 * 1000 * 1000 * 1000);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "ohms");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1000000000000O");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1PV");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1000.0 * 1000 * 1000 * 1000 * 1000);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "volts");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1000000000000000V");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1EWh");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1000.0 * 1000 * 1000 * 1000 * 1000 * 1000);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "watt-hours");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1000000000000000000Wh");
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
pv = PerfdataValue::Parse("test=1000mW");
|
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "watts");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
|
PerfdataValue: add UoMs
* {,{K,M,G,T,P,E,Z,Y}{,i}}B
=> bytes
* {,{k,m,g,t,p,e,z,y}{,i}}b
=> bits
* packets
* {n,u,m,}s m h d
=> seconds
* {n,u,m,,k,M,G,T,P,E,Z,Y}{{A,O,V,W},{A,W}{s,m,h}}
=> amperes, ohms, volts, watts, ampere-seconds, watt-hours
* lm dBm
=> lumens decibel-milliwatts
* {n,u,m,,k}g t
=> grams
* C F K
=> degrees-celsius, degrees-fahrenheit, degrees-kelvin
* {m,,h}l
=> liters
refs #7225
2020-04-03 12:47:36 +02:00
|
|
|
|
|
|
|
str = pv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=1W");
|
2013-11-07 13:37:58 +01:00
|
|
|
}
|
|
|
|
|
2013-11-07 18:21:55 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(warncritminmax)
|
2013-11-07 13:37:58 +01:00
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
PerfdataValue::Ptr pv = PerfdataValue::Parse("test=123456B;1000;2000;3000;4000");
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_CHECK(pv);
|
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 123456);
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_CHECK(!pv->GetCounter());
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "bytes");
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), 1000);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), 2000);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), 3000);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), 4000);
|
2013-11-07 13:37:58 +01:00
|
|
|
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->Format(), "test=123456B;1000;2000;3000;4000");
|
2013-11-07 13:37:58 +01:00
|
|
|
}
|
|
|
|
|
2024-03-26 12:49:24 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(ignore_warn_crit_ranges)
|
2015-03-01 17:04:48 +01:00
|
|
|
{
|
|
|
|
PerfdataValue::Ptr pv = PerfdataValue::Parse("test=123456;1000:2000;0:3000;3000;4000");
|
|
|
|
BOOST_CHECK(pv);
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 123456);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMin(), 3000);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetMax(), 4000);
|
2015-03-01 17:04:48 +01:00
|
|
|
|
2024-03-26 12:49:24 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->Format(), "test=123456;;;3000;4000");
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(empty_warn_crit_min_max)
|
|
|
|
{
|
|
|
|
Array::Ptr pd = PluginUtility::SplitPerfdata("testA=5;;7;1;9 testB=5;7;;1;9 testC=5;;;1;9 testD=2m;;;1 testE=5;;7;;");
|
|
|
|
BOOST_CHECK_EQUAL(pd->GetLength(), 5);
|
|
|
|
|
|
|
|
String str = PluginUtility::FormatPerfdata(pd, true);
|
|
|
|
BOOST_CHECK_EQUAL(str, "testA=5;;7;1;9 testB=5;7;;1;9 testC=5;;;1;9 testD=120s;;;60 testE=5;;7");
|
2015-03-01 17:04:48 +01:00
|
|
|
}
|
|
|
|
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(invalid)
|
|
|
|
{
|
2015-03-01 17:04:48 +01:00
|
|
|
BOOST_CHECK_THROW(PerfdataValue::Parse("123456"), boost::exception);
|
2014-09-17 15:38:39 +02:00
|
|
|
BOOST_CHECK_THROW(PerfdataValue::Parse("test=1,23456"), boost::exception);
|
2021-06-08 11:44:12 +02:00
|
|
|
BOOST_CHECK_THROW(PerfdataValue::Parse("test=123_456"), boost::exception);
|
|
|
|
BOOST_CHECK_THROW(PerfdataValue::Parse("test="), boost::exception);
|
|
|
|
BOOST_CHECK_THROW(PerfdataValue::Parse("test=123,456;1;1;1;1"), boost::exception);
|
|
|
|
BOOST_CHECK_THROW(PerfdataValue::Parse("test=1;123,456;1;1;1"), boost::exception);
|
|
|
|
BOOST_CHECK_THROW(PerfdataValue::Parse("test=1;1;123,456;1;1"), boost::exception);
|
|
|
|
BOOST_CHECK_THROW(PerfdataValue::Parse("test=1;1;1;123,456;1"), boost::exception);
|
|
|
|
BOOST_CHECK_THROW(PerfdataValue::Parse("test=1;1;1;1;123,456"), boost::exception);
|
2013-11-07 13:37:58 +01:00
|
|
|
}
|
|
|
|
|
2013-11-17 03:29:43 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(multi)
|
|
|
|
{
|
2014-09-17 15:38:39 +02:00
|
|
|
Array::Ptr pd = PluginUtility::SplitPerfdata("test::a=3 b=4");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pd->Get(0), "test::a=3");
|
|
|
|
BOOST_CHECK_EQUAL(pd->Get(1), "test::b=4");
|
2013-11-17 03:29:43 +01:00
|
|
|
}
|
|
|
|
|
2020-11-26 18:53:57 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(scientificnotation)
|
|
|
|
{
|
|
|
|
PerfdataValue::Ptr pdv = PerfdataValue::Parse("test=1.1e+1");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pdv->GetLabel(), "test");
|
|
|
|
BOOST_CHECK_EQUAL(pdv->GetValue(), 11);
|
2020-11-26 18:53:57 +01:00
|
|
|
|
|
|
|
String str = pdv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=11");
|
2020-11-26 18:53:57 +01:00
|
|
|
|
|
|
|
pdv = PerfdataValue::Parse("test=1.1e1");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pdv->GetLabel(), "test");
|
|
|
|
BOOST_CHECK_EQUAL(pdv->GetValue(), 11);
|
2020-11-26 18:53:57 +01:00
|
|
|
|
|
|
|
str = pdv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=11");
|
2020-11-26 18:53:57 +01:00
|
|
|
|
|
|
|
pdv = PerfdataValue::Parse("test=1.1e-1");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pdv->GetLabel(), "test");
|
|
|
|
BOOST_CHECK_EQUAL(pdv->GetValue(), 0.11);
|
2020-11-26 18:53:57 +01:00
|
|
|
|
|
|
|
str = pdv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=0.110000");
|
2020-11-26 18:53:57 +01:00
|
|
|
|
|
|
|
pdv = PerfdataValue::Parse("test=1.1E1");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pdv->GetLabel(), "test");
|
|
|
|
BOOST_CHECK_EQUAL(pdv->GetValue(), 11);
|
2020-11-26 18:53:57 +01:00
|
|
|
|
|
|
|
str = pdv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=11");
|
2020-11-26 18:53:57 +01:00
|
|
|
|
|
|
|
pdv = PerfdataValue::Parse("test=1.1E-1");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pdv->GetLabel(), "test");
|
|
|
|
BOOST_CHECK_EQUAL(pdv->GetValue(), 0.11);
|
2020-11-26 18:53:57 +01:00
|
|
|
|
|
|
|
str = pdv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=0.110000");
|
2020-11-26 18:53:57 +01:00
|
|
|
|
|
|
|
pdv = PerfdataValue::Parse("test=1.1E-1;1.2e+1;1.3E-1;1.4e-2;1.5E2");
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pdv->GetLabel(), "test");
|
|
|
|
BOOST_CHECK_EQUAL(pdv->GetValue(), 0.11);
|
|
|
|
BOOST_CHECK_EQUAL(pdv->GetWarn(), 12);
|
|
|
|
BOOST_CHECK_EQUAL(pdv->GetCrit(), 0.13);
|
|
|
|
BOOST_CHECK_EQUAL(pdv->GetMin(), 0.014);
|
|
|
|
BOOST_CHECK_EQUAL(pdv->GetMax(), 150);
|
2020-11-26 18:53:57 +01:00
|
|
|
|
|
|
|
str = pdv->Format();
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(str, "test=0.110000;12;0.130000;0.014000;150");
|
2020-11-26 18:53:57 +01:00
|
|
|
}
|
|
|
|
|
2021-06-08 11:44:12 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(parse_edgecases)
|
|
|
|
{
|
|
|
|
// Trailing decimal point
|
|
|
|
PerfdataValue::Ptr pv = PerfdataValue::Parse("test=23.");
|
|
|
|
BOOST_CHECK(pv);
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 23.0);
|
2021-06-08 11:44:12 +02:00
|
|
|
|
|
|
|
// Leading decimal point
|
|
|
|
pv = PerfdataValue::Parse("test=.42");
|
|
|
|
BOOST_CHECK(pv);
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 0.42);
|
2021-06-08 11:44:12 +02:00
|
|
|
|
|
|
|
// E both as exponent and unit prefix
|
|
|
|
pv = PerfdataValue::Parse("test=+1.5E-15EB");
|
|
|
|
BOOST_CHECK(pv);
|
2024-03-26 12:49:11 +01:00
|
|
|
BOOST_CHECK_EQUAL(pv->GetValue(), 1.5e3);
|
|
|
|
BOOST_CHECK_EQUAL(pv->GetUnit(), "bytes");
|
2021-06-08 11:44:12 +02:00
|
|
|
}
|
|
|
|
|
2013-11-07 13:37:58 +01:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|