add new AdcValueHolder implementation in adc_value.h
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "../common/adc_utils.h"
|
||||
#include "../common/adc_value_holder.h"
|
||||
// #include "../common/adc_value_holder.h"
|
||||
#include "../common/adc_value.h"
|
||||
|
||||
TEST_CASE("[ADC VALUEHOLDER]")
|
||||
{
|
||||
@@ -36,7 +37,9 @@ TEST_CASE("[ADC VALUEHOLDER]")
|
||||
CHECK_THROWS_WITH_AS(vh = 1.1, "conversion function is not defined", std::system_error);
|
||||
CHECK_THROWS_WITH_AS(vh = -3, "user value is not valid", std::system_error);
|
||||
|
||||
double dv = 33.33;
|
||||
std::cout << "int_val = " << int_val << "\n";
|
||||
|
||||
const double dv = 33.33;
|
||||
vah = dv;
|
||||
|
||||
REQUIRE_EQ(int_val, 33);
|
||||
@@ -66,13 +69,15 @@ TEST_CASE("[ADC VALUEHOLDER]")
|
||||
|
||||
adc::AdcValueHolder vsh(sget, sset, sval);
|
||||
|
||||
vsh.addConvertFunc<const char*>([](std::any& v) { v = std::string(std::any_cast<const char*>(v)); },
|
||||
[](std::any& v) {
|
||||
auto sval = std::any_cast<std::string>(&v);
|
||||
v = sval->c_str();
|
||||
});
|
||||
// vsh.addConvertFunc<const char*>([](std::any& v) { v = std::string(std::any_cast<const char*>(v)); },
|
||||
// [](std::any& v) {
|
||||
// auto sval = std::any_cast<std::string>(&v);
|
||||
// v = sval->c_str();
|
||||
// });
|
||||
|
||||
|
||||
vsh.addConvertFunc([](const std::string& v) { return v.c_str(); }, [](const char* v) { return std::string(v); });
|
||||
|
||||
vsh = "NEW VALUE";
|
||||
|
||||
REQUIRE_EQ(str, "NEW VALUE");
|
||||
|
||||
Reference in New Issue
Block a user